octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #58745] Conversion between matrices and Java a


From: Benjamin Moody
Subject: [Octave-bug-tracker] [bug #58745] Conversion between matrices and Java arrays
Date: Fri, 10 Jul 2020 15:00:24 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0

URL:
  <https://savannah.gnu.org/bugs/?58745>

                 Summary: Conversion between matrices and Java arrays
                 Project: GNU Octave
            Submitted by: bmoody
            Submitted on: Fri 10 Jul 2020 07:00:22 PM UTC
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
                 Release: 5.2.0
         Discussion Lock: Any
        Operating System: Any

    _______________________________________________________

Details:

In order to pass a vector or matrix as an argument to a Java method, or to
return a vector or matrix value from a Java method, the value needs to be
converted from a Java object to an Octave value, or vice versa.

In Matlab, this conversion is supposed to be automatic, as (partially)
documented here:

https://www.mathworks.com/help/matlab/matlab_external/passing-data-to-java-methods.html
https://www.mathworks.com/help/matlab/matlab_external/handling-data-returned-from-java-methods.html

It gets very messy, but let's focus on the common cases:
* Passing a vector (1xN or Nx1) as an argument converts it into a Java array.
* Passing a matrix (MxN) as an argument converts it into a two-dimensional
Java array.
* Returning an array from a Java method converts it into a column vector.
* Returning a rectangular two-dimensional array from a Java method converts it
into a matrix.

Octave seems to work the same way for vectors.  For matrices, however, it is
considerably more complicated:
* If a matrix is passed as an argument, it is converted into either an
org.octave.OctaveReference object (if java_matrix_autoconversion is 0) or an
org.octave.Matrix object (if java_matrix_autoconversion is 1).
* If a Java method returns a two-dimensional array, it is left as a
semi-opaque "Java object", which can be indexed, but can't be used directly as
a matrix, or converted directly to another type (e.g. calling double() gives
"invalid conversion from octave_java to double".)
* If a Java method returns an org.octave.Matrix object and
java_matrix_autoconversion is 1, it is converted into an Octave matrix.
* The 'java2mat' function is provided as a way to explicitly convert
two-dimensional arrays to matrices.  (Long ago, I believe, it was also
necessary to use this for one-dimensional arrays as well.)  However, this
function has now been deprecated, and (as far as I know) it never worked for
types other than double.

Automatic conversion can be less efficient, but I think it would be preferable
for convenience and for compatibility with Matlab's Java interface.

One possibility would be to make automatic conversions the default, but keep
both existing behaviors as options for compatibility.  (For example, we could
say that "java_matrix_autoconversion(2)" would be the default, but a program
could explicitly call "java_matrix_autoconversion(0)" or
"java_matrix_autoconversion(1)" to get the old behavior.)

Another possibility would be to keep the current default behavior but to add
Matlab-style autoconversion as an option that must be enabled explicitly.

A third possibility would be to always use Matlab-style autoconversion and
remove all support for "java_matrix_autoconversion".


This issue is tangentially related to, but separate from, several existing
bugs:
* bug #48591 (handling of java.lang.Number objects)
* bug #51822 (handling of multi-dimensional object arrays)
* bug #53524 ("fuzzy prototype matching" for scalars)
* bug #54170 (handling of character arrays)




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?58745>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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