There are a number of matrix libraries out there for clojure:
What are the performance trade-offs between these libraries? I've heard that with some of the underlying implementations, there are trade-offs between (for-example) matrix instantiation and operation performance, but I haven't been able to find a comprehensive resource detailing these considerations.
Thanks
If you want to make use of core.matrix
, there are only two implementations at present that are reasonably mature and performant:
Clatrix
- uses calls to native BLAS
vectorz-clj
- a flexible and fast pure-JVM implementationIt really comes down to your use cases. If you mostly care about big linear algebra operations and don't mind the native dependencies, then Clatrix
is your best bet at present - simply because BLAS implementations are so fast. This is particularly useful for:
If you want to do general array-programming work, then vectorz-clj
has the advantage of being pure JVM code and much more flexible in terms of array/matrix formats. Examples of things that vectorz-clj supports well that you can't do in Clatrix:
Overall, vectorz-clj
won't be as fast for things like big matrix multiplication, but is probably faster than Clatrix
for many other operations and small/medium sized vector work. I'd normally choose vectorz-clj
unless I thought that linear algebra performance would be the main bottleneck.
The other core.matrix
implementations are less mature, but may still be useful for specific use cases. A nice feature of core.matrix
is the ability to mix and match implementations while using the same common API, so it's not an "all or nothing" choice.
Disclaimer: I have created or contributed to many of the above projects. I hope I've given a fairly unbiased and objective evaluation.
If you don't need core.matrix
support, then you have many more options - you can use any of the Java matrix libraries via Clojure's Java interop. In theory, these could become core.matrix
implementations as well - the only constraint is that someone needs to do the work to extend the core.matrix protocols to support the new matrix types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With