bugGNU Octave - Bugs: bug #48749, size and dimensionality of java...

 
 

bug #48749: size and dimensionality of java arrays

Submitter:  Ernst Reissner <ernstreissner>
Submitted:  Wed 10 Aug 2016 02:05:07 PM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Need Info Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 19 Aug 2016 10:38:32 AM UTC, comment #7: 

in case of confirmation: delivered a fix.

(file #38274)

Ernst Reissner <ernstreissner>
Fri 19 Aug 2016 09:43:10 AM UTC, comment #6: 

Hi Mike,
what kind of information do you need to confirm or reject this bugreport?

Ernst Reissner <ernstreissner>
Fri 12 Aug 2016 10:53:10 PM UTC, comment #5: 

By the way,
n = numel(A) is equivalent to prod(size(A))
is not appropriate for Java arrays,
because they are usually ragged: the entries of Object[][]
in general do not have the same length.
Thus numel cannot be determined by product but by recursively summing up.

That may be the reason why matlab defines size(arr) for java arrays arr as it does.

Ernst Reissner <ernstreissner>
Fri 12 Aug 2016 09:16:51 PM UTC, comment #4: 

Hi Mike,
I overread a comment of you:
'To be compatible, the size of a Java array should always be Nx1 reflecting the length of the outermost array. The number of dimensions (ndims) should always be 2. It would be nice to confirm whether numel agrees with size for 2 or higher-dimensional Java arrays.'

Hm, according to matlab docs
http://de.mathworks.com/help/matlab/ref/numel.html,
n = numel(A) is equivalent to prod(size(A)).
So size(.) determines numel(.) not the other way round.
In the docs, nothing is mentioned on java or not.
This is not necessary,
because size makes the distinction.
That's the way, also Octave shall implement numel.

So, I think there is no futher info required
and I would vote (if i could) for confirming the bug.


Ernst Reissner <ernstreissner>
Thu 11 Aug 2016 06:49:01 PM UTC, comment #3: 

To fix this for Matlab compatibility, it would be useful to know what Matlab's numel(arr) returns on an N-dimensional Java array object.

Mike Miller <mtmiller>
Group Member
Thu 11 Aug 2016 02:31:30 PM UTC, comment #2: 

Hi Mike,
so you can change the status from need info to confirmed?
I would fix easily.

Ernst Reissner <ernstreissner>
Wed 10 Aug 2016 02:39:33 PM UTC, comment #1: 

That looks right according to my reading also.

The current Octave behavior is nice, but not fully Matlab compatible. The higher dimensions in the returned size are just the lengths of the first nested arrays.

To be compatible, the size of a Java array should always be Nx1 reflecting the length of the outermost array. The number of dimensions (ndims) should always be 2. It would be nice to confirm whether numel agrees with size for 2 or higher-dimensional Java arrays.

Mike Miller <mtmiller>
Group Member
Wed 10 Aug 2016 02:05:07 PM UTC, original submission:  

In

http://de.mathworks.com/help/matlab/ref/size.html

we read:

For a Java array, size returns the length of the Java array as the number of rows. The number of columns is always 1. For a Java array of arrays, the result describes only the top level array.

In fact, in octave,

octave:22> arr=javaArray('java.lang.Object',5)
arr =

<Java object: java.lang.Object[]>

octave:23> size(arr)
ans =

   5   1

Which is correct: 5 is the number of rows and 1 the number of columns.

But lets go on:

octave:24> arr=javaArray('java.lang.Object',5,4)
arr =

<Java object: java.lang.Object[][]>
octave:25> size(arr)
ans =

   5   4

which is not correct.

The result should still be 5 1.



Ernst Reissner <ernstreissner>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #38274:  patchBug48749.patch added by ernstreissner (5KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-08-19 ernstreissner Attached File- Added patchBug48749.patch, #38274
    2016-08-10 mtmiller CategoryNone Octave Function
        Severity3 - Normal 1 - Wish
        Priority5 - Normal 3 - Low
        Item GroupNone Matlab Compatibility
        StatusNone Need Info
        Summarysize of java arrays size and dimensionality of java arrays
    2016-08-10 ernstreissner Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-5884.
    Corresponding source code