aset and shorts, aset vs aset-int

2011-05-29 Thread bOR_
Is there something obvious I am missing when aset in clojure 1.3-alpha8 
won't work for shorts. aset-shorts does work, but way slower than I'd 
expect. There is also an order of magnitude difference in speed between aset 
^ints and aset-int.

I've looked at the source of amap (which was the first thing to give me 
problems with shorts), and from there came to writing the expanded amap 
macro out, and using aset-shorts rather than aset to get shorts working. I'm 
however stuck at looking at the source of aset and understanding how I can 
make that work with shorts.

Related (now that I have the floor anyway), should I still be messing with 
java arrays in clojure 1.3, or would a vector of primitives be as fast?

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

Re: aset and shorts, aset vs aset-int

2011-05-29 Thread David Nolen
On Sun, May 29, 2011 at 9:17 AM, bOR_  wrote:

> Is there something obvious I am missing when aset in clojure 1.3-alpha8
> won't work for shorts. aset-shorts does work, but way slower than I'd
> expect. There is also an order of magnitude difference in speed between aset
> ^ints and aset-int.
>
> I've looked at the source of amap (which was the first thing to give me
> problems with shorts), and from there came to writing the expanded amap
> macro out, and using aset-shorts rather than aset to get shorts working. I'm
> however stuck at looking at the source of aset and understanding how I can
> make that work with shorts.
>
> Related (now that I have the floor anyway), should I still be messing with
> java arrays in clojure 1.3, or would a vector of primitives be as fast?
>

aset- usage is not correct. Always use aset.

(let [^shorts as (make-array Short/TYPE 10)]
  (aset as 0 (short 1)))

Works fine.

Proper use of Java arrays is idiomatic for the forseeable future as far as I
can tell. Vectors of primitives are more efficient, but there's work to be
done for them to approach Java arrays in perf.

David

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

Re: aset and shorts, aset vs aset-int

2011-05-29 Thread bOR_
Thanks for the help, appreciated! It helped me figuring out where exactly 
things go haywire.

This works:
user> (let [^ints as (make-array Integer/TYPE 10)] (aset as 0 (+ (aget as 1) 
(aget as 2   
  
0 

and this breaks

user> (let [^shorts as (make-array Short/TYPE 10)] (aset as 0 (+ (aget as 1) 
(aget as 2 
No matching method found: aset   

What am I doing wrong?

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

Re: aset and shorts, aset vs aset-int

2011-05-29 Thread David Nolen
On Sun, May 29, 2011 at 4:35 PM, bOR_  wrote:

> Thanks for the help, appreciated! It helped me figuring out where exactly
> things go haywire.
>
> This works:
> user> (let [^ints as (make-array Integer/TYPE 10)] (aset as 0 (+ (aget as
> 1) (aget as 2
>
> 0
>
> and this breaks
>
> user> (let [^shorts as (make-array Short/TYPE 10)] (aset as 0 (+ (aget as
> 1) (aget as 2
> No matching method found: aset
>
> What am I doing wrong?
>

You need to cast to short.

(aset as 0 (short (+ (aget as 1) (aget as 2

David

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

Re: aset and shorts, aset vs aset-int

2011-05-29 Thread Ken Wesson
On Sun, May 29, 2011 at 1:39 PM, David Nolen  wrote:
> Vectors of primitives are more efficient,

[1]

> but there's work to be done for them to approach Java
> arrays in perf.

[2]

Aren't your statements [1] and [2] contradictory? Did you mean "more
idiomatic" perhaps in [1], or "more functional"?

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

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


Re: aset and shorts, aset vs aset-int

2011-05-29 Thread Jonathan Fischer Friberg
I think he meant that vectors of primitives are more efficient than normal
vectors.

Jonathan

On Sun, May 29, 2011 at 11:26 PM, Ken Wesson  wrote:

> On Sun, May 29, 2011 at 1:39 PM, David Nolen 
> wrote:
> > Vectors of primitives are more efficient,
>
> [1]
>
> > but there's work to be done for them to approach Java
> > arrays in perf.
>
> [2]
>
> Aren't your statements [1] and [2] contradictory? Did you mean "more
> idiomatic" perhaps in [1], or "more functional"?
>
> --
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.
>
> --
> 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
>

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

Re: aset and shorts, aset vs aset-int

2011-05-29 Thread Alan Malloy
More efficient than vectors of non-primitives, one imagines. Or, more
efficient than primitive vectors before 1.3 (I'm not sure if primitive
vectors exist in 1.2).

On May 29, 2:26 pm, Ken Wesson  wrote:
> On Sun, May 29, 2011 at 1:39 PM, David Nolen  wrote:
> > Vectors of primitives are more efficient,
>
> [1]
>
> > but there's work to be done for them to approach Java
> > arrays in perf.
>
> [2]
>
> Aren't your statements [1] and [2] contradictory? Did you mean "more
> idiomatic" perhaps in [1], or "more functional"?
>
> --
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.

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