pymc-devs / pymc-devs/pytensor

`pytensor.sparse.dot` returns a dense matrix even when both inputs are sparse

Open
#1,855 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

gradients graph rewriting request discussion sparse variables
Dominant language
Python
Stars
644
Forks
208
Avg merge
2d 14h
Merged PRs (30d)
16

Description

Description

As mentioned in https://github.com/pymc-devs/pytensor/pull/1854, PyTensor's dot product for sparse matrices always returns a dense array, even when both inputs are sparse. This behavior differs from SciPy's, which returns a sparse matrix when both inputs are sparse (using the format of the first input IIRC).

Note this only happens with pytensor.sparse.dot. The other operator, pytensor.sparse.structured_dot, does return a sparse matrix when both inputs are sparse.

I have not looked into pytensor.sparse.true_dot yet, but a skim suggests this one always return a sparse matrix.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the pytensor.sparse.dot entry point and compare its behavior with SciPy when both inputs are sparse. Check the existing behavior of pytensor.sparse.structured_dot and pytensor.sparse.true_dot for guidance, then verify that sparse inputs produce a sparse result while existing dense behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.