A first good start is to put
(set! *warn-on-relection* true) at the start of the file and removes
all reflective access.

Before the 1.3 release, function cannot receive/returns primitive so
you might consider
(defmacro next-gaussian []
  `(.nextGaussian  ^Random r))

(^Random is here to make sure r is seen with the right type)

in both function, add ^doubles before arr at the binding point.
(defn ... [^doubles arr....])

then set will not be rflective and be as fast as a set in java.

Ask other questions of you need more help.
The best reference on all that: clojure.org/java_interop


On Sun, Sep 19, 2010 at 3:29 PM, Ranjit <rjcha...@gmail.com> wrote:
> Hi,
>
> I'm trying learn Clojure to see if I can use it in my simulations, and
> one thing I need to do is generate arrays of normally distributed
> numbers.
>
> I've been able to come up with the following two ways of doing this.
> gaussian-matrix2 is a lot faster than gaussian-matrix1, but I'm not
> sure why. And it's still slower than it should be I think. Is there
> anything I can do to speed this up still further?
>
> Thanks,
>
> -Ranjit
>
> (import java.util.Random)
> (def r (Random. ))
>
> (defn next-gaussian [] (.nextGaussian r))
>
> (defn gaussian-matrix1 [arr L]
>     (doseq [x (range L) y (range L)] (aset arr x y (next-gaussian))))
>
> (defn gaussian-matrix2 [L]
>     (into-array (map double-array (partition L (repeatedly (* L L)
> next-gaussian)))))
>
> --
> 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



-- 
Sent from an IBM Model M, 15 August 1989.

-- 
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