bugGNU Octave - Bugs: bug #48790, javaArray('double',1)

 
 

bug #48790: javaArray('double',1)

Submitted by:  Ernst Reissner <ernstreissner>
Submitted on:  Mon 15 Aug 2016 05:25:25 PM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: None
Status: Need InfoAssigned to: None
Originator Name: Open/Closed: Open
Release: devOperating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Fri 19 Aug 2016 08:23:44 AM UTC, comment #4:

Nonono!!!

The site you cite,
https://www.mathworks.com/help/matlab/ref/javaarray.html,
clearly says

ObjArr = javaArray(PackageName.ClassName,x1,...,xN) constructs an empty Java® array object for objects of the specified PackageName.ClassName class.

That is clear and that is not what is done in Octave.
What you cite:

> To create an array of primitive Java types, create an array of the equivalent MATLAB type, shown in the Conversion of MATLAB Types to Java Types table. See Conversion of MATLAB Argument Data.


is a tip only and it says nothing about the return type of javaArray, right?
The tip is not bad, but not always applicable,
as seen in you other link,

https://www.mathworks.com/matlabcentral/answers/96483-how-can-i-pass-a-ragged-array-of-java-primitive-types-to-a-java-function-from-matlab

It is about ragged arrays, which are supported by Java but not by Octave.

By the way, although maybe

> The ability to create Java primitive types is not available in MATLAB.


Octave HAS the ability to create arrays of primitive types.
It is an undocumented feature, that instead of a string,
one can pass a class and in particular Double.TYPE
as I pointed out below.
Maybe matlab can do so as well.

Also:
javaObject('java.lang.Double',42)
yields

ans =

<Java object: java.lang.Double>

not just 42 for that reason.

A re

Ernst Reissner <ernstreissner>
Fri 19 Aug 2016 01:41:19 AM UTC, comment #3:

According to https://www.mathworks.com/matlabcentral/answers/96483-how-can-i-pass-a-ragged-array-of-java-primitive-types-to-a-java-function-from-matlab

> The ability to create Java primitive types is not available in MATLAB.


And according to https://www.mathworks.com/help/matlab/ref/javaarray.html

> To create an array of primitive Java types, create an array of the equivalent MATLAB type, shown in the Conversion of MATLAB Types to Java Types table. See Conversion of MATLAB Argument Data.


So there is no Matlab compatibility issue here, Matlab simply dodges the issue. I see nothing wrong with what Octave does with this. The normal return value conversion rules should apply.

If there is any bug here, I think it's this

According to https://www.mathworks.com/help/matlab/matlab_external/handling-data-returned-from-a-java-method.html, any rectangular array of a primitive type returned by any function should be converted to the corresponding Octave type. So I would think arr above should be converted to an Octave double matrix of size [3, 3].

Mike Miller <mtmiller>
Project Administrator
Thu 18 Aug 2016 10:27:32 PM UTC, comment #2:

The problem is, that javaArray is a constructor invocation in matlab which means that the result is a java array.
In the example I provided, the result is an octave array or even an octave scalar, because boxing is applied.
The latter is wrong.

Ernst Reissner <ernstreissner>
Thu 18 Aug 2016 05:46:51 PM UTC, comment #1:

I don't see a bug here. Can you explain what you think should be returned instead? What does Matlab do? I can't find any reference on the Matlab docs of constructing an array using the javaArray funcion with the type set to a primitive (non-class) type.

But assuming the same return value conversion rules apply as with other functions, it looks to me like everything is working correctly here.

Mike Miller <mtmiller>
Project Administrator
Mon 15 Aug 2016 05:25:25 PM UTC, original submission:

According to

http://de.mathworks.com/help/matlab/ref/javaarray.html?searchHighlight=javaArray

javaArray(cls,1) has to return a java array
i.e. for Octave an instance of octave_java
wrapping some new cls[1].

Consider
octave:16> dblCls=java_get('java.lang.Double', 'TYPE')
dblCls =

<Java object: java.lang.Class>

This is the class of the type double.

o=javaArray(dblCls,1)
seems to be 0
and really:
class(o)
yields double instead of double[]

I know also the reason: javaArray is based on javaMethod
which performs boxing and unboxing.
That way, double[] is converted to a double scalar.

Ernst Reissner <ernstreissner>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by mtmiller (Posted a comment)
  • -unavailable- added by ernstreissner
  • -unavailable- added by ernstreissner (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 18 Aug 2016 05:46:51 PM UTCmtmillerCategoryNone=>Octave Function
      StatusNone=>Need Info
    Mon 15 Aug 2016 05:25:50 PM UTCernstreissnerCarbon-Copy-=>Added -unavailable-

    Back to the top


    Powered by Savane 3.1-cleanup1