[Top][All Lists]

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

Re: Two questions about Java in Octave 4

From: Carnë Draug
Subject: Re: Two questions about Java in Octave 4
Date: Mon, 29 Feb 2016 16:49:44 +0000

On 29 February 2016 at 06:43:51 -0500, Ericbarnhill
<address@hidden> 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.
> 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
such tests?

There is an Octave function java_matrix_autoconversion() which I never quite
figured what it should do and might help you.


reply via email to

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