[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
invoking java from within octave and do overloading
From: |
Ernst Reissner |
Subject: |
invoking java from within octave and do overloading |
Date: |
Sun, 31 Oct 2010 13:42:46 +0100 |
User-agent: |
Thunderbird 2.0.0.23 (X11/20090817) |
Hi all there,
i try to integrate a special arithmetics into octave, something like interval
arithmetics.
It is implemented in Java.
The main tool for integration is the package java 1.2.8.
Herzlichen Dank.
Several things work well like the constructor:
function fpNum = l2r(dNum)
fpNum = java_invoke('eu.simuline.arithmetics.left2right.XFPNumber',
'atomic',
java_new('java.lang.Double',dNum));
endfunction
and the sum
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.
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.
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??
How is overload of function plus(a,b) is tied to overload of infix operator +?
Help very much appreciated.
greetings,
Ernst
> >
- invoking java from within octave and do overloading,
Ernst Reissner <=