pymc-devs / pymc-devs/pytensor
Implement MaskedTensorVariables and operations
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 644
- Forks
- 208
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 16
Description
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
MaskedTensorVariablesand write all the operations to support those types. Similar to how we handleSparseTensorVariables.
Originally posted by @ricardoV94 in https://github.com/pymc-devs/pytensor/issues/258#issuecomment-1488040890
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the pytensor.shared example and compare the proposed MaskedTensorVariables design with the existing SparseTensorVariables approach. Trace how the masked array behaves through an operation such as addition. Done means masked values are preserved correctly across supported operations, rather than producing unmasked numeric results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100