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: Ernst Reissner
Subject: Re: invoking java from within octave and do overloading
Date: Sun, 31 Oct 2010 16:09:18 +0100
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

Hello Michael,

  
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?
  
Yes, the message was:

octave:1> l2r(0.4)
error: `XFPNumber' undefined near line 7 column 9
error: called from:
error:   /usr/share/octave/3.2.4/m/left2right/l2r.m at line 7, column 7

although
## load java package to enable l2r arithmetics
pkg load java
## load jar first and then classes
javaaddpath('/home/ernst/Software/jars/createdApp.jar')
javaaddpath('/home/ernst/Software/cls')

##XFPNumber = java_get('eu.simuline.arithmetics.left2right.XFPNumber','ONE');
XFPNumber = java_invoke('eu.simuline.arithmetics.left2right.XFPNumber',
                        'atomic',
                         java_new('java.lang.Double',2.5));
##FPNumber = java_get('eu.simuline.arithmetics.left2right.FPNumber', 'ONE');
double    = java_new('eu.simuline.octave.Number');
Number    = XFPNumber;

although octaverc looks like this:
## load java package to enable l2r arithmetics
pkg load java
## load jar first and then classes
javaaddpath('/home/ernst/Software/jars/createdApp.jar')
javaaddpath('/home/ernst/Software/cls')

##XFPNumber = java_get('eu.simuline.arithmetics.left2right.XFPNumber','ONE');
XFPNumber = java_invoke('eu.simuline.arithmetics.left2right.XFPNumber',
                        'atomic',
                         java_new('java.lang.Double',2.5));

I thought, octaverc was invoked quite early.


  
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.
  
ok, this was one point.
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.
  
Yes, this is exactly the problem.
I do not want this.
I would like to dispatch separately for lr-arithmetics, interval arithmetics, bigdecimal arithmetics and all others.

How can i do this?
Can you tell me where to look up the class octave_java?

greetings,
Ernst


  


reply via email to

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