bugGNU Octave - Bugs: bug #53524, Java: cannot call method requiring...

 
 

bug #53524: Java: cannot call method requiring array argument with single-element-array

Submitted by:  Adrian <adaerr>
Submitted on:  Fri 30 Mar 2018 11:38:28 AM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  4.2.2 Operating System:  GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Wed 18 Jul 2018 11:42:44 PM UTC, comment #2:

> I have no idea how Matlab behaves in this regard.


In Matlab, scalar primitives may be implicitly converted to Java arrays.

For example:

I believe that integer-valued scalar Matlab doubles may also be implicitly converted to Java int[], short[], byte[], and so on. Here's an example that I think demonstrates this.

I agree with you that this is unexpected behavior, and the N=1 case should not differ from the N>1 case.

There is one other concern: if you have an object that defines both `foo(double x)` and `foo(double x[])` methods, you may need some mechanism to disambiguate them if scalar doubles can auto-box to Java double[]s.

There's a discontinuity at the N=0 case: in Matlab, [] is implicitly converted to null, and not a 0-long array. IMHO, this is unfortunate, but Octave will probably need to do the same if it wants Matlab compatibility.

Andrew Janke <apjanke>
Fri 30 Mar 2018 11:58:45 AM UTC, comment #1:

Forgot to suggest that the conversion could be made wider to accept converting an octave scalar double to a Java primitive int[] array for the purpose of matching a method argument type.

Adrian <adaerr>
Fri 30 Mar 2018 11:38:28 AM UTC, original submission:

When calling a java object's method foo(int[] array) via

octave throws an

when the parameter vector (an octave double array of size (N,1)) has a single element (N=1). I guess this is because 'vector' in that case is a simple scalar, and being of type double is not cast to an array. However it is on one hand side unexpected that the case N=1 should behave differently from N>1 and make the script fail, and on the other hand side I see no work-around to call that method with a single-element-array as required.

I will bump bug #48790 which, if solved, would provide a work-around by explicitely creating a single element java array (currently the resulting array is immediately converted into an octave scalar).

Another solution would be to be able to provide conversion hints explicitely (as is possible in the opposite direction java->octave by applying e.g. function double on java objects #48591) instead of relying on auto(un)boxing.

I have no idea how Matlab behaves in this regard.

Adrian <adaerr>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

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

    Only project members can vote.

     

     

     

    No changes have been made to this item

    Back to the top


    Powered by Savane 3.3