flow_stability
flow_stability copied to clipboard
Type declaration for `indices` and `indptr` might lead to dtype mismatch
When passing the arguments of a scipy.sparse.csr_matrix
to sparse_stoch_from_full_csr
we run into a ValueError
:
long long[:] Tf_indices, E ValueError: Buffer dtype mismatch, expected 'long long' but got 'int'
See e.g. here
We can address this by explicitly converting the indices to np.int64
when passing them as arguments, or we might change datat type to int
instead of long long
in sparse_stochfrom_full_csr
(and others).
Note that for some functions in _cython_sparse_stoch.pyx already declare int[:]
as data type when indices are passed as arguments.
We have some issues with the type declarations for `indices` and `indptr`:
https://github.com/alexbovet/flow_stability/actions/runs/10513029536/job/29127746857#step:5:116
It also seems not completely consistent in the defs:
E.g. for indptr
some functions require int
:
https://github.com/alexbovet/flow_stability/blob/8648a8bd715e3b086ed13cb7453d41754c176398/src/flowstab/_cython_sparse_stoch.pyx#L859-L863
some long long
:
https://github.com/alexbovet/flow_stability/blob/8648a8bd715e3b086ed13cb7453d41754c176398/src/flowstab/_cython_sparse_stoch.pyx#L613-L618
I'd put everything indices
and indptr
to long
and declare with np.int64
on the python site.
@alexbovet is that OK for you or is there actually a use-case for long long
?
Originally posted by @j-i-l in https://github.com/alexbovet/flow_stability/issues/35#issuecomment-2305337823