Use scipy.sparse arrays#7576
Conversation
6452e61 to
eda36b0
Compare
eda36b0 to
23c63ae
Compare
|
@stefanv @dschult Any thoughts about the error in this PR? The main error is That looks like a bug to me, but I am not sure. When we test against our minimum requirements we use scipy-1.10.0 and get errors like this as well: because I changed to What is the recommend upgrade path for projects that want to switch to sparse arrays, but plan to support scipy 1.10 and above? We are also getting errors like this with scipy-1.10.0: |
|
According to https://scipy.github.io/devdocs/reference/generated/scipy.sparse.diags_array.html#scipy.sparse.diags_array diags_array was added in 1.11. But I couldn't find it in the documentation for 1.11. I went searching and it looks like I may have taken it out: scipy/scipy#18599 All the constructors seem to have been introduced in 1.12. But only diags_array has an "Added in version" notice (and it is wrongly states 1.11). |
|
Dan just submitted an update to the docs, I don't think it fixes the version, but dia_array can often be instantiated directly, instead of using diags. |
|
What should we do about the dtype issue? |
|
Dan figured out that we need to ensure that the index dtype is 32-bit for pyamg. Currently, dtype is inferred from type used in constructor, I believe, without a way to make it explicit. Bad :) There is an internal method to use to fix that. Hopefully I can get to it on Friday, or maybe Dan is feeling generous before then. |
|
I believe The calls to Can you give me an overview of the goals or intents and scope of this PR? The OP looks anemic. :) What are we working toward? |
|
I made a PR to @jarrodmillman 's branch. Downcasting before sending to pyamg seems to "work", but inside pyamg they are converting back to csr_matrix, and they warn that it might not be efficient. That's cause they identify that it has CSR format using |
|
@dschult Thanks!! It looks like your PR only fixes the CI when pyamg is installed (i.e., linux-cp3.12-optional-deps). In the other tests, whne pyamg is not installed, we are getting same error as before. |
debb62e to
5b72717
Compare
dschult
left a comment
There was a problem hiding this comment.
To fix the lack of diags_array in earlier versions of scipy, let's try constructing the dia_array directly. It's just the main diagonal so shouldn't mess up length of the diagonals (which are treated differently for diags_array and dia_array when offset != 0). (untested)
fd34a81 to
39d7e1c
Compare
|
It looks like the only failing test now is I am getting different results locally when I run it. It looks like the Why would the result change from one run to another? Is there roundoff error or randomness involved? |
|
Looks like the cut_normalized error is due to a matrix multiplication that was still using skimage/graph/_graph_cut.py:281 It looks like there might be others: Step 1 of the magration guide is probably the hardest. Can we create a tool that runs code/tests and raises whenever |
1827a90 to
2cc3ebb
Compare
|
Looks like another I have created a way to look for places where Any suggestions/thoughts are appreciated. I'm thinking of adding it to the migration guide along with possibly helpful Code to find spmatrix opsimport scipy
class _strict_mul_mixin:
def __mul__(self, other):
if not scipy.sparse._sputils.isscalarlike(other):
raise ValueError('Operator * used here! Change to @?')
return super().__mul__(other)
def __rmul__(self, other):
if not scipy.sparse._sputils.isscalarlike(other):
raise ValueError('Operator * used here! Change to @?')
return super().__rmul__(other)
def __imul__(self, other):
if not scipy.sparse._sputils.isscalarlike(other):
raise ValueError('Operator * used here! Change to @?')
return super().__imul__(other)
def __pow__(self, *args, **kwargs):
raise ValueError('spmatrix ** found! Use linalg.matrix_power?')
class _strict_coo_matrix(_strict_mul_mixin, scipy.sparse.coo_matrix):
pass
class _strict_bsr_matrix(_strict_mul_mixin, scipy.sparse.bsr_matrix):
pass
class _strict_csr_matrix(_strict_mul_mixin, scipy.sparse.csr_matrix):
pass
class _strict_csc_matrix(_strict_mul_mixin, scipy.sparse.csc_matrix):
pass
class _strict_dok_matrix(_strict_mul_mixin, scipy.sparse.dok_matrix):
pass
class _strict_lil_matrix(_strict_mul_mixin, scipy.sparse.lil_matrix):
pass
class _strict_dia_matrix(_strict_mul_mixin, scipy.sparse.dia_matrix):
pass
scipy.sparse.coo_matrix = scipy.sparse._coo.coo_matrix = _strict_coo_matrix
scipy.sparse.bsr_matrix = scipy.sparse._bsr.bsr_matrix = _strict_bsr_matrix
scipy.sparse.csr_matrix = scipy.sparse._csr.csr_matrix = _strict_csr_matrix
scipy.sparse.csc_matrix = scipy.sparse._csc.csc_matrix = _strict_csc_matrix
scipy.sparse.dok_matrix = scipy.sparse._dok.dok_matrix = _strict_dok_matrix
scipy.sparse.lil_matrix = scipy.sparse._lil.lil_matrix = _strict_lil_matrix
scipy.sparse.dia_matrix = scipy.sparse._dia.dia_matrix = _strict_dia_matrix |
1e8ec1e to
9f5d6b2
Compare
| # Don't use the cache provider plugin, as it doesn't work with Pyodide | ||
| # right now: https://github.com/pypa/cibuildwheel/issues/1966 | ||
| pytest -svra -p no:cacheprovider --pyargs skimage | ||
| # pytest -svra -p no:cacheprovider --pyargs skimage |
There was a problem hiding this comment.
This will be re-enabled in a follow-up PR.
bad60db to
e82056a
Compare
fe64f45 to
feb9cfe
Compare
* CI: bump macos image pin from 12 to 13 (scikit-image#7582) * Use scipy.sparse arrays * updates to downcast for amg_core and simplify CSR --------- Co-authored-by: Brigitta Sipőcz <[email protected]> Co-authored-by: Jarrod Millman <[email protected]>
Co-authored-by: Dan Schult <[email protected]>
Partially reverts 60831c4. This should accept both, csc_array and csr_array. Co-authored-by: Dan Schult <[email protected]>
as pointed out by Dan. Co-authored-by: Dan Schult <[email protected]>
0992754 to
992cc5b
Compare
|
Just curious why you chose to use a merge commit instead of squashing here? The PR commit history doesn't seem particularly useful to preserve? |
GH remembers the default, so it's easy to accidentally revert to one or the other. Oh well. |
Leaving this commented is probably an oversight from scikit-imagegh-7576 / a7b54a8.
* Use pytest config in pyroject.toml in CI This should be safe, as the pytest documentation [1] states that "rootdir is NOT used to modify sys.path/PYTHONPATH". So while the `--config-file` option affects the `rootdir`, it's not adding that directory to the PYTHONPATH where it could accidentally overwrite the installed package. This solution is somewhat unsatisfying. Personally, I think a better approach would be to switch to the src-layout. [1] https://docs.pytest.org/en/7.1.x/reference/customize.html?highlight=rootdir#initialization-determining-rootdir-and-configfile * Use correct operator to check if GITHUB_WORKSPACE exists * Ignore missing dask dependency in cycle_spin * Don't expect newbyteorder warning caused by tifffile I believe this warning disappeared with tifffile 2024.4.24 which added support for NumPy 2. * Ignore warning if cg_mg is not available (missing pyamg) * Update test scripts in new locations * Pin higher version of pytest * Pin newer dask to get rid of distutils warning * Expect sparse efficiency warnings until new pyamg * New dask version requires newer cloudpickle * Tell pytest where to find SparseEfficiencyWarning * Catch additional warnings * Up minimum version of SciPy to fix sparse errors * Catch additional warning * Ignore warnings raised by pyamg internally * Use a reasonable range in simpleitk roundtrip test * Re-enable testing in Emscripten/Pyodide job Leaving this commented is probably an oversight from gh-7576 / a7b54a8. --------- Co-authored-by: Stefan van der Walt <[email protected]>
Description
Checklist
./doc/examplesfor new featuresRelease note
For maintainers and optionally contributors, please refer to the instructions on how to document this PR for the release notes.