Skip to content

BUG: numpy.array_api: fix linalg.cholesky upper decomp for complex dtypes#24777

Merged
rgommers merged 1 commit intonumpy:mainfrom
lucascolley:array-api-cholesky-fix
Jan 3, 2024
Merged

BUG: numpy.array_api: fix linalg.cholesky upper decomp for complex dtypes#24777
rgommers merged 1 commit intonumpy:mainfrom
lucascolley:array-api-cholesky-fix

Conversation

@lucascolley
Copy link
Copy Markdown
Contributor

@lucascolley lucascolley commented Sep 22, 2023

Closes gh-24451

cc @asmeurer

[skip travis] [skip azp] [skip circle] [skip cirrus]
Copy link
Copy Markdown
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

Thanks @lucascolley, this LGTM. The upstream definition fix got merged, and this seems clearly correct. It's easy to test now too, since np.linalg.cholesky recently gained an upper keyword (we don't want to change this PR though, because it'd be good for this code to work with numpy 1.25/1.26):

>>> A = np.array([[1,-2j], [2j,5]])
>>> np.linalg.cholesky(A)
array([[1.+0.j, 0.+0.j],
       [0.+2.j, 1.+0.j]])
>>> np.array_api.linalg.cholesky(np.array_api.asarray(A))
Array([[1.+0.j, 0.+0.j],
       [0.+2.j, 1.+0.j]], dtype=complex128)
>>> np.linalg.cholesky(A, upper=True)
array([[ 1.+0.j, -0.-2.j],
       [ 0.+0.j,  1.+0.j]])
>>> np.array_api.linalg.cholesky(np.array_api.asarray(A), upper=True)
Array([[1.-0.j, 0.-2.j],
       [0.-0.j, 1.-0.j]], dtype=complex128)

So that matches, while in main the sign of the off-diagonal element is reversed.

@rgommers rgommers merged commit 98c39ae into numpy:main Jan 3, 2024
@rgommers rgommers added this to the 2.0.0 release milestone Jan 3, 2024
@rgommers rgommers added the 09 - Backport-Candidate PRs tagged should be backported label Jan 3, 2024
@rgommers
Copy link
Copy Markdown
Member

rgommers commented Jan 3, 2024

Adding the backport candidate, because it'd be nice if it were correct in 1.26.x if we do another bugfix release there.

@lucascolley lucascolley deleted the array-api-cholesky-fix branch January 3, 2024 19:42
@charris charris changed the title BUG: numpy.array_api: fix linalg.cholesky upper decomp for complex dtypes BUG: numpy.array_api: fix linalg.cholesky upper decomp for complex dtypes Jan 4, 2024
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: array_api: linalg.cholesky returns the conjugate of the expected upper decomposition

3 participants