uncomplicate / neanderthal

Fast Clojure Matrix Library
http://neanderthal.uncomplicate.org
Eclipse Public License 1.0
1.07k stars 56 forks source link

Support for arbitrary subvector views? #23

Closed rbuchmann closed 7 years ago

rbuchmann commented 7 years ago

Hi, I am using neanderthal to do a particular kind of FEM calculations, for which it would be desirable to have vectors of element nodes that are only references to the data of all nodes, so that v(i) = N(some_arbitrary_f(i)), where N has considerably more elements than v. I saw that neanderthal already supports subvectors for consecutive indices. Is there an easy way to add more general views in the way described above, maybe by implementing the listed protocols?

blueberry commented 7 years ago

I am not sure what exactly do you need. It seems to me that you want a vector that contains some arbitrary subset of another vector, but that subset is: 1) sparse 2) not very regular (some_arbitrary_f(i)) could be anything

This is possible to do and not difficult at all - you'd have to implement your own vector type, which reuses data from the buffer of the original vector, and implement the existing protocols and interfaces.

However, such vector will not be very useful in linear algebra operations. How would you multiply a matrix with such vector? Or a dot product? You'd have to implement those operations, and, since their "sparseness" is arbitrary, the performance would be rather bad (compared to the rest of neanderthal).

rbuchmann commented 7 years ago

Yes, your summary is accurate. I think I need to accept that the performance isn't going to be as good as the rest of neanderthal, the question is if this would be faster than copying everything out into a new dense vector, doing the operations on that copy and then writing it back to the respective indices. Judging from your answer, that might be the way to go though. I'd rather not implement my own operations.

blueberry commented 7 years ago

That depends on the complexity of the operations. For anything more complex that O(n), copying will probably be faster. I'd also see if I can keep that copy for a while and use it on several operations. Anyway, the best thing is to measure a few test cases and see how it goes.

rbuchmann commented 7 years ago

Will do that, thanks for the quick replies.

rbuchmann commented 7 years ago

(And the awesome library ;) )

blueberry commented 7 years ago

You're welcome. Please share how you use it, and what are the challenges you have, and I can even be able to make it much better!

Don't hesitate to spread the word :)