Open
Description
Description
from scipy.sparse import random
import pytensor.sparse as ps
x = ps.csc_dmatrix()
x_test = random(5, 5, density=0.5, random_state=1)
y = ps.structured_exp(x)
np.testing.assert_allclose(
y.eval({x: x_test}).todense(),
np.exp(x_test.todense()),
)
Mismatched elements: 13 / 25 (52%)
Max absolute difference: 1.
Max relative difference: 1.
# x: matrix([[0. , 0. , 2.55775 , 0. , 1.678923],
# [0. , 2.375054, 0. , 0. , 1.538332],
# [1.097243, 0. , 0. , 2.494185, 0. ],...
# y: matrix([[1. , 1. , 2.55775 , 1. , 1.678923],
# [1. , 2.375054, 1. , 1. , 1.538332],
# [1.097243, 1. , 1. , 2.494185, 1. ],...
Since exp(0) != 0, the output is no longer sparse (where missing values are by definition zero). So the wrapper logic where we apply the elemwise operation to the non-sparse entries does not make sense.
Same for log
and potentially other Ops