Thanks for the input on this. I have the source and in a few weeks' time I will go check and see if it has been implemented. If not I'll be happy to join the dev list and see if I can add the functionality.
In the meantime, the best solution seems to be to vectorise the input, pass the vector and array dimensions to Java, and reassemble on the Java side, which is really not much trouble.
-------- Original Message --------
Subject: Re: Two questions about Java in Octave 4
Local Time: February 29, 2016 5:49 pm
UTC Time: February 29, 2016 4:49 PM
On 29 February 2016 at 06:43:51 -0500, Ericbarnhill
> Two questions about Octave Java usage. I would be happy to push some small
> changes to the Java section of the Octave FAQ after discussing, if the
> community so wishes.
> 1) sending (>1)D arrays to Java methods.
> One of my objects has methods called dt.forward1d(double x) and
> dt.forward2d(double x).
> The following works: dt.forward1d(ones(64, 1))
> However the following does not: dt.forward2d(ones(64,64))
> Can anyone explain why this is so. Do I need to send JavaArray objects
> for dims > 1.
> 2) javaArrays. Can anyone cite the exact syntax for creating a java array
> of primitive type, say double. The following works:
> javaArray("java.lang.Double", 16, 16)
> but is of course boxed. The following does not:
> javaArray("double", 16, 16)
> The FAQ specifies that primitives are supported so perhaps I can add to the
> FAQ the specific syntax to create a double array.
A couple of things:
1) java primitives are automatically converted into Octave types. This was
done for compatibility with Matlab documentation (this might change in the
future because Matlab doesn't actually do it).
2) java arrays can be ragged. Octave arrays cannot. I remember looking
at the code and having a path to unbox 1 dimensional arrays but not when
there were more dimensions.
This said, javaArray() creates an array of java objects. Even if you could
use it for primitives, since Octave unboxes them automatically, you would get
back an Octave array. Therefore you should just use "ones (16, 16)" like
you already tried. It is possible that it hasn't been implemented yet?
It would be very helpful if there were tests for this cases that did not
require java packages, that it only use java core functions. Can you write
There is an Octave function java_matrix_autoconversion() which I never quite
figured what it should do and might help you.