Interfacing octave with C#
Asked Answered
A

5

22

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?

Attenweiler answered 6/11, 2011 at 12:18 Comment(1)
You should edit your title to match your question, you might get more people interested.Penile
S
10

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.

Sky answered 6/11, 2011 at 13:21 Comment(0)
T
9

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.

Tomlinson answered 17/12, 2011 at 12:28 Comment(3)
@Anton Andreev Can it handle plots? I can do calculations using OctaveController, but cannot figure out how to view the plots.Hueston
@Anton - this looks awesome; thanks for sharing. Do you know how easy this would be to get working in Mono on Linux? I see you've got some API calls to Kernel32... (UPDATE: I have spotted this: codeproject.com/Articles/342007/…)Stamm
The API calls are to avoid problems with names on Windows - when you have a space for example. It is not Octave or C# specific. On Linux this would not be needed. The code can be easily adapted to work with Mono, just need to be changed for things like \n\n etc.Tomlinson
F
3

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

Fabrienne answered 6/11, 2011 at 12:18 Comment(0)
F
1

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.

Freckle answered 30/12, 2012 at 12:8 Comment(0)
L
1

I recently needed this functionality for my pet-project and all existing solutions weren't user friendly or just didn't work. I created an open-source, cross-platform, .NET Standard library for this sole purpose. I hope it will save some headaches - Octave.NET on GitHub

Layoff answered 29/6, 2018 at 17:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.