On 23 Oct 2009, at 22:00, Konrad Hinsen wrote:

> For matrix computations and linear algebra, your best choice is  
> probably
>  the Colt library developed at CERN, or the somewhat parallelized
> version called Parallel Colt. Colt has arrays up to three dimensions  
> for
> a couple of data types, enough for matrix stuff but not much more.
>
> If you need higher-dimensional arrays, e.g. to store complex data  
> sets,
> your best bet would be the netCDF implementation for Java, which
> contains a very complete array library that handles any number of
> dimensions. However, it provides no linear algebra at all.

I should have added that it is possible to convert between netCDF and  
Colt arrays without a costly element-by-element copying procedure. For  
example, the following code inverts a matrix read from a netCDF file  
using Colt:

(ns netcdf-read
  (:import (ucar.nc2 NetcdfFile)
           (cern.colt.matrix.tdouble.impl DenseDoubleMatrix2D)
           (cern.colt.matrix.tdouble.algo DenseDoubleAlgebra)))

(defn unidata-to-colt
  [#^ucar.ma2.ArrayDouble$D2 array]
  (let [java-array-1d (.get1DJavaArray array Double)
        [rows, cols]  (.getShape array)]
    (new DenseDoubleMatrix2D rows cols java-array-1d 0 0 cols 1 false)))

(let [matrix      (with-open [ncfile (NetcdfFile/open "/Users/hinsen/ 
Temp/matrix.nc")]
                    (.read (.findVariable ncfile "matrix")))
      colt-matrix (unidata-to-colt matrix)
      la          (new DenseDoubleAlgebra)
      inverse     (.inverse la colt-matrix)]
  (prn inverse))

Konrad.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to