Skip to content

Conversation

@ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Jan 6, 2026

Fix failure in BlockDiag


Numba is so limited for meta-programming, that we often have only two options:

  • String codegen
  • Use llvmline building blocks (too low level)

This PR adds a super simple helper for string codegen, so we can build statements programatically, and it handles the indentation. It's super cumbersome otherwise, and since string codegen isn't going anywhere I think it's worth it. I tried to keep it really barebones.

@ricardoV94 ricardoV94 added bug Something isn't working help wanted Extra attention is needed numba linalg Linear algebra labels Jan 6, 2026
Removes depracated `create_tuple_creator`
@ricardoV94 ricardoV94 force-pushed the block_diag_bug branch 3 times, most recently from 37fae8f to fb308ca Compare January 7, 2026 13:51
@ricardoV94 ricardoV94 marked this pull request as ready for review January 7, 2026 14:39
@ricardoV94 ricardoV94 changed the title Fix BlockDiag bug in numba backend Fix BlockDiag failure to compile in numba backend Jan 7, 2026
Copy link
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

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

Approved with a small request for change.

out[r : r + rr, c : c + cc] = arr
r += rr
c += cc
rr, cc = arr0.shape
Copy link
Member

Choose a reason for hiding this comment

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

Do we miss out on any LLVM optimizations by eagerly in-lining the loop? They're supposed to be good at loops.

Copy link
Member Author

@ricardoV94 ricardoV94 Jan 7, 2026

Choose a reason for hiding this comment

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

You cannot loop through mixed read-only/regular arrays, as you can't put them in a container that numba will be happy about? Also I think numba is good at iterating over arrays, not containers of them.

Copy link
Member

Choose a reason for hiding this comment

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

I thought it was supposed to be good at loops in general

Copy link
Member Author

Choose a reason for hiding this comment

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

All claims I see (and what I expect from what they're doing) is about loops on arrays

@register_funcify_default_op_cache_key(BlockDiagonal)
def numba_funcify_BlockDiagonal(op, node, **kwargs):
dtype = node.outputs[0].dtype
"""Codegen something like:
Copy link
Member

Choose a reason for hiding this comment

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

Add a note why codegen is required here (the readonly problem)

Copy link
Member Author

@ricardoV94 ricardoV94 Jan 7, 2026

Choose a reason for hiding this comment

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

The note is time-context sensitive. You could argue a note is then needed in all the Ops that require codegen. The common theme is anything with variadic arguments basically needs it: Alloc, Scan, OFG, Elemwise (that uses low level) ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Added anyway

Copy link
Member

Choose a reason for hiding this comment

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

Yeah then we should do that in each one of those ops. Or write some docs, heaven forbid.

Copy link
Member Author

Choose a reason for hiding this comment

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

docs get stale, code is docs, long live LLM-auto-real-time-doc

Copy link
Member

Choose a reason for hiding this comment

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

us: "why doesn't anyone want to help develop pytensor"
also us: "lol docs? figure it out idiot"

return f"({', '.join(x)})"


class CODE_TOKEN(Enum):
Copy link
Member

Choose a reason for hiding this comment

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

oo a wild Enum. Make me feel all warm and Java-y

@ricardoV94 ricardoV94 merged commit ee47dcc into pymc-devs:main Jan 7, 2026
11 of 12 checks passed
@ricardoV94 ricardoV94 deleted the block_diag_bug branch January 7, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working help wanted Extra attention is needed linalg Linear algebra numba

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants