java - Using Generic Primitive Arrays in Scala -
this question has answer here:
- how can use primitives in scala? 2 answers
i asked this question whether possible parameterize type of primitive array in java. (basically, have array want either double[] or float[] based on argument. i'm using arrays of primitives rather arrays of wrapper classes (double[], float[]) because they're more memory-and-time efficient, when dealing big vector operations. answer, appears, no, can't in java.
so, new question is: can in scala? understand primitives kind of more hidden, , boxed on operations... if possible parameterize arrays being of double or float, , compiler implement them primitives, how tell if they're being unboxed, or otherwise implemented less efficiently if go "find: double, replace: float" in source code?
does work you?
object specialisedarray { def apply[@specialized(float, double) t: classtag](size: int) = new array[t](size) }
Comments
Post a Comment