-
Notifications
You must be signed in to change notification settings - Fork 7
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
SparseVector #3
Comments
I managed to make setting with iterable slices twice as fast when the indices are already in the sparse vector (which is my real-world use-case):
But it's still slower when the indices are not yet present in the vector. |
Optimized some more by leveraging numpy's internals for things like densification :
I also found out the hard way that |
I went ahead and published |
Hi @Goutte! Sorry I missed this for so long. Great work on creating |
Your yummy test-suite has spurred me to try my hand at making a quick'n dirty implementation of a sparse list using not a dictionary of keys, but linked lists : two
numpy.ndarrays
internally, one of integers for the keys, and one for the values, whosedtype
is left to the choice of the user.If this works, I'll probably make a sparse_vector lib, unless you think this lib should hold multiple implementations. (my inner sloth hopes that you do)
I called it vector because it's specialized for numerical values.
The idea is to make the init with initial values and the setting via list slicing (see PR #2) both faster.
I tried
scipy.sparse
andpandas.Series
but they don't fit my immediate needs.My constraints are :
1. Python only
2. Performance
3. Available now :)
I just want a simple sparse 1D numerical vector that works well with numpy.
I guess
scipy.sparse
should make separate classes for 1D, 2D, 3D, and ND.They only support 2D right now (and therefore 1D), with classes such as
scipy.sparse.lil_matrix
, which is also a linked list implementation.But the API does not feel right for vectors, look at the instantiation :
Besides having to
np.zeros(len(indices))
to fulfill the 2D signature, there's no settable default value,which is zero. (and I need another)
And there's a bunch of 2D-only "features" such as :
I have not tried
sympy.matrices.sparse.SparseMatrix
yet.Anyhow, I'm running benchmarks with sparse_vector :
which right now yields :
Not optimal yet, but it's still quick'n dirty, I can clean that up some and maybe start comparing with
lil_matrix
too.The text was updated successfully, but these errors were encountered: