Skip to content

Add empty input guards to numba linalg#2057

Merged
jessegrabowski merged 6 commits intov3from
numba-empty-schur
Apr 19, 2026
Merged

Add empty input guards to numba linalg#2057
jessegrabowski merged 6 commits intov3from
numba-empty-schur

Conversation

@jessegrabowski
Copy link
Copy Markdown
Member

@jessegrabowski jessegrabowski commented Apr 18, 2026

I was hitting this error in #2032; tests/tensor/linalg/test_decomposition/test_schur.py::test_schur_empty was failing because we didn't have any guard in place for an early return on empy inputs. I am a bit at a loss why the CI isnt' currently failing on v3. It might be a mac vs linux lapack thing?

Anyway I fixed it, and also did an audit of the other linalg functions against empty inputs and found several decompositions that didn't have an appropriate guard, so I added those as well.

Related to: #1298

@jessegrabowski jessegrabowski added bug Something isn't working numba linalg Linear algebra labels Apr 18, 2026
@jessegrabowski
Copy link
Copy Markdown
Member Author

general comment: we could either guard in the overload or in the dispatch. I chose the dispatch to keep the overload as light as possible. We could even optimize further to replace these Ops with a DeepCopy if we know at compile time that the input will be empty. But that seems like an extraordinary corner case.

Copy link
Copy Markdown
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

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

Re empty inputs there's an open issue for this, it goes beyond linalg Ops.

You don't need deepcopy just zeros(output_shape).

@ricardoV94
Copy link
Copy Markdown
Member

It's #1298

Comment thread pytensor/link/numba/dispatch/linalg/decomposition/dispatch.py
if x.size == 0:
m, n = x.shape
k = min(m, n)
# The LAPACK dispatch returns matrices in fortran order. To match this for the empty cases,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why does it matter the order? Because numba doesn't want one branch returning F and another returning C?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes exactly

@ricardoV94
Copy link
Copy Markdown
Member

squash, rebase, or cleanup first?

@jessegrabowski jessegrabowski merged commit 2d37751 into v3 Apr 19, 2026
66 checks passed
@jessegrabowski
Copy link
Copy Markdown
Member Author

SQUASH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working linalg Linear algebra numba

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants