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

Numba solve_triangular returns wrong results when overwrite_b=True #1233

Closed
ricardoV94 opened this issue Feb 23, 2025 · 0 comments · Fixed by #1235
Closed

Numba solve_triangular returns wrong results when overwrite_b=True #1233

ricardoV94 opened this issue Feb 23, 2025 · 0 comments · Fixed by #1235
Labels
bug Something isn't working linalg Linear algebra numba

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Feb 23, 2025

Description

Revealed in #1226

import numpy as np
import pytensor
import pytensor.tensor as pt
from pytensor.tensor.slinalg import SolveTriangular

rng = np.random.default_rng(1)
a_test = rng.normal(size=(2, 2))
a_test[1, 0] = 0
b_test = rng.normal(size=(2, 2))

op = SolveTriangular(trans=0, unit_diagonal=False, lower=False, check_finite=True, b_ndim=2, overwrite_b=True)

a_pt = pt.matrix("a", shape=a_test.shape)
b_pt = pt.matrix("b", shape=b_test.shape)
out = op(a_pt, b_pt)

py_fn = pytensor.function([a_pt, b_pt], out, accept_inplace=True)
numba_fn = pytensor.function([a_pt, b_pt], out, accept_inplace=True, mode="NUMBA")

(
    py_fn(a_test.copy(), b_test.copy()),
    numba_fn(a_test.copy(), b_test.copy()),
)

# (array([[ 1.64016796,  2.35184226],
#         [ 0.41204025, -0.44593092]]),
#  array([[ 3.4341482 , -0.34253317],
#         [-0.49356511, -0.44593092]]))
@ricardoV94 ricardoV94 added bug Something isn't working numba linalg Linear algebra labels Feb 23, 2025
@ricardoV94 ricardoV94 changed the title Numba solve_triangular return wrong results when overwrite_b=True Numba solve_triangular returns wrong results when overwrite_b=True Feb 23, 2025
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 a pull request may close this issue.

1 participant