On Tue, Nov 18, 2008 at 1:50 PM, Chouser <[EMAIL PROTECTED]> wrote:

>
> On Tue, Nov 18, 2008 at 11:44 AM, everyman <[EMAIL PROTECTED]>
> wrote:
> >
> > The signature for the Java constructor I am trying to use is:
> > ; Matrix(double[][] A)
> >
> > (ns clojure-matrix
> >  (:import (Jama Matrix)))
> >
> > clojure-matrix=> (new Matrix (to-array-2d [[1.0 2.0] [3.0 4.0]])))
> >
> > java.lang.ClassCastException: [[Ljava.lang.Object; cannot be cast to
> > [[D
> This should build what you want:
> user=> (def my-tricky-array (into-array (map #(into-array Double/TYPE
> %) [[1 2][3 4]])))
> #'user/my-tricky-array
>
> Take a look at it, and see that the type signature looks good:
> user=> my-tricky-array
> #<double[][] [EMAIL PROTECTED]>
>

Here's a slight tweak using double-array instead of nested calls to
into-array (double-array isn't mentioned in clojure.org/java_interop page,
but it is in the full API listing):

user=> (into-array (map double-array [[1.0] [2.0]]))
#<double[][] [EMAIL PROTECTED]>

Shawn

--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to