Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interfacing octave with C#

Tags:

c#

math

octave

I have developed a program in Octave to which I would like to add a GUI layer. I want to create an executable program in C# that I can distribute but want to stick with the linear algebra constructs of Octave without having to implement them on my own. Particularly, I want basic matrix, vector operations and optimization functions (like fminunc and fmincg).

What is the best way to achieve this? Appropriate C# linear algebra library, perhaps?

like image 631
Vikesh Avatar asked Nov 06 '11 12:11

Vikesh


4 Answers

There are lots of math libraries for c#. Math.NET Numerics seems to be a good free alternative. There are also commercial implementations.

Another alternative is to call Octave with Process.Start and parse the output. This saves you from rewriting your calculations but you need to able do bundle Octave with your application. If you want to tightly mix c# and math code this will be a quite complicated, but if your math code is a big calculation with a single set of inputs and a single set of outputs it might be a good alternative.

like image 184
Albin Sunnanbo Avatar answered Nov 16 '22 12:11

Albin Sunnanbo


I have written an Octave C# wrapper for my Adastra project:

http://code.google.com/p/adastra/source/browse/trunk/src/Adastra/Tools/OctaveController.cs

This is an example usage: http://code.google.com/p/adastra/source/browse/trunk/src/Adastra/Algorithms/OctaveLogisticRegression.cs This is a hybrid Octave and C# implementation of Logistic Regression classificator.

like image 25
Anton Andreev Avatar answered Nov 16 '22 12:11

Anton Andreev


To build a standalone: http://www.gnu.org/software/octave/doc/interpreter/Standalone-Programs.html#Standalone-Programs

I have a similar problem, which is to create a .dll for C# I've been looking for a way to do this for a while now, I have not been able to find instructions or an easy way to do it. This is more an ongoing project than a question, but I' d definitely take any answer or help!:)

I am planning to keep track of my efforts here, so at the end this should become a page that will allow people to find how to compile octave into a .dll ( always assuming this is possible)

So:

-I am using VS2010

-I started with the MS VS2010 compiled binaries for octave, assuming this will be closer.

-I created a project in VS and used the following code:

#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>


int main(int argc, char* argv[])
{
    std::cout<<"hello world"<<std::endl;
    char a[900];
    std::cin>>a;
    return 0;
}

-The code would of course not find the octave libs, so I added them, e.g.,

C:\Octave\Octave-3.6.1-VS10\lib\octave\3.6.1;C:\Octave\Octave-3.6.1-VS10\include\octave-3.6.1;C:\Octave\Octave-3.6.1-VS10\include;$(VCInstallDir)include;...

To Include Directories (Right click on Project-->Properties)

Now I get

Error   73  error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall octave_value::~octave_value(void)" (__imp_??1octave_value@@QAE@XZ) referenced in function "public: void * __thiscall octave_value::`vector deleting destructor'(unsigned int)" (??_Eoctave_value@@QAEPAXI@Z)    ...\Projects\cppap32\cppap32\main.obj   cppap32

which basically means it cannot find octave_value... By using dumpbin.exe we can see that it needs to have both octave.lib AND octinterp.lib

It now does compile.... :)

Next step create a .dll ...

Notes:

To check what is exported by a .lib:

dumpbin.exe /exports C:\Octave\Octave-3.6.1-VS10\lib\octave\3.6.1\octave.lib

Relevant links:

Similar, open question on other site: http://www.daniweb.com/software-development/cpp/threads/297336/gnu-octave-for-c-how-to-start

like image 3
7 revs Avatar answered Nov 16 '22 12:11

7 revs


Maybe you can look the Xoctave. This is an GUI written for Octave. Here is the link: www.xoctave.com

And maybe the guys there could have a solution for your questions.

like image 1
macrobook Avatar answered Nov 16 '22 13:11

macrobook