Skip to content

Conversation

@ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Dec 6, 2025

Cherry picked from #811

The casting logic did something nonsensical for complex inputs. Fix is simple as they are supported by numba anyway

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the Numba dot operation's type handling logic to properly support complex number inputs, which were previously mishandled by the casting logic.

Key changes:

  • Updated dtype handling to use numpy_dtype objects instead of dtype strings
  • Added check for float/complex types (out_dtype.kind not in "fc") to only cast non-float/non-complex types
  • Added cache versioning to the return values for proper function caching

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pytensor/link/numba/dispatch/elemwise.py Fixed dtype casting logic to properly handle complex types by checking dtype.kind and only casting integer types to float; added cache version support; improved verbose logging
tests/link/numba/test_elemwise.py Added test cases for complex128 matrix dot products and mixed int64/complex128 operations to ensure the fix works correctly

if x_dtype == dot_dtype and y_dtype == dot_dtype:
numba_dot_dtype = out_dtype = out.type.numpy_dtype
if out_dtype.kind not in "fc":
# Numba alawys returns non-integral outputs, we need to cast to float
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

Typo in comment: "alawys" should be "always".

Suggested change
# Numba alawys returns non-integral outputs, we need to cast to float
# Numba always returns non-integral outputs, we need to cast to float

Copilot uses AI. Check for mistakes.
@ricardoV94 ricardoV94 merged commit 3b722ce into pymc-devs:main Dec 6, 2025
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working numba

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants