I don't see what you're seeing for the type-hinted version: user=> (defn asum-sq [ ^floats xs ] user=* (let [ ^floats dbl (amap xs i ret user=* (* (aget xs i) user=* (aget xs i)))] user=* (areduce dbl i ret 0 user=* (+ ret (aget dbl i))))) NO_SOURCE_FILE:12 recur arg for primitive local: ret is not matching primitive, had: double, needed: long Auto-boxing loop arg: ret #'user/asum-sq
Perhaps you need to update your 1.3 install. On Oct 3, 11:16 pm, Sean Corfield <seancorfi...@gmail.com> wrote: > Further digging seems to indicate aset etc work for int-array types - > but not float-array types? > > (let [^ints xii (int-array [1 2 3 4 5])] (amap xii i ret (* (aget xii > i) (aget xii i)))) > > (without the hint, it also works but emits various reflection warnings) > > > > On Sun, Oct 3, 2010 at 9:41 PM, Sean Corfield <seancorfi...@gmail.com> wrote: > > I'm trying out various examples in The Joy Of Clojure and I'm in > > Chapter 12 Performance looking at type hinting. > > > The authors give this example: > > > (set! *warn-on-reflection* true) > > ; true > > (defn asum-sq [xs] > > (let [dbl (amap xs i ret > > (* (aget xs i) > > (aget xs i)))] > > (areduce dbl i ret 0 > > (+ ret (aget dbl i))))) > > > ; Reflection warning, NO_SOURCE_PATH:2 - call to aclone can't be resolved. > > > Plus lots of others: > > > Reflection warning, NO_SOURCE_PATH:2 - call to alength can't be resolved. > > Reflection warning, NO_SOURCE_PATH:2 - call to aget can't be resolved. > > Reflection warning, NO_SOURCE_PATH:2 - call to aget can't be resolved. > > Reflection warning, NO_SOURCE_PATH:2 - call to aset can't be resolved. > > Reflection warning, NO_SOURCE_PATH:2 - call to alength can't be resolved. > > Reflection warning, NO_SOURCE_PATH:2 - call to aget can't be resolved. > > NO_SOURCE_FILE:2 recur arg for primitive local: ret is not matching > > primitive, had: Object, needed: long > > Auto-boxing loop arg: ret > > Reflection warning, NO_SOURCE_PATH:2 - call to alength can't be resolved. > > Reflection warning, NO_SOURCE_PATH:2 - call to aget can't be resolved. > > #'user/asum-sq > > > They claim if you use ^floats as a type hint, this will solve the > > problem, but here's what I get (on Clojure 1.3): > > > (defn asum-sq [ ^floats xs ] > > (let [ ^floats dbl (amap xs i ret > > (* (aget xs i) > > (aget xs i)))] > > (areduce dbl i ret 0 > > (+ ret (aget dbl i))))) > > Reflection warning, NO_SOURCE_PATH:3 - call to aclone can't be resolved. > > Reflection warning, NO_SOURCE_PATH:3 - call to alength can't be resolved. > > Reflection warning, NO_SOURCE_PATH:3 - call to aget can't be resolved. > > Reflection warning, NO_SOURCE_PATH:3 - call to aget can't be resolved. > > Reflection warning, NO_SOURCE_PATH:3 - call to aset can't be resolved. > > Reflection warning, NO_SOURCE_PATH:3 - call to alength can't be resolved. > > Reflection warning, NO_SOURCE_PATH:3 - call to aget can't be resolved. > > NO_SOURCE_FILE:3 recur arg for primitive local: ret is not matching > > primitive, had: Object, needed: long > > Auto-boxing loop arg: ret > > Reflection warning, NO_SOURCE_PATH:3 - call to alength can't be resolved. > > Reflection warning, NO_SOURCE_PATH:3 - call to aget can't be resolved. > > #'user/asum-sq > > > In other words, the same set of reflection warnings. > > > Trying either version of asum-sq blows up tho'... > > > (time (dotimes [_ 10000] (asum-sq (float-array [1 2 3 4 5])))) > > ; IllegalArgumentException No matching method found: aset > > clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:77) > > > Shouldn't it at least run, albeit slowly? > > > Simplifying the example somewhat: > > > (def xs (float-array [1 2 3 4 5])) > > ; #'user/xs > > (amap xs i ret (* (aget xs i) (aget xs i))) > > ; Reflection warning, NO_SOURCE_PATH:12 - call to aclone can't be resolved. > > ; Reflection warning, NO_SOURCE_PATH:12 - call to alength can't be resolved. > > ; Reflection warning, NO_SOURCE_PATH:12 - call to aget can't be resolved. > > ; Reflection warning, NO_SOURCE_PATH:12 - call to aget can't be resolved. > > ; Reflection warning, NO_SOURCE_PATH:12 - call to aset can't be resolved. > > ; IllegalArgumentException No matching method found: aset > > clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:77) -- 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