Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support assignment of DOK to DOK subarray #400

Open
tbenst opened this issue Aug 22, 2020 · 0 comments
Open

Support assignment of DOK to DOK subarray #400

tbenst opened this issue Aug 22, 2020 · 0 comments
Labels
enhancement Indicates new feature requests

Comments

@tbenst
Copy link

tbenst commented Aug 22, 2020

Is your feature request related to a problem? Please describe.
Allow assignment of DOK subarray without requiring creation of dense array.

Describe the solution you'd like

>>> import sparse
>>> import numpy as np
>>> array = sparse.DOK([3,4,5], dtype=np.int8)
>>> subarray = sparse.DOK([4,5], dtype=np.int8)
>>> subarray[1,1] = 1
>>> array[0] = subarray
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tyler/lib/anaconda3/envs/glia/lib/python3.8/site-packages/sparse/_dok.py", line 317, in __setitem__
    value = np.asanyarray(value)
  File "/home/tyler/lib/anaconda3/envs/glia/lib/python3.8/site-packages/numpy/core/_asarray.py", line 136, in asanyarray
    return array(a, dtype, copy=False, order=order, subok=True)
  File "/home/tyler/lib/anaconda3/envs/glia/lib/python3.8/site-packages/sparse/_sparse_array.py", line 222, in __array__
    raise RuntimeError(
RuntimeError: Cannot convert a sparse array to dense automatically. To manually densify, use the todense method.

Describe alternatives you've considered

>>> array[0] = subarray.todense()
>>>

Additional context
If subarray is huge and very sparse, todense is not feasible.

@tbenst tbenst added the enhancement Indicates new feature requests label Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests
Projects
None yet
Development

No branches or pull requests

1 participant