help-octave
[Top][All Lists]
Advanced

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

Re: Basic question: usage of Java methods in Octave


From: PhilipNienhuis
Subject: Re: Basic question: usage of Java methods in Octave
Date: Wed, 16 Oct 2013 05:51:23 -0700 (PDT)

Michael Goffioul wrote
> On Tue, Oct 15, 2013 at 6:58 PM, Michael Goffioul <

> michael.goffioul@

>> wrote:
> 
>> On Tue, Oct 15, 2013 at 6:15 PM, Michael Goffioul <
>> 

> michael.goffioul@

>> wrote:
>>
>>> On Tue, Oct 15, 2013 at 5:27 PM, PhilipNienhuis &lt;

> pr.nienhuis@

> &gt;wrote:
>>>
>>>> Fedemone wrote
>>>> > Hi Philip,
>>>> >
>>>> > sorry forr late answer, I forgot in previous days...
>>>> >
>>>> > You are right, the code is really ugly, and my duty right now is to
>>>> > reverse-engineer it, in order to make this third-party-code usable
>>>> locally
>>>> > in Octave rather than Matlab.
>>>> > That's where all the problems rise, and I'm try to do what you
>>>> suggest: to
>>>> > dissect, to de-assembly in simplier code and to understand what are
>>>> the
>>>> > single elements (some are surely variables, other are functions
>>>> declared
>>>> > elsewhere, Integer and Float should be Java classes... a real mess).
>>>> >
>>>> > By the way, trying to use the Java Method seems a bit less intuitive
>>>> than
>>>> > expected:
>>>> >
>>>> > octave:1> x = javaMethod('floatToIntBits', 'java.lang.Float', 10.07)
>>>> > error: [java] java.lang.IllegalArgumentException
>>>> >
>>>> > Actually no numer is accepted in this way, and any manual I'm lookin
>>>> ginto
>>>> > is lacking of the very basic introduction to method usage...
>>>>
>>>> Starting off with the basics:
>>>>
>>>> (Octave-3.7.7+ on MinGW)
>>>>
>>>> >> x = javaObject ("java.lang.Float", 10.07)
>>>> x =
>>>>
>>>> 
> <Java object: java.lang.Float>
>>>>
>>>> >> x.floatToIntBits
>>>> error: [java] java.lang.NoSuchFieldException: floatToIntBits
>>>>
>>>> ## Field? This doesn't look right.
>>>>
>>>
>>> The current code only looks for method when you use a combination of .
>>> and (. That is something like:
>>>
>>> x.floatToIntBits()
>>>
>>> That is probably another compatibility problem.
>>>
>>
>> Actually, because it's a static method, it should be something like:
>>
>> x.floatToIntBits(x)

x.toString 

(toString is a static method as well) works all right, so Octave is at least
a bit inconsistent.
IIRC (but my memory may be hazy) I've used a lot of static method calls this
way in the io package.


>> and that leads to the original java.lang.IllegalArgumentException as
>> reported initially.
> 
> I'm not sure what version of octave/java the original poster is using, but
> the current development source is behaving better than initially reported.
> For instance, the following worked for me:
> 
> javaMethod('floatToIntBits', 'java.lang.Float', single(10.07))
> 
> However, there was still a bug in automatic conversion between numeric
> types, which is fixed by this changeset:
> 
> http://hg.savannah.gnu.org/hgweb/octave/rev/78e9bfdc544e

Thanks.
Perhaps it is better to check this for all other Java data types currently
supported in octave. I'll try to have a look tonight.

Anyway, Rik has a long To-Do list for Java here:
http://savannah.gnu.org/task/?12601

As to Matlab:
r2012a does this:

============================================
>> x = javaObject ('java.lang.Float', 10.07)

x =
 
10.07
 
>> x.floatToIntBits
No method 'floatToIntBits' with matching signature found for class
'java.lang.Float'.
 
>> x.floatToIntBits()
No method 'floatToIntBits' with matching signature found for class
'java.lang.Float'.

>> methods (x)

Methods for class java.lang.Float:

Float              floatToRawIntBits  isNaN              toString           
byteValue          floatValue         longValue          valueOf            
compare            getClass           notify             wait               
compareTo          hashCode           notifyAll          
doubleValue        intBitsToFloat     parseFloat         
equals             intValue           shortValue         
floatToIntBits     isInfinite         toHexString        

>> javaMethod ('floatToIntBits', x)
Error using javaMethod
No floatToIntBits method with appropriate signature
exists in Java class java.lang.Float

>> javaMethod('floatToIntBits', 'java.lang.Float', single(10.07))

ans =

   1.0927e+09

>> javaMethod('floatToIntBits', 'java.lang.Float', 10.07)

ans =

   1.0927e+09

>> javaMethod('floatToIntBits', 'java.lang.Float',
>> javaObject('java.lang.Float', 10.07))
Error using javaMethod
No static floatToIntBits method with appropriate signature
exists in Java class java.lang.Float

============================================

I like Octave's behavior a little better than that of Matlab.

Philip




--
View this message in context: 
http://octave.1599824.n4.nabble.com/Basic-question-usage-of-Java-methods-in-Octave-tp4658091p4658291.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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