[Mono-devel-list] Mono and GSL
Paolo Molaro
lupus at ximian.com
Tue Mar 25 06:42:06 EST 2003
On 03/24/03 bsuss_ca at yahoo.ca wrote:
> I've been playing around with getting Mono to work
> with the Gnu Scientific Library (GSL).
Great!
> uncommenting the comment. If you
> have any clue about how to get this to work, it would
> be much appreciated.
>
> The complex number is a C struct that looks like:
> >>
> typedef struct
> {
> double dat[2];
> } gsl_complex;
> <<
Please file a bug report in bugzilla.ximian.it with the test case,
this looks like an error while marshaling back a structure with a fixed
length array when it's a return type.
> public struct complex
> {
> [MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
> public double[] dat;
>
> complex(double re, double im)
> {
> this.dat=new double[] {re,im};
> }
> }
Now, I would suggest implementing the mapping between gsl_complex and a
C# struct in this way, instead:
public struct complex
{
public double real;
public double imm;
complex(double re, double im) {
real = re;
imm = im;
}
}
This way, the generated code is much faster (no need to do conversions
when marshaling) and it uses less memory (no need to allocate an array).
Note: I still get the wrong result from gsl_complex_sin(), but at least
it doesn crash:-)
I haven't investigated what the issue really is, since the same test is
executed correctly by the new jit, mini (due out in a few days):
$ mini gsl.exe
1
5
3
3.85373687744141
The same program translated to C gives:
$ ./a.out
1
5
3
3.85374
lupus
--
-----------------------------------------------------------------
lupus at debian.org debian/rules
lupus at ximian.com Monkeys do it better
More information about the Mono-devel-list
mailing list