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

BUG: linalg.solve_{sylvester, continuous_lyapunov}: empty array support #20528

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

redha2404
Copy link

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

@github-actions github-actions bot added scipy.linalg defect A clear bug or issue that prevents SciPy from being installed or used as expected labels Apr 19, 2024
@lucascolley lucascolley changed the title BUG: linalg.solve_sylvester linalg.solve_continuous_lyapunov : empty array support BUG: linalg: solve_{sylvester, continuous_lyapunov}: empty array support Apr 19, 2024
@lucascolley lucascolley changed the title BUG: linalg: solve_{sylvester, continuous_lyapunov}: empty array support BUG: linalg.solve_{sylvester, continuous_lyapunov}: empty array support Apr 19, 2024
@lucascolley lucascolley requested review from ev-br and removed request for ilayn and larsoner April 19, 2024 11:15
scipy/linalg/_solvers.py Outdated Show resolved Hide resolved
@redha2404 redha2404 requested a review from ilayn April 19, 2024 15:35
dt = np.result_type(a, b, q)
if dt == int:
dt = np.float64
return np.empty(q.shape, dtype=dt)
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done 👍

@redha2404 redha2404 requested a review from ilayn April 19, 2024 18:14
@ilayn ilayn mentioned this pull request Apr 20, 2024
92 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.linalg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants