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

Add possibility for sparse default value different than zero #88

Open
icarocd opened this issue Jul 3, 2016 · 1 comment
Open

Add possibility for sparse default value different than zero #88

icarocd opened this issue Jul 3, 2016 · 1 comment

Comments

@icarocd
Copy link

icarocd commented Jul 3, 2016

In SparseRowMatrix and SparseColumnMatrix, zero is assumed as the sparse value.
However, there are many applications were the default value if 1 instead, as in some symmetric distance matrices for example.
Although it is possible to handle this limitation by inverting the logic of the application to treat the way the data structure is used, the possibility I am suggesting is simple to implement and very useful.

@mikera
Copy link
Owner

mikera commented Jul 5, 2016

Good idea, I also thought about this before.

Ultimately I decided that the performance tradeoff / extra complexity wasn't worth it in the main sparse classes (SparseRowMatrix and SparseColumnMatrix). Assuming zero as the sparse value keeps things simple and enables many optimisations.

However it could make sense as a separate class / pair of classes, so leaving this open as an enhancement idea. Could also be implemented using a new kind of sparse vector that support non-zero default values

Another interesting idea would be a "SparseMaskMatrix" that allows you to mask any elements of an array and let other elements fall through to a "background" matrix. Would allow lightweight "edit layers" over large immutable arrays, for example.

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

No branches or pull requests

2 participants