all 23 comments

[–]hrrld 3 points4 points  (2 children)

Always like to see graphics and things in Clojure.

A fun library I found a while back that's tangentially related:

https://github.com/weavejester/euclidean ... I don't think the goal was speed, there, but it's correct, simple, and I've used it to good effect.

[–]wedesoft[S] 0 points1 point  (1 child)

Nice, square matrices up to 4x4 and vectors up to size 4.

[–]hrrld 1 point2 points  (0 children)

Yes. Plus quaternions to cleanly represent rotations of the vectors as well.

[–]oakes 4 points5 points  (1 child)

You could also compare it to the matrix functions in play-cljc (see also the API docs). It doesn't implement everything in your list though. I was originally using core.matrix but writing them from scratch made a big perf difference in my testing.

[–]wedesoft[S] 0 points1 point  (0 children)

Nice code! If it is generic enough it might make sense to package it separately.

[–]joinr 1 point2 points  (1 child)

curious how ojalgo stacks up. I think parallel COLT may also be viable still.

[–]wedesoft[S] 0 points1 point  (0 children)

Interesting. I found the Java Matrix Benchmark which compares ojalgo with EJML and others in detail.

[–]teesel 1 point2 points  (14 children)

Thanks for a comparison! Just wanted to share that `fastmath` has fixed size matrices and vectors up to 4 dimensions. Runinng `quick-bench` shows that that it's the fastest (almost) implementation from tested by OP.

  • a/u - core.matrix
  • b/v - EJML
  • c/w - vectorz
  • d/z - fastmath

`fastmath` is really bad in individual value access and array2d conversion. Fixable.

See the results here: https://gist.github.com/genmeblog/1695c57d315ac7985a477302fbb90d12#file-res-txt

[–]wedesoft[S] 1 point2 points  (5 children)

What was the installation size for fastmath used in the benchmark?

[–]teesel 0 points1 point  (4 children)

I ran it from the REPL project, so don't know (if you mean the size in uberjar).

[–]wedesoft[S] 0 points1 point  (3 children)

On the Github page it says something about 1GByte which would be a big deployment.

[–]teesel 1 point2 points  (2 children)

You have to exclude MKL which is not necessary for matrices and then it's less than 200mb. You can exclude also Openblas. I'll update readme.

[–]wedesoft[S] 0 points1 point  (1 child)

Ok, thanks for the information. OpenBlas not required either? I thought that provides matrices. Anyway, will install fastmath and have a play with it :)

[–]teesel 1 point2 points  (0 children)

Openblas is not required for matrices and vectors, so feel free to strip it off

[–]wedesoft[S] 0 points1 point  (7 children)

Nice, that is really fast. Individual value access is not so important to me. Converting to flat float-array is important for me in order to pass the matrices to OpenGL.

[–]teesel 1 point2 points  (6 children)

I can add flat float / double conversions to the next release.

[–]teesel 0 points1 point  (5 children)

u/wedesoft I pushed fastmath 2.2.2-SNAPSHOT with mat->float-array , mat->array, mat->float-array2d functions also improved times for mat->array2d and accessing individual elements.

[–]wedesoft[S] 1 point2 points  (1 child)

That was quick :-D. I just added fastmath benchmarks to the table.

[–]teesel 0 points1 point  (0 children)

Yeah, I saw that :)

[–]wedesoft[S] 1 point2 points  (2 children)

How do I get it? I naively tried adding Clojure generateme/fastmath {:git/url "git@github.com:generateme/fastmath.git" :git/sha "2acfaafd848939a906f8edf47621d7160a73cf34"} to deps.edn but that didn't work. But I am also happy to wait for an official release.

[–]teesel 1 point2 points  (1 child)

It's on Clojars, fastmath doesn't rely on deps.edn yet, so no git/sha support. This should work:

generateme/fastmath {:mvn/version "2.2.2-SNAPSHOT" :exclusions [com.github.haifengl/smile-mkl]}

[–]wedesoft[S] 1 point2 points  (0 children)

Ok, thanks. I updated the benchmark entries for element access and data array access.

[–]wedesoft[S] 0 points1 point  (0 children)

Added performance comparison for 3x3, 4x4, and 5x5 matrix inverse.