help-octave
[Top][All Lists]
Advanced

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

Re: invoking java from within octave and do overloading


From: Michael Goffioul
Subject: Re: invoking java from within octave and do overloading
Date: Sun, 31 Oct 2010 13:13:41 +0000

On Sun, Oct 31, 2010 at 12:42 PM, Ernst Reissner <address@hidden> wrote:
> function fpNum = plus(fpNum1,fpNum2)
>  fpNum = java_invoke(fpNum1,'add',fpNum2);
> endfunction
>
> IT is great that oo-notation is usable. This allows also:
>
> function fpNum = plus(fpNum1,fpNum2)
>  fpNum = fpNum1.add(fpNum2);
>  endfunction
>
> I think that tje java-package uses the reflection api if i work with strings 
> which would slow down invocations.
> Thus the second version of plus is better.

Actually it's the opposite. The second oo form is internally
translated into a java_invoke
call. So while the second form is more elegant, it's also slightly
slower (though I guess
the overhead is not really significant compared to the rest of the process.)

> Naturally i want to use this technique also in the constructor.
> Another advantage is more flexibility, delivering the number type i need: 
> double or my XFPNumber.
>
> This led me to the idea to define in octaverc a constant XFPNumber
> assigned with an arbitrary instance of XFPNumber an to invoke directly
>
> XFPNumber.atomic(0.4)
>
> This works but on the command line only.
> In my file l2r.m it doesnt and so i pressume i cannot avoid reflection and 
> also i would prefer the second variant because i find it smoother.

Could you report the error you are seeing and a piece of code to reproduce your
problem? It should work the same. For instance, is XFPNumber variable accessible
from your constructor function?

>
> I also specified a class double implementing double.atomic(0.4)
> which just returns a double number.
>
> I could also invoke Number.atomic(0.4) where Number is initialized likewise 
> with XFPNumber or with Klasse double.
> That way one and the same script could run on two or more different 
> arithmetics which would ease comparison of the results.
> Another reason why i would appreciate XFPNumber.atomic(0.4) in scripts so 
> much.
> Is there some explanation or even better a fix?
>
>
> I would also like to use overloading for function plus,
> i.e. using plus(x,y) for my number type XFPNumber but also for classical 
> double's.
> I am new to octave but documentation seems to suggest something like
>
> dispatch ("sin", "spsin", "sparse matrix");
>
> What i consider strange is that i shall use the type `octave_java' not the 
> Java-classname
> eu.simuline.arithmetics.left2right.XFPNumber.
> This would be much more flexible because i could include several different 
> arithmetics in java.
>
> I tried:
>
> dispatch('plus','lr_plus','java_octave'),
>
> but this did not succeed:
> plus(l2r(0.3),l2r(0.4))
> yields
> binary operator `+' not implemented for `octave_java' by `octave_java'
> operations
>
> What went wrong here??

Maybe you got the class name wrong? In the dispatch call above, you
used java_octave for the type name, while if should be octave_java.

Note also that if you overload the + operator that way (assuming it
works ok, I'm not 100% sure you can overload standar operators
with dispatch), this will use your lr_plus function for *any* octave_java
object.

Michael.



reply via email to

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