Clojure Matrix Representation

2019-02-03 18:03发布

What is a good representation for matrices in Clojure? I'm interested in dealing with dense matrices of floating point numbers. The "list of lists" representation springs to mind, but is there something better?

Some criteria for a good representation include:

  • Efficiency: They won't be used for constant processing of huge data sets, but I don't want to spend hours calculating results that could have been done in minutes with a better design.
  • Java Interoperability: It would be nice to pass the data back and forth between the two languages easily.
  • Easy Parallelization: If I can use all the cores available simply by replacing map with pmap, that would be nice.
  • Amenable to the use of reduce: It seems like lots of the calculations I'm doing work very well with reduce.
  • Ability to Represent Image Scan Lines in Matrix Rows: Not really very important, but would be nice to have.

Any thoughts?

8条回答
相关推荐>>
2楼-- · 2019-02-03 18:14

the answers may need to be updated as 8 years passed. A quick google search shows that if you need to be compatible with Clojure core.matrix API, you can use core.matrix itself or other implementations such as vectorz-clj.

In addition I found Neanderthal which is optimized for GPU

查看更多
欢心
3楼-- · 2019-02-03 18:21

I'm writing a matrix library wrapping jblas called, tentatively, Clatrix. It's missing a lot of features I still want to add, but it's got most of what you might be looking for. Take a look, http://github.com/tel/clatrix.

查看更多
干净又极端
4楼-- · 2019-02-03 18:21

I am presently using the list of lists approach in cryptovide because its very important for this application to keep things lazy. I am also considering switching to a more efficient approach as long as it kept at least the outward representation lazy.

查看更多
够拽才男人
5楼-- · 2019-02-03 18:22

Incanter supplies a wrapper around some of Parallel Colt, including what looks to be a pretty decent implementation of fast, parallelized dense matrices that interface with Clojure's seq-based libraries. I haven't used it, but it should be what you're looking for.

Example.

查看更多
狗以群分
6楼-- · 2019-02-03 18:23

Check out the core.matrix proposal + experimental implementation here:

https://github.com/mikera/matrix-api

Very early days at time of writing, but worth keeping an eye on.

查看更多
神经病院院长
7楼-- · 2019-02-03 18:29

Rich Hickey’s Clojure is a JVM-based Lisp that represents PersistentVector (not a PersistentList) with a 32-way tree.

If you would like to write your own matrix Type i would use PersistentVector otherwise the best choice is to use Parallel Colt with Incanter.

查看更多
登录 后发表回答