You might be interested in core.matrix , a project that allows you to use multidimensional arrays and numerical computing capabilities in Clojure. Still in a very active development, but already usable.
Features:
- Pure functional API
- Corresponding multidimensional arrays
- The idiomatic style of working with Clojure data, for example. the embedded vector
[[1 2] [3 4]] can automatically be used as a 2x2 matrix. - All the array conversion features you might expect.
- All common operations with matrices (multiplication, scaling, determinants, etc.)
- Support for multiple matrix matrix implementations, for example. JBLAS for high performance (uses native code)
See sample code here:
;; a matrix can be defined using a nested vector (def a (matrix [[2 0] [0 2]])) ;; core.matrix.operators overloads operators to work on matrices (* aa) ;; a wide range of mathematical functions are defined for matrices (sqrt a) ;; you can get rows and columns of matrices individually (get-row a 0) ;; Java double arrays can be used as vectors (* a (double-array [1 2])) ;; you can modify double arrays in place - they are examples of mutable vectors (let [a (double-array [1 4 9])] (sqrt! a) ;; "!" signifies an in-place operator (seq a)) ;; you can coerce matrices between different formats (coerce [] (double-array [1 2 3])) ;; scalars can be used in many places that you can use a matrix (* [1 2 3] 2) ;; operations on scalars alone behave as you would expect (* 1 2 3 4 5) ;; you can do various functional programming tricks with matrices too (emap inc [[1 2] [3 4]])
core.matrix was approved by Rich Hickey as the official Clojure contrib library, and it is likely that Incanter will switch to using core.matrix in the future.
Support for SQL tables is not directly included in core.matrix, but there will only be a single-line .jdbc in the core.matrix array to convert the result set from clojure.java. Something like the following should do the trick:
(coerce [] (map vals resultset))
You can then convert and process it using core.matrix as you like.
source share