Skip to content

Commit

Permalink
Fix test and import for macos (#3)
Browse files Browse the repository at this point in the history
* Fix imports for macos

* Bump version 1.0.2

* fix actions
  • Loading branch information
asobczyk committed Mar 11, 2022
1 parent ae59fdc commit 9ec3a0a
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ jobs:
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 .
- name: Test with pytest
run: |
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:"$(pip show pylspack | grep 'Location:' | awk '{print $2}')/pylspack/" && python3 -m pytest -svvv test
cd test && python3 -m pytest -svvv .
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,29 @@ As already noted, the implementation is designed for existing data structures of
The C++ API **can** be used as a standalone package, but it has not been tested.

### Citation
The corresponding publication https://doi.org/10.1137/20m1314471 can be cited as follows:
If you use this software in academic work, please consider citing the corresponding publications:
- https://doi.org/10.1137/20m1314471
```
@article{Sobczyk2021,
doi = {10.1137/20m1314471},
url = {https://doi.org/10.1137/20m1314471},
year = {2021},
publisher = {Society for Industrial {\&} Applied Mathematics ({SIAM})},
volume = {42},
number = {3},
pages = {1199--1228},
author = {Aleksandros Sobczyk and Efstratios Gallopoulos},
title = {Estimating Leverage Scores via Rank Revealing Methods and Randomization},
journal = {{SIAM} Journal on Matrix Analysis and Applications}
@article{sobczyk2021estimating,
title={Estimating leverage scores via rank revealing methods and randomization},
author={Sobczyk, Aleksandros and Gallopoulos, Efstratios},
journal={SIAM Journal on Matrix Analysis and Applications},
volume={42},
number={3},
pages={1199--1228},
year={2021},
doi={10.1137/20m1314471},
url={https://doi.org/10.1137/20m1314471},
publisher={SIAM}
}
```
- https://doi.org/10.48550/arxiv.2203.02798
```
@article{sobczyk2022pylspack,
title={pylspack: Parallel algorithms and data structures for sketching, column subset selection, regression and leverage scores},
author={Sobczyk, Aleksandros and Gallopoulos, Efstratios},
journal={arXiv preprint arXiv:2203.02798},
year={2022}
}
```

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

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

## Contributing
Expand Down
22 changes: 13 additions & 9 deletions pylspack/linalg_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
from scipy.sparse import csr_matrix

libdir = os.path.dirname(os.path.realpath(__file__))
try:
libfile = glob.glob('{}/liblinalg_kernels*.so'.format(libdir))[0]
ext_lib = CDLL(os.path.join(libdir, libfile))
except Exception as e:
print('Warning: could not find {}/liblinalg_kernels*.so'.format(libdir))
print('Caught exception: {}. Trying to load from LD_LIBRARY_PATH...'.format(e))
ext_lib = CDLL('liblinalg_kernels.so')
libfile = glob.glob(f'{libdir}/liblinalg_kernels*')
if libfile:
ext_lib = CDLL(os.path.join(libdir, libfile[0]))
else:
print(f'Warning: could not find {libdir}/liblinalg_kernels*')
try:
print('Trying to fild liblinalg_kernels.so from LD_LIBRARY_PATH...')
ext_lib = CDLL('liblinalg_kernels.so')
except Exception:
print('Trying to fild liblinalg_kernels.dylib from LD_LIBRARY_PATH...')
ext_lib = CDLL('liblinalg_kernels.dylib')

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


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


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


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def read_readme(fname):

setup(
name='pylspack',
version='1.0.1',
version='1.0.2',
description='Python package for leverage scores computations.',
author='Sobczyk Aleksandros',
author_email='obc@zurich.ibm.com',
Expand Down
7 changes: 4 additions & 3 deletions src/csr_kernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ extern "C" {
double *_C;
int i, j, k, up, lo;

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

double *_G = &( G[ row_limits.first ] );
for ( k = 0; k < n; ++k ) {
lo = A_indptr[k];
up = A_indptr[k + 1];
Expand All @@ -224,9 +225,9 @@ extern "C" {
}
}
}

delete[] _G;
}

delete[] G;
double scale_factor = static_cast<double>( 1 ) / sqrt( static_cast<double>( m ) );
scale( m, d, C, scale_factor );
}
Expand Down
Empty file removed test/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion test/test_csrrk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from scipy.sparse import csr_matrix
import pytest
from pylspack.linalg_kernels import csrrk
from .utils import (
from utils import (
eps_machine, min_size, max_size, alpha_beta_pairs_generic, get_random_matrices,
set_arrays_elements_to_value
)
Expand Down
6 changes: 3 additions & 3 deletions test/test_csrsqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from scipy.sparse import csr_matrix
import pytest
from pylspack.linalg_kernels import csrsqn
from .utils import (
from utils import (
eps_machine, alpha_beta_pairs_generic, get_random_matrices, set_arrays_elements_to_value
)
from .utils import A_shapes_generic as A_shapes
from .utils import B_shapes_generic as B_shapes
from utils import A_shapes_generic as A_shapes
from utils import B_shapes_generic as B_shapes


def execute_and_check(alpha: float, A: csr_matrix, B: np.ndarray, beta: float, C: np.ndarray):
Expand Down
6 changes: 3 additions & 3 deletions test/test_gemm.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import numpy as np
import pytest
from pylspack.linalg_kernels import gemm
from .utils import (
from utils import (
eps_machine, alpha_beta_pairs_generic, get_random_matrices, set_arrays_elements_to_value
)
from .utils import A_shapes_generic as A_shapes
from .utils import B_shapes_generic as B_shapes
from utils import A_shapes_generic as A_shapes
from utils import B_shapes_generic as B_shapes


def execute_and_check(alpha: float, A: np.ndarray, B: np.ndarray, beta: float, C: np.ndarray):
Expand Down
4 changes: 2 additions & 2 deletions test/test_leverage_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
sample_columns, ls_via_inv_gram, ls_via_sketched_svd, ls_hrn_exact, ls_hrn_approx,
get_rank_from_vector
)
from .utils import eps_machine
from utils import eps_machine

density = [0.1, 0.3, 1]
matrices = [
Expand All @@ -19,7 +19,7 @@
def test_get_rank_from_vector():
s = np.zeros((10, ))
assert get_rank_from_vector(s, rcond=0.5) == 0
s = np.arange(10, 0, -1)
s = np.arange(10, 0, -1) # type: ignore
assert get_rank_from_vector(s, rcond=0.65) == 4
assert get_rank_from_vector(s, rcond=0.05) == 10
assert get_rank_from_vector(s, rcond=0) == 10
Expand Down
2 changes: 1 addition & 1 deletion test/test_rmdsc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest
from pylspack.linalg_kernels import rmdsc
from .utils import eps_machine, min_size, max_size, set_arrays_elements_to_value
from utils import eps_machine, min_size, max_size, set_arrays_elements_to_value

B_shapes = [(1, 1), (3, 1), (1, 3), (3, 3), (17, 5), (17, 17), (237, 631), (631, 237), (237, 237)]
D_shapes = [(1, 1), (1, 1), (3, 3), (3, 3), (5, 5), (17, 17), (631, 631), (237, 237), (237, 237)]
Expand Down
6 changes: 3 additions & 3 deletions test/test_rmsqn.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import numpy as np
import pytest
from pylspack.linalg_kernels import rmsqn
from .utils import (
from utils import (
eps_machine, alpha_beta_pairs_generic, get_random_matrices, set_arrays_elements_to_value
)
from .utils import A_shapes_generic as A_shapes
from .utils import B_shapes_generic as B_shapes
from utils import A_shapes_generic as A_shapes
from utils import B_shapes_generic as B_shapes


def execute_and_check(alpha: float, A: np.ndarray, B: np.ndarray, beta: float, C: np.ndarray):
Expand Down
4 changes: 2 additions & 2 deletions test/test_scale.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
import pytest
from pylspack.linalg_kernels import scale
from .utils import eps_machine
from .utils import A_shapes_generic as A_shapes
from utils import eps_machine
from utils import A_shapes_generic as A_shapes


def execute_and_check(A: np.ndarray, alpha: float):
Expand Down
2 changes: 1 addition & 1 deletion test/test_set_randn.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest
from pylspack.linalg_kernels import set_randn
from .utils import A_shapes_generic as A_shapes
from utils import A_shapes_generic as A_shapes


def execute_and_check(A: np.ndarray):
Expand Down
2 changes: 1 addition & 1 deletion test/test_set_value.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest
from pylspack.linalg_kernels import set_value
from .utils import A_shapes_generic as A_shapes
from utils import A_shapes_generic as A_shapes


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

0 comments on commit 9ec3a0a

Please sign in to comment.