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

Perpare Ad framework for the use of scipy sparse arrays #1319

Open
keileg opened this issue Jan 30, 2025 · 0 comments
Open

Perpare Ad framework for the use of scipy sparse arrays #1319

keileg opened this issue Jan 30, 2025 · 0 comments

Comments

@keileg
Copy link
Contributor

keileg commented Jan 30, 2025

Scipy.sparse is moving to a new implementation, based on what they term sparse arrays rather than sparse matrices, see documentation for more information. As of now, it is unclear to which degree we will and should introduce the new format, but we should at least make the Ad framework ready for it.

Changes needed:

  1. The AdArray class should be able to deal with sps.sparray and subclasses. My feeling is that this to a large degree is a question of replacing checks of the type if isinstance(mat, sps.spmatrix) to if isinstance(mat, (sps.spmatrix, sps.sparray)), but this should be checked.
  2. Tests must be updated. In the first instance, the target should be the method test_arithmetic_operations_on_ad_objects() in tests/numerics/ad/test_operators.py, which should be rewritten to cover both sparse arrays and matrices. My first idea is to change the parametrization of this function to include both sparse_matrix (which replaces the current sparse) and sparse_array. Furthermore, the method to get hold of the matrix (current method _get_sparse_array()), should be invoked both for sparse arrays and matrices, but the wrapped array (line mat = sps.csr_matrix in _get_sparse_array) should be changed to mat = sps.csr_array when relevant.

It may be that further tweaks are needed, this will have to be seen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant