Skip to content

Commit 9ec3a0a

Browse files
authored
Fix test and import for macos (#3)
* Fix imports for macos * Bump version 1.0.2 * fix actions
1 parent ae59fdc commit 9ec3a0a

15 files changed

+61
-45
lines changed

.github/workflows/python-package.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ jobs:
9696
yapf --quiet --style "{based_on_style: pep8, blank_line_before_nested_class_or_def: true, indent_dictionary_value: true, dedent_closing_brackets: true, column_limit: 99}" --recursive .
9797
- name: Test with pytest
9898
run: |
99-
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:"$(pip show pylspack | grep 'Location:' | awk '{print $2}')/pylspack/" && python3 -m pytest -svvv test
99+
cd test && python3 -m pytest -svvv .

README.md

+25-14
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,29 @@ As already noted, the implementation is designed for existing data structures of
1717
The C++ API **can** be used as a standalone package, but it has not been tested.
1818

1919
### Citation
20-
The corresponding publication https://doi.org/10.1137/20m1314471 can be cited as follows:
20+
If you use this software in academic work, please consider citing the corresponding publications:
21+
- https://doi.org/10.1137/20m1314471
2122
```
22-
@article{Sobczyk2021,
23-
doi = {10.1137/20m1314471},
24-
url = {https://doi.org/10.1137/20m1314471},
25-
year = {2021},
26-
publisher = {Society for Industrial {\&} Applied Mathematics ({SIAM})},
27-
volume = {42},
28-
number = {3},
29-
pages = {1199--1228},
30-
author = {Aleksandros Sobczyk and Efstratios Gallopoulos},
31-
title = {Estimating Leverage Scores via Rank Revealing Methods and Randomization},
32-
journal = {{SIAM} Journal on Matrix Analysis and Applications}
23+
@article{sobczyk2021estimating,
24+
title={Estimating leverage scores via rank revealing methods and randomization},
25+
author={Sobczyk, Aleksandros and Gallopoulos, Efstratios},
26+
journal={SIAM Journal on Matrix Analysis and Applications},
27+
volume={42},
28+
number={3},
29+
pages={1199--1228},
30+
year={2021},
31+
doi={10.1137/20m1314471},
32+
url={https://doi.org/10.1137/20m1314471},
33+
publisher={SIAM}
34+
}
35+
```
36+
- https://doi.org/10.48550/arxiv.2203.02798
37+
```
38+
@article{sobczyk2022pylspack,
39+
title={pylspack: Parallel algorithms and data structures for sketching, column subset selection, regression and leverage scores},
40+
author={Sobczyk, Aleksandros and Gallopoulos, Efstratios},
41+
journal={arXiv preprint arXiv:2203.02798},
42+
year={2022}
3343
}
3444
```
3545

@@ -92,11 +102,12 @@ pip install git+https://github.com/IBM/pylspack
92102

93103
To run the tests:
94104
```bash
105+
python3 -m pip install -r test_requirements.txt
106+
cd test
107+
python3 -m pytest -svvv .
95108
# If you get an error about liblinalg_kernels.so, do the following:
96109
# PYLSPACK_LOCATION="$(pip show pylspack | grep Location: | awk '{print $2}')/pylspack/"
97110
# export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PYLSPACK_LOCATION}
98-
pip install -r test_requirements.txt
99-
pytest -svvv test
100111
```
101112

102113
## Contributing

pylspack/linalg_kernels.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
from scipy.sparse import csr_matrix
88

99
libdir = os.path.dirname(os.path.realpath(__file__))
10-
try:
11-
libfile = glob.glob('{}/liblinalg_kernels*.so'.format(libdir))[0]
12-
ext_lib = CDLL(os.path.join(libdir, libfile))
13-
except Exception as e:
14-
print('Warning: could not find {}/liblinalg_kernels*.so'.format(libdir))
15-
print('Caught exception: {}. Trying to load from LD_LIBRARY_PATH...'.format(e))
16-
ext_lib = CDLL('liblinalg_kernels.so')
10+
libfile = glob.glob(f'{libdir}/liblinalg_kernels*')
11+
if libfile:
12+
ext_lib = CDLL(os.path.join(libdir, libfile[0]))
13+
else:
14+
print(f'Warning: could not find {libdir}/liblinalg_kernels*')
15+
try:
16+
print('Trying to fild liblinalg_kernels.so from LD_LIBRARY_PATH...')
17+
ext_lib = CDLL('liblinalg_kernels.so')
18+
except Exception:
19+
print('Trying to fild liblinalg_kernels.dylib from LD_LIBRARY_PATH...')
20+
ext_lib = CDLL('liblinalg_kernels.dylib')
1721

1822
# arg types
1923
ext_lib.csrcgs.argtypes = [
@@ -48,12 +52,12 @@ def assert_shape(a: int, b: int) -> None:
4852

4953

5054
def assert_dtype(A: np.ndarray, dtype: str) -> None:
51-
if A.dtype != dtype:
55+
if A.dtype != dtype: # type: ignore
5256
raise TypeError('unsupported dtype: {}.'.format(A.dtype))
5357

5458

5559
def assert_contiguous_type(A: np.ndarray, contiguous_type: str) -> None:
56-
if A.flags[contiguous_type] is False:
60+
if A.flags[contiguous_type] is False: # type: ignore
5761
raise TypeError('array is not {} as expected.'.format(contiguous_type))
5862

5963

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def read_readme(fname):
4747

4848
setup(
4949
name='pylspack',
50-
version='1.0.1',
50+
version='1.0.2',
5151
description='Python package for leverage scores computations.',
5252
author='Sobczyk Aleksandros',
5353
author_email='[email protected]',

src/csr_kernels.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ extern "C" {
186186
double *_C;
187187
int i, j, k, up, lo;
188188

189+
double *G = new double[m];
189190
#pragma omp parallel private(_C, i, j, k, up, lo)
190191
{
191192
double A_ki;
@@ -197,11 +198,11 @@ extern "C" {
197198
row_limits.second = block_size * ( thread_id + 1 );
198199
row_limits.second = std::min( row_limits.second, m );
199200
const int n_rows = row_limits.second - row_limits.first;
200-
double *_G = new double[n_rows];
201201
std::random_device rd{};
202202
std::mt19937_64 gen{rd()};
203203
std::normal_distribution<double> dist;
204204

205+
double *_G = &( G[ row_limits.first ] );
205206
for ( k = 0; k < n; ++k ) {
206207
lo = A_indptr[k];
207208
up = A_indptr[k + 1];
@@ -224,9 +225,9 @@ extern "C" {
224225
}
225226
}
226227
}
227-
228-
delete[] _G;
229228
}
229+
230+
delete[] G;
230231
double scale_factor = static_cast<double>( 1 ) / sqrt( static_cast<double>( m ) );
231232
scale( m, d, C, scale_factor );
232233
}

test/__init__.py

Whitespace-only changes.

test/test_csrrk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from scipy.sparse import csr_matrix
33
import pytest
44
from pylspack.linalg_kernels import csrrk
5-
from .utils import (
5+
from utils import (
66
eps_machine, min_size, max_size, alpha_beta_pairs_generic, get_random_matrices,
77
set_arrays_elements_to_value
88
)

test/test_csrsqn.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from scipy.sparse import csr_matrix
33
import pytest
44
from pylspack.linalg_kernels import csrsqn
5-
from .utils import (
5+
from utils import (
66
eps_machine, alpha_beta_pairs_generic, get_random_matrices, set_arrays_elements_to_value
77
)
8-
from .utils import A_shapes_generic as A_shapes
9-
from .utils import B_shapes_generic as B_shapes
8+
from utils import A_shapes_generic as A_shapes
9+
from utils import B_shapes_generic as B_shapes
1010

1111

1212
def execute_and_check(alpha: float, A: csr_matrix, B: np.ndarray, beta: float, C: np.ndarray):

test/test_gemm.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import numpy as np
22
import pytest
33
from pylspack.linalg_kernels import gemm
4-
from .utils import (
4+
from utils import (
55
eps_machine, alpha_beta_pairs_generic, get_random_matrices, set_arrays_elements_to_value
66
)
7-
from .utils import A_shapes_generic as A_shapes
8-
from .utils import B_shapes_generic as B_shapes
7+
from utils import A_shapes_generic as A_shapes
8+
from utils import B_shapes_generic as B_shapes
99

1010

1111
def execute_and_check(alpha: float, A: np.ndarray, B: np.ndarray, beta: float, C: np.ndarray):

test/test_leverage_scores.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
sample_columns, ls_via_inv_gram, ls_via_sketched_svd, ls_hrn_exact, ls_hrn_approx,
77
get_rank_from_vector
88
)
9-
from .utils import eps_machine
9+
from utils import eps_machine
1010

1111
density = [0.1, 0.3, 1]
1212
matrices = [
@@ -19,7 +19,7 @@
1919
def test_get_rank_from_vector():
2020
s = np.zeros((10, ))
2121
assert get_rank_from_vector(s, rcond=0.5) == 0
22-
s = np.arange(10, 0, -1)
22+
s = np.arange(10, 0, -1) # type: ignore
2323
assert get_rank_from_vector(s, rcond=0.65) == 4
2424
assert get_rank_from_vector(s, rcond=0.05) == 10
2525
assert get_rank_from_vector(s, rcond=0) == 10

test/test_rmdsc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33
from pylspack.linalg_kernels import rmdsc
4-
from .utils import eps_machine, min_size, max_size, set_arrays_elements_to_value
4+
from utils import eps_machine, min_size, max_size, set_arrays_elements_to_value
55

66
B_shapes = [(1, 1), (3, 1), (1, 3), (3, 3), (17, 5), (17, 17), (237, 631), (631, 237), (237, 237)]
77
D_shapes = [(1, 1), (1, 1), (3, 3), (3, 3), (5, 5), (17, 17), (631, 631), (237, 237), (237, 237)]

test/test_rmsqn.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import numpy as np
22
import pytest
33
from pylspack.linalg_kernels import rmsqn
4-
from .utils import (
4+
from utils import (
55
eps_machine, alpha_beta_pairs_generic, get_random_matrices, set_arrays_elements_to_value
66
)
7-
from .utils import A_shapes_generic as A_shapes
8-
from .utils import B_shapes_generic as B_shapes
7+
from utils import A_shapes_generic as A_shapes
8+
from utils import B_shapes_generic as B_shapes
99

1010

1111
def execute_and_check(alpha: float, A: np.ndarray, B: np.ndarray, beta: float, C: np.ndarray):

test/test_scale.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import numpy as np
22
import pytest
33
from pylspack.linalg_kernels import scale
4-
from .utils import eps_machine
5-
from .utils import A_shapes_generic as A_shapes
4+
from utils import eps_machine
5+
from utils import A_shapes_generic as A_shapes
66

77

88
def execute_and_check(A: np.ndarray, alpha: float):

test/test_set_randn.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33
from pylspack.linalg_kernels import set_randn
4-
from .utils import A_shapes_generic as A_shapes
4+
from utils import A_shapes_generic as A_shapes
55

66

77
def execute_and_check(A: np.ndarray):

test/test_set_value.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33
from pylspack.linalg_kernels import set_value
4-
from .utils import A_shapes_generic as A_shapes
4+
from utils import A_shapes_generic as A_shapes
55

66

77
def execute_and_check(A: np.ndarray, alpha: float):

0 commit comments

Comments
 (0)