val X: Array[Float] = x.toFloatArray()
val Y = y.toFloatArray()
val data = Table.create("Data").addColumns(
FloatColumn.create("X", X),
FloatColumn.create("relu(x)", Y)
)
First of all, it would be good to mention from where do those functions came from.
Second, are you sure the error is real (meaning it was produced by a real compiler) or it is just in your IDE; if you are sure it is real then adding the compiler version, as well as the libraries and their versions, would help in reproduce and fix the problem.
If that comes from java then those methods should erase to exactly the same thing. Which makes me wonder how that bytecode is generated and accepted.
So I looked for the corresponding Java code and found this:
public static FloatColumn create(String name, Float[] arr)
So that’s an Array[java.lang.Float], not an array of primitive floats.
I guess you have to either convert to an Array[java.lang.Float] or call the varargs method with create("X", X :_*). I would expect the second one to be faster.
I can report this as an issue to the Tablesaw developers and find out why they use a boxed float. Maybe its needed to match on columns of different types?
I do have one more question though for @Jasper-M: why is the varargs call faster? That’s a conversion to a sequence, correct?
Not really in this case, since it is a vargars from Java which is a plain array, so it would just pass the variable as it is (I believe).
Jasper says it is faster because that, it won’t create a new array like my map approach and box each float. However, if the underlying algorithm boxes them in a new array then both are the same at the end - in any case, for small arrays you shouldn’t notice any difference, and for bigger ones then benchmarking in the only valid answer.