Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic CSC and CSR sparse matrix support #92

Merged
merged 5 commits into from
Mar 31, 2023

Conversation

brandonwillard
Copy link
Contributor

@brandonwillard brandonwillard commented Dec 9, 2022

This PR adds basic type support for CSC and CSR sparse matrices. It's just a start to adding real sparse matrix support (i.e. #29), but it at least allows one to use object mode in a more constrained way and reference simple properties of sparse matrices. More useful additions will follow.

@brandonwillard
Copy link
Contributor Author

@esc
Copy link
Member

esc commented Dec 12, 2022

It looks like the environment is missing a command used by the build script?

It looks like catchsegv isn't installed on the host doing the testing?

@guilhermeleobas
Copy link

guilhermeleobas commented Jan 10, 2023

catchsegv is available from glibc. Could we get that installed? Or perhaps don't use catchsegv if it is not installed:

if [[ "$unamestr" == 'Linux' ]]; then
    if [[ "${BITS32}" == "yes" ]]; then
        SEGVCATCH=""
    else
        if command -v catchsegv; then
            CATCHSEGV=catchsegv
        else
            CATCHSEGV=""
        fi
    fi

@guilhermeleobas
Copy link

All tests pass locally, but I had to manually import sparse at the top level of test_sparse.py

$ pytest -rs -sv numba_scipy/tests/test_sparse.py --tb=short -x
========================================================================================================================= test session starts ==========================================================================================================================
platform darwin -- Python 3.10.8, pytest-7.2.0, pluggy-1.0.0 -- /Users/guilhermeleobas/miniconda3/envs/numba-scipy/bin/python3.10
cachedir: .pytest_cache
rootdir: /Users/guilhermeleobas/git/numba-scipy
collected 5 items

numba_scipy/tests/test_sparse.py::test_sparse_unboxing PASSED
numba_scipy/tests/test_sparse.py::test_sparse_boxing PASSED
numba_scipy/tests/test_sparse.py::test_sparse_shape PASSED
numba_scipy/tests/test_sparse.py::test_sparse_ndim PASSED
numba_scipy/tests/test_sparse.py::test_sparse_copy PASSED

@brandonwillard brandonwillard force-pushed the add-scipy-sparse-basics branch 2 times, most recently from 1a638be to f6a491a Compare January 10, 2023 18:23
@brandonwillard
Copy link
Contributor Author

All tests pass locally, but I had to manually import sparse at the top level of test_sparse.py

Fixed.

@guilhermeleobas
Copy link

@brandonwillard, code looks good. My only suggestion is to emit a NumbaExperimentalFeatureWarning. Also, it looks like you have a failure in one of the Azure CI jobs.

As for the current catchsegv failure. Could you add the following to the github actions file:

- name: Install glibc-tools
  shell: bash -l {0}
  run: |
    if [[ $(uname) == Linux ]]; then
      sudo apt-get install glibc-tools
    fi

@brandonwillard
Copy link
Contributor Author

@brandonwillard, code looks good. My only suggestion is to emit a NumbaExperimentalFeatureWarning.

Should this be on module load? Seems like that might cause the warning to be emitted whenever numba_scipy is loaded, no?

Also, it looks like you have a failure in one of the Azure CI jobs.

Oh, perhaps that's due to the changes between Numba 0.47.0+0.g4eb9cf875.dirty and 0.53.1.

As for the current catchsegv failure. Could you add the following to the github actions file:

I added that liberally.

@brandonwillard
Copy link
Contributor Author

Yes, that's it: Numba 0.47 appears to have some important differences that cause this approach to fail.

@brandonwillard brandonwillard force-pushed the add-scipy-sparse-basics branch from a9386bf to 93285a4 Compare January 11, 2023 02:45
@brandonwillard
Copy link
Contributor Author

I've updated the imports so that some of the module changes between versions are handled, but that doesn't seem to do the trick locally.

@guilhermeleobas
Copy link

guilhermeleobas commented Jan 11, 2023

Yes, that's it: Numba 0.47 appears to have some important differences that cause this approach to fail.

I'm impressed that one of the CI jobs is using Numba 0.47 as it is almost ten versions older. I'll raise this at the next public meeting to update the CI config used here.

Should this be on module load? Seems like that might cause the warning to be emitted whenever numba_scipy is loaded, no?

Try to put the warning at the __init__ method of CSMatrixType.

.github/workflows/test_and_deploy.yml Outdated Show resolved Hide resolved
.github/workflows/test_and_deploy.yml Outdated Show resolved Hide resolved
@brandonwillard brandonwillard force-pushed the add-scipy-sparse-basics branch 2 times, most recently from db16cfe to d14617d Compare January 11, 2023 19:08
@brandonwillard
Copy link
Contributor Author

Yes, that's it: Numba 0.47 appears to have some important differences that cause this approach to fail.

I'm impressed that one of the CI jobs is using Numba 0.47 as it is almost ten versions older. I'll raise this at the next public meeting to update the CI config used here.

Thanks; making this support much older versions already seems like it could be a real hassle.

Should this be on module load? Seems like that might cause the warning to be emitted whenever numba_scipy is loaded, no?

Try to put the warning at the __init__ method of CSMatrixType.

Done.

@brandonwillard brandonwillard force-pushed the add-scipy-sparse-basics branch from d14617d to c9ae99b Compare January 11, 2023 19:14
@brandonwillard brandonwillard force-pushed the add-scipy-sparse-basics branch from c9ae99b to 5a52147 Compare January 11, 2023 19:15
@stuartarchibald
Copy link
Contributor

Yes, that's it: Numba 0.47 appears to have some important differences that cause this approach to fail.

I'm impressed that one of the CI jobs is using Numba 0.47 as it is almost ten versions older. I'll raise this at the next public meeting to update the CI config used here.

Thanks; making this support much older versions already seems like it could be a real hassle.

I suspect this is coming from CI using Python 3.6 and 3.7, Numba 0.57 (currently in development) has a baseline of Python 3.8. Perhaps move all the Python versions in CI up by a .1 and see if that helps?

@brandonwillard
Copy link
Contributor Author

Yes, that's it: Numba 0.47 appears to have some important differences that cause this approach to fail.

I'm impressed that one of the CI jobs is using Numba 0.47 as it is almost ten versions older. I'll raise this at the next public meeting to update the CI config used here.

Thanks; making this support much older versions already seems like it could be a real hassle.

I suspect this is coming from CI using Python 3.6 and 3.7, Numba 0.57 (currently in development) has a baseline of Python 3.8. Perhaps move all the Python versions in CI up by a .1 and see if that helps?

It seems like it's all passing now for related reasons.

@guilhermeleobas
Copy link

@brandonwillard, can you add docs for your changes?

@guilhermeleobas
Copy link

@brandonwillard, let me know once you have the chance to update the docs and we can merge this PR.

@brandonwillard
Copy link
Contributor Author

@brandonwillard, let me know once you have the chance to update the docs and we can merge this PR.

I'll try to do that in the next day or so. If I don't, feel free to send me another reminder.

@guilhermeleobas
Copy link

Hi @brandonwillard. Quick update on my side. I'll review this PR later this week.

Comment on lines +54 to +55
self.indices = types.Array(types.int32, 1, "A")
self.indptr = types.Array(types.int32, 1, "A")
Copy link

@ivirshup ivirshup Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, but these can also be int64. Scipy is pretty aggressive about down casting it to int32, but if you have enough values to need 64 bit integers they will stick around.

Super excited to see this moving forward!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, but these can also be int64. Scipy is pretty aggressive about down casting it to int32, but if you have enough values to need 64 bit integers they will stick around.

Super excited to see this moving forward!

Thanks for the heads up! If no one objects, I'll be glad to change them.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linking in some relevant discussion from scipy, since it came up on my notifications again: scipy/scipy#16774

tldr (from my perspective) scipy wants to be more supportive of int64 indices, and remove the automatic down casting to int32 since checking the values is expensive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guilhermeleobas, are you folks cool with these changes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brandonwillard can you submit this change in a new PR, if it is still needed?

Copy link

@guilhermeleobas guilhermeleobas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @brandonwillard.

@guilhermeleobas guilhermeleobas added 5 - Ready to merge Review and testing done, is ready to merge and removed 5 - Ready to merge Review and testing done, is ready to merge labels Mar 28, 2023
@guilhermeleobas
Copy link

@esc, Could you take a look at this PR and merge it if possible?

Co-authored-by: stuartarchibald <stuartarchibald@users.noreply.github.com>
@esc
Copy link
Member

esc commented Mar 31, 2023

@stuartarchibald thank you for the last review. I will merge this now trusting everyone involved. Thank you all for the patch!

Copy link
Member

@esc esc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@esc esc merged commit d1fc4e1 into numba:main Mar 31, 2023
@esc esc added the 5 - Ready to merge Review and testing done, is ready to merge label Mar 31, 2023
@esc
Copy link
Member

esc commented Mar 31, 2023

the deployment to anacona.org broke on this one because the token was out of date.

@esc
Copy link
Member

esc commented Mar 31, 2023

I deployed a fresh token and retriggered the action to produce a new dev package:

https://anaconda.org/numba/numba-scipy/files?version=0.4.0dev0&type=conda&channel=dev

@esc esc mentioned this pull request Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to merge Review and testing done, is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants