I'm trying to use part of Quantlib in C#, but the swig interface seems
incomplete. I followed a thread about a similar problem using QuantLib with Java, and I've quoted part of a message from that thread below. I believe I'm having the same issues as the Java people, so I'm working on fixing the linearalgebra.i interface to the Matrix class, in order to use it with C#. I think I've got something working, but I thought I would post this in case anyone else is working on the same thing and/or encounters the same issues. So here are some questions, comments, and a tip to solve a problem I encountered: Questions: 1) Why is the SWIG interface for the Matrix class defined in a file called linearalgebra.i rather than a file called Matrix.i or Matrix.swg? 2) Why do they use .i files instead of .swg files? Wouldn't it be more clear that .swg files are SWIG files, to a developer new to SWIG? 3) In the swig/java thread, Luigi Ballabio was kind enough to offer some sample code to create SWIG bindings, he said: > 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 believe I understand this code for the most part, but I wasn't sure why get returns an entire row of the matrix, and isn't used to just get one cell? Is it related to efficiency/speed? Comment/Opinion: Regarding the QuantLib C++ code here, it seems like self->columns() should be called self->numColumns(). I expect a method called self->columns() to return a set of columns (which I guess would be a Matrix) rather than the number of columns. Tip: For those who might be building the SWIG bindings on Windows: I couldn't figure out how to make the Quantlib-SWIG/CSharp project re-build the swig bindings. I tried by re-building each part of the QuantLib-SWIG project (in Visual Studio) using "Rebuild All" and rebuilding the Solution using "Rebuild All", but that did not re-build the swig bindings. So, after a long and frustrating search and several futile attempts, I managed to discover the magic incantation to re-build the swig bindings on the command line. At first, I kept getting the error that "swig.swg" and other files were not found -- i.e. it couldn't find the main swig library directory. First I tried adding it to the Windows PATH, but that didn't help. Eventually I figured out how to tell swig where the swig libraries are: you have to set an environment variable called SWIG_LIB by doing something like the following: set SWIG_LIB=[your path here]\swigwin-1.3.31\Lib This isn't the recommended method according to the documentation, but since I don't know what ./configure is, and I don't have mingw or minw or whatever it is, I couldn't run ./configure and I'm not sure that would have done much for me anyway. (And installing all that to do something 'relatively simple' seems like a huge hassle.) cheers, Paul G. ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
On Thu, 2007-09-27 at 16:31 -0400, Paul Gentry(INTERN) wrote:
> I'm trying to use part of Quantlib in C#, but the swig interface seems > incomplete. I followed a thread about a similar problem using QuantLib > with Java, and I've quoted part of a message from that thread below. > > I believe I'm having the same issues as the Java people, so I'm working > on fixing the linearalgebra.i interface to the Matrix class, in order to > use it with C#. I think I've got something working, but I thought I > would post this in case anyone else is working on the same thing and/or > encounters the same issues. Paul, are you willing to contribute the updated bindings? > So here are some questions, comments, and a tip to solve a problem I > encountered: > > Questions: > 1) Why is the SWIG interface for the Matrix class defined in a file > called linearalgebra.i rather than a file called Matrix.i or Matrix.swg? Because it contains interfaces for both Array and Matrix. It's called after the subdomain it's exporting. > 2) Why do they use .i files instead of .swg files? Wouldn't it be more > clear that .swg files are SWIG files, to a developer new to SWIG? It seemed to be the existing practice among SWIG developers. > 3) In the swig/java thread, Luigi Ballabio was kind enough to offer some > sample code to create SWIG bindings, he said: > [...] > I believe I understand this code for the most part, but I wasn't sure > why get returns an entire row of the matrix, and isn't used to just get > one cell? Is it related to efficiency/speed? No, it was just the interface requested by the poster I was replying to. One can just as easily export get(i,j) if it's more idiomatic C#. > Tip: > For those who might be building the SWIG bindings on Windows: I couldn't > figure out how to make the Quantlib-SWIG/CSharp project re-build the > swig bindings. It's done externally, by running the included swig.cmd script. You're right, this should be documented. > I kept getting the error > that "swig.swg" and other files were not found -- i.e. it couldn't find > the main swig library directory. First I tried adding it to the Windows > PATH, but that didn't help. Eventually I figured out how to tell swig > where the swig libraries are: you have to set an environment variable > called SWIG_LIB by doing something like the following: > set SWIG_LIB=[your path here]\swigwin-1.3.31\Lib Strange---as long as the Lib folder is in the same location as the SWIG executable (swig.exe) it should pick it up automatically---at least it does on my machine. > This isn't the recommended method according to the documentation, but > since I don't know what ./configure is, and I don't have mingw or minw > or whatever it is, I couldn't run ./configure and I'm not sure that > would have done much for me anyway. (And installing all that to do > something 'relatively simple' seems like a huge hassle.) True---configure only applies to Linux or MinGW. You're better off your way on a Windows machine. Thanks for the feedback, Luigi -- Cogito ergo I'm right and you're wrong. -- Blair Houghton ------------------------------------------------------------------------- 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 |
Free forum by Nabble | Edit this page |