pydata / pydata/sparse

Dot product between ones and COO tensor

Open
#265 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
668
Forks
141
Avg merge
2d 8h
Merged PRs (30d)
4

Description

Currently, sparse.ones returns a sparse tensor with a fill value of 1 which seems incompatible with the default value (0), at least when taking a dot product.

Minimal code to reproduce the issue:

import sparse
t1 = sparse.ones(5)
t2 = sparse.COO([1, 2], [1, 1], shape=(5, ))
sparse.dot(t1, t2)

Output:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-d149cc87b95e> in <module>
      2 t1 = sparse.ones(5)
      3 t2 = sparse.COO([1, 2], [1, 1], shape=(5, ))
----> 4 sparse.dot(t1, t2)

~/anaconda3/lib/python3.7/site-packages/sparse/coo/common.py in dot(a, b)
    256     COO.dot : Equivalent function for COO objects.
    257     """
--> 258     check_zero_fill_value(a, b)
    259     if not hasattr(a, 'ndim') or not hasattr(b, 'ndim'):
    260         raise TypeError(

~/anaconda3/lib/python3.7/site-packages/sparse/utils.py in check_zero_fill_value(*args)
    291                 not equivalent(arg.fill_value, _zero_of_dtype(arg.dtype))):
    292             raise ValueError('This operation requires zero fill values, '
--> 293                              'but argument {:d} had a fill value of {!s}.'.format(i, arg.fill_value))
    294 
    295 

ValueError: This operation requires zero fill values, but argument 0 had a fill value of 1.0.

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 with sparse/coo/common.py, especially dot, and sparse/utils.py where check_zero_fill_value raises the error. Run the reproducer and inspect existing dot and fill-value tests. Done means the reported ones-and-COO case has defined behavior and a regression test covering it.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.