Re: Java ready for number crunching?
Lew wrote:
Monty Hall wrote:
While I can understand why Sun implemented templates as they did, to
me the problem w/ Java templates is that
Java does not have templates.
Sorry, I meant generics.
primitives. I don't like boxing and unboxing primitives as there is a
space and speed penality (or is there? some optimization?)
Study the matter, then make the claim. There is generally little to no
"penalty" for boxing and unboxing.
WOW! Now that's a claim! Please let Sun, IBM, NIST, the academy, or
any authors of java numerical software know of your insight. I know a
fair number of people who would love a generic java numerics library.
Little or no penalty casting to/fro primitive numerical types? What
libraries are you using? Is it open source and where can I get it!
I mostly use templates
but not in Java.
The following is from Sun. I would think there would be many
"performance critical inner loops" in numerical code. Study the matter,
then make the claim.
You can have the last word - I suspect you will.
Monty
///////////////////////////////////
// List adapter for primitive int array
public static List<Integer> asList(final int[] a) {
return new AbstractList<Integer>() {
public Integer get(int i) { return a[i]; }
// Throws NullPointerException if val == null
public Integer set(int i, Integer val) {
Integer oldVal = a[i];
a[i] = val;
return oldVal;
}
public int size() { return a.length; }
};
}
The performance of the resulting list is likely to be poor, as it boxes
or unboxes on every get or set operation. It is plenty fast enough for
occasional use, but it would be folly to use it in a performance
critical inner loop.