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

sparse.linalg.expm_multiply causes ValueError when fed with (dense, sparse, *args) #9771

Open
daniel-edler opened this issue Feb 6, 2019 · 0 comments

Comments

@daniel-edler
Copy link

daniel-edler commented Feb 6, 2019

The following works

  • expm_multiply(A, B) without optional parameter (which is equivalent to _expm_multiply_simple(A, B))
  • expm_multiply(A, B, start, stop, num) where
    • type(A) == numpy.ndarray and type(B) == scipy.sparse.csc.csc_matrix
    • and of course type(A) == numpy.ndarray and type(B) == numpy.ndarray

The following fails

...and throws a ValueError: setting an array element with a sequence exception:

  • expm_multiply(A, B, start, stop, num) where
    • type(A) == scipy.sparse.csc.csc_matrix and type(B) == numpy.ndarray
    • type(A) == scipy.sparse.csc.csc_matrix and type(B) == scipy.sparse.csc.csc_matrix

Example

import numpy as np
import scipy.sparse.linalg as linalg
from scipy.sparse import csc_matrix

A = np.array([[1, 0], [0, 1]])
B = csc_matrix([[np.exp(-1.), np.exp(-2.)],[0, 1]])

linalg.expm_multiply(A, B, start=1, stop=2, num=2)

Attempt to understand the problem

The traceback points to line 597 in scipy/scipy/sparse/linalg/_expm_multiply.py

 X[0] = _expm_multiply_simple_core(A, B, t_0, mu, m_star, s)

where _expm_multiply_simple_core(A, B, t_0, mu, m_star, s) returns a sparse matrix but X is a numpy matrix of type np.result_type(A.dtype, B.dtype, float) (In my case a float64) . So either the np.result_type function should have returned the type object to store the sparse matrices or in such cases _expm_multiply_simple_core(A, B, t_0, mu, m_star, s) should be transformed to a dense matrix.

Scipy/Numpy/Python version information:

1.1.0 1.15.1 sys.version_info(major=3, minor=6, micro=7, releaselevel='final', serial=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants