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
BUG: linalg.solve_{sylvester, continuous_lyapunov}: empty array support #20528
base: main
Are you sure you want to change the base?
Conversation
Add two ValueError for shape consistency in solve_sylvester
solve_{sylvester, continuous_lyapunov}
: empty array support
solve_{sylvester, continuous_lyapunov}
: empty array support
scipy/linalg/_solvers.py
Outdated
dt = np.result_type(a, b, q) | ||
if dt == int: | ||
dt = np.float64 | ||
return np.empty(q.shape, dtype=dt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you can write the following
tdict = {'s': np.float32, 'd': np.float64, 'c': np.complex64, 'z': np.complex128}
func = get_lapack_funcs(('trsyl',), arrays=(a, b, q))
return np.empty(q.shape, dtype=tdict[func.typecode])
First line creates the mapping from lapack types to numpy types, second line searches for the suitable type given the arrays (uses an example array of 'trsyl' but can be anything). Third line uses the resulting lapack type to get the numpy type of q
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Done 👍
Reference issue
Check the boxes solve_sylvester and solve_continuous_lyapunov Linalg empty array support #20372
What does this implement/fix?
The functions now support empty array and return outputs of the same dtype of the non empty array
The function solve_sylvester now raises a value error if the shape of the inputs are not correct
Additional information