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

Respect fill_value argument in COO constructor #179

Closed
abhinav-upadhyay opened this Issue Sep 6, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@abhinav-upadhyay

abhinav-upadhyay commented Sep 6, 2018

It's not clear from the documentation what's the use of the fill_value argument in the COO constructor. But I guess I can use it to tell sparse that I am using some value other than 0 for the majority of data. But it seems if I pass it when creating a COO array, it doesn't have any effect.

For example in the below code I am using np.nan instead of 0 as the fill value but sparse.COO creates an array with nnz=100 and fill_value=0.0, which isn't really sparse.

In [1]: import numpy as np

In [2]: import sparse

In [3]: arr1 = np.random.random(100)

In [4]: arr1[arr1 < 0.9] = np.nan

In [5]: c1 = sparse.COO(arr1, fill_value=np.nan)

In [6]: c1
Out[6]: <COO: shape=(100,), dtype=float64, nnz=100, fill_value=0.0>
@hameerabbasi

This comment has been minimized.

Collaborator

hameerabbasi commented Sep 6, 2018

Currently, "migrating a fill-value" is only allowed between DOK and COO. I guess I could add the functionality when migrating from NumPy arrays.

@abhinav-upadhyay

This comment has been minimized.

abhinav-upadhyay commented Sep 6, 2018

It would be nice but I just realized I could create the coords and data arrays myself and then call sparse.COO with np.nan as fill_value, that works.

@hameerabbasi

This comment has been minimized.

Collaborator

hameerabbasi commented Sep 6, 2018

This feature is now available in master. Closed via #180

@abhinav-upadhyay

This comment has been minimized.

abhinav-upadhyay commented Sep 6, 2018

Much appreciated, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment