[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two questions about Java in Octave 4

From: PhilipNienhuis
Subject: Re: Two questions about Java in Octave 4
Date: Thu, 3 Mar 2016 11:19:31 -0800 (PST)

Ericbarnhill wrote
> 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.

That entirely depends on what classes (types) your Java method dt.forward2d
expects. Based on your example it appears you need to send a javaArray.
I'm a little surprised the first form (1d) works at all, but again, that
depends on the actual Java method.

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

With Octave-4.1.0+ (development version), but equally on 4.0.1:

>> a  = javaArray ("double", 3, 2)
error: [java] java.lang.ClassNotFoundException: double
error: called from
    javaArray at line 50 column 10

... so that form you mentioned doesn't work. javaArray expects Java types,
not Octave types.

>> a  = javaArray ("java.lang.Double", 3, 2)
a =
<Java object: java.lang.Double[][]>
>> a(2, 2)
ans = [](0x0)
>> a(1:3,1:2) = rand(3, 2)
error: [java] java.lang.IllegalArgumentException: Argument is not an array
>> a(1,1) = 11
a =
<Java object: java.lang.Double[][]>
>> a(2,1) = 21
a =
<Java object: java.lang.Double[][]>
>> a(1, 1)
ans =  11

...which shows that the javaArray object itself isn't unboxed, but its
contents are as soon as you access them individually from Octave.

As to java_matrix_autoconversion() (mentioned by Carnë), that has a clear
use but it doesn't seem to function as advertised in its help text. Maybe
file a bug report after sorting out what it should do and test it?


View this message in context:
Sent from the Octave - General mailing list archive at

reply via email to

[Prev in Thread] Current Thread [Next in Thread]