On Jan 15, 4:33 am, Rich Hickey <richhic...@gmail.com> wrote:

> Try this (and make sure you are using -server):
>
> (defn diffuse [grid diff-ratio dt]
>   (let [a (float (* dt diff-ratio grid-size grid-size))
>         a4-1 (float (+ 1 (* 4 a)))
>         grid #^floats (deref grid)
>         diffused-grid #^floats (make-grid)
>         grid-size (int grid-size)
>         line-length (int (+ grid-size 2))]
>     (dotimes [n 20]
>       (dotimes [y grid-size]
>         (let [line-offset (* (inc y) line-length)]
>          (loop [x (int 1)
>                 c (int (+ x line-offset))]
>            (aset diffused-grid c
>                        (/ (+ (aget grid c)
>                                     (*  a
>                                         (+ (+ (aget diffused-grid
> (unchecked-dec c))
>                                               (aget diffused-grid
> (unchecked-inc c)))
>                                            (+ (aget diffused-grid
> (unchecked-subtract c line-length))
>                                               (aget diffused-grid
> (unchecked-add c line-length))))))
>                                  a4-1))
>            (when (< x grid-size)
>              (recur (unchecked-inc x)
>                     (unchecked-inc c)))))))
>     diffused-grid))
>
> (time (diffuse foo 0.00025 0.002))
> "Elapsed time: 25.588 msecs"

Your computer is faster than mine.:)
I got to check when I get back home tonight, but I think this might
be fast enough once I use this technique in all the array manipulation
functions. I got about a 4x speedup in my quick tests. Thanks.

--
 -asbjxrn
--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to