pymc-devs / pymc-devs/pytensor
Sparse TensorVariables are not using the Sparse Elemwise methods
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 644
- Forks
- 208
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 16
Description
Description
I think during the merging of SparseVariable and TensorVariables Type classes still in Aesara https://github.com/aesara-devs/aesara/pull/766, there was a mistake where the Structured methods were not borrowed, instead we always convert to dense with a warning
import numpy as np
import pytensor.tensor as pt
import pytensor.sparse as ps
X_sp = ps.csc_from_dense(pt.arange(5))
X_sp.sin() # Method sin is not implemented for sparse variables. The variable will be converted to dense.
Either way, we have a sparse Sin implemented, so we should use them:
out = ps.sin(X_sp)
out.eval() # <1x5 sparse matrix of type '<class 'numpy.float64'>'
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
Reproduce the sparse TensorVariable example from the issue, then inspect pytensor/sparse/basic.py at lines 3028-3051 and the Structured methods mentioned in the report. Compare X_sp.sin() with ps.sin(X_sp); done means the method uses the sparse implementation, returns a sparse result, and no longer warns about dense conversion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100