I should add, "oops, ignore what I wrote". :)

see:

https://groups.google.com/group/clojure/tree/browse_frm/thread/33366bccc6df7756/415072576d83b757?rnum=11&_done=%2Fgroup%2Fclojure%2Fbrowse_frm%2Fthread%2F33366bccc6df7756%3F#doc_0d0a3759a0a10328

Carson

On Jul 17, 3:58 pm, Carson <c.sci.b...@gmail.com> wrote:
> Hi, Try this:
>
> (defn stationary-convolve [n fs gs]
>   (let [window-size (count fs)
>         padding (repeat window-size 0)
>         padded-gs (concat padding gs padding)
>         new-center (+ n window-size)
>         window-of-gs (subvec (vec padded-gs)
>                              (- (inc new-center) window-size)
>                              (inc new-center))
>         reverse-window-fn (fn [i] (nth window-of-gs
>                                                    (mod  (- -1 i) 
> window-size)))
>         reverse-window (map reverse-window-fn (range 0 window-size))]
>     (reduce + (map * fs reverse-window))))
>
> (defn convolve [fs gs]
>   (map #(stationary-convolve % fs gs)
>        (range 0 (+ (count fs) (count gs)))))
>
> (let [xs (for [i (range 1000000)] (rand 100))
>       ys (for [i (range 1000000)] (rand 100))]
>   (time (dotimes [_ 3] (convolve xs ys))))
>
> "Elapsed time: 2540.967482 msecs"
>
> Seems to run pretty fast and seems to be the kind of convolution you
> want.
>
> Thanks for the interesting problem!
>
> Carson
>
> On Jul 16, 12:57 pm, Isaac Hodes <iho...@mac.com> wrote:
>
> > I posted this on StackOverflow yesterday, but to no avail: I don't
> > think many people looked at it, or least I didn't get much feedback.
>
> > I am trying to create a lazy/functional/efficient/Clojuresque function
> > to carry out convolution on two lists/vectors of (ideally BigDecimals
> > but that may be inefficient) doubles.
>
> > It is turning out to be very difficult. I have four or five versions
> > in my buffer right now, and none of them are acceptable. I've even
> > tried a number of versions using into-array etc, e.g. mutables.
>
> > Instead of posting a lot of links to pastie, I'm just copying the SO
> > link here, where my code and the algorithms can be found.
>
> > Right now, it seems as though this is something Clojure cannot do.
> > David Nolen mentioned that the appropriate Java-interop functionality
> > may come in Clojure 1.3, but aside from eschewing the functional style
> > by using arrays, it seems as though there should be a better answer.
> > (As an aside, where can I find out about 1.3?)
>
> > I have a Python implementation to show how nicely it can be expressed
> > in an imperitive language (though I suppose I dabbled in the
> > functional style initializing my return array).
>
> > Is it possible to do this, and do it well?
>
> > Thank you so much, in advance.

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