Posted by
Luigi Ballabio on
Sep 04, 2007; 9:26am
URL: http://quantlib.414.s1.nabble.com/swig-and-java-bindings-tp1316p1317.html
On Mon, 2007-09-03 at 14:19 +0100, Richard Gomes wrote:
> I have some code already written in Java, using third party math libs and
> I'm evaluating the possibility of adopting QuantLib as far as possible.
>
> I've noticed that swig did an incomplete job, for instance:
>
> // Create 2 matrices
> Matrix a = new Matrix(4, 4);
> Matrix b = new Matrix(4, 4);
>
> // SWIG did not converted C++: operator[] to something like
> // Java: Array get(int)
> a[0][3] = 5; // it does not compile in Java
>
> // SWIG did not converted C++: operator* to something like
> // Java: Matrix multiply(Matrix)
> Matrix c = a * b; // it does not compile in Java
>
> How it can be done?
You'll have to edit the corresponding SWIG interface file, namely,
linearalgebra.i, regenerate the wrappers, and recompile.
As for the edit, you have to add the methods you want to the Matrix
interface, e.g.,
class Matrix {
...
#if defined(SWIGJAVA)
Array get(int i) {
Array a(self->columns());
std::copy(self->row_begin(i), self->row_end(i), a.begin());
return a;
}
Matrix multiply(Matrix m) {
return *self * m;
}
...
#endif
...
};
I'll be happy to include your patch in next release. And of course you
can post here if you need a hand to make it work.
Later,
Luigi
--
Hanlon's Razor:
Never attribute to malice that which is adequately explained
by stupidity.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>
http://get.splunk.com/_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users