Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Implement MaskedTensorVariables and operations #259

Open
ricardoV94 opened this issue Mar 29, 2023 · 0 comments
Open

Implement MaskedTensorVariables and operations #259

ricardoV94 opened this issue Mar 29, 2023 · 0 comments
Labels

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Mar 29, 2023

PyTensor doesn't have a type that behaves like masked arrays. It's not just a problem of wrapping a masked array.

In your example, as soon as you try to do some operation, you will get incorrect values:

import pytensor
import numpy as np

X = np.ma.masked_greater(np.array([1, 2, 3, 4]), 3)
sh_val = pytensor.shared(X)
print(sh_val.eval()) # [1,2,3,4]
sh_val.set_value(X)
print(sh_val.eval()) # [1,2,3,--]
print((sh_val + 1).eval())  # [2 3 4 5]

We can raise explicitly when a user tries to pass a masked array. To actually support numpy-like behavior, we would need to implement something like MaskedTensorVariables and write all the operations to support those types. Similar to how we handle SparseTensorVariables.

Originally posted by @ricardoV94 in #258 (comment)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant