matrix business in D

Yura min_yura at mail.ru
Thu Oct 24 04:22:15 PDT 2013


Thank you very much for your help! I think I start to understand 
it better.

On Wednesday, 23 October 2013 at 14:48:52 UTC, John Colvin wrote:
> On Wednesday, 23 October 2013 at 14:00:46 UTC, Yura wrote:
>> Dear all,
>>
>> Thank you for your replies!
>>
>> Regarding Julia - it seems to be interesting, but - it is too 
>> fresh, and from what I understood, it is not compiled. I think 
>> D language would be more interesting for me and suitable for 
>> my needs (scientific computing).
>>
>> Yes, numpy/scipy is OK, but since I have now some time I would 
>> like to learn one compiled language which is more close to the 
>> hardware,
>>
>> "I have done some linear algebra in D. If you are comfortable
>> calling C functions, you can easily call into existing 
>> solutions,
>> because it is trivial to call into C from D."
>>
>> This is very interesting since as you know lots of code is 
>> written in c. GSL is a good example. The only problem is how 
>> to use it. The thing is that i don't know c, but the question 
>> is whether I really need to be skilled in c to be able to call 
>> c functions. My gut feeling is that no, I don't need to be 
>> skilled. I have installed gsl on my computer. But what I need 
>> is a good example of a code/codes on how to call this library 
>> from d programming language. E.g. I have tried to use gsl. I 
>> have written a code in c (simple.c):
>>
>> -------
>> #include <stdio.h>
>> #include <gsl/gsl_sf_bessel.h>
>>
>> double fun(double x)
>> //main (void)
>> {
>> //  x = 5.0;
>>  double y = gsl_sf_bessel_J0 (x);
>> //  printf ("J0(%g) = %.18e\n", x, y);
>>  return y;
>> }
>> ----------------
>> Also, I have written a di file (simple.di):
>> ----------------
>> extern (C):
>> double fun(double);
>> ----------------
>> And finally, d code (simple.d):
>> ------------------
>> import std.stdio, std.string, std.array;
>> import std.conv;
>>
>> import std.stdio;
>> import simple;
>>
>> void main(){
>>    writeln( fun(10.0) );
>> }
>> ------------------------------------
>>
>> Unfortunately, when I compile it it says:
>>
>> dmd simple.d simple.o
>> simple.d(8): Error: undefined identifier fun
>>
>> Could one provide a working clear example how to use gsl in D?
>>
>> I have tried SciD and it apparently works, though I did not 
>> test it so far. I think a tutorial on how to use D in 
>> scientific programming would be very appreciated and could 
>> attract more people to D.
>>
>> PS Thank all of you for helping.
>>
>>
>
>
> Don't call everything the same name. At the very least don't 
> have the di and d file with the same name.
>
> Once you've done that, it will compile but the linker will 
> start to complain. You will need to link to the gsl and 
> gslcblas libraries, making your compilation command this:
>
> dmd test.d simple.o -L-lgsl -L-lgslcblas
>
>
> The simplest possible example of using gsl would be this:
> simpleGSL.d
>
> import std.stdio;
>
> extern(C) double gsl_sf_bessel_J0(double);
>
> void main()
> {
>     writeln(gsl_sf__bessel_J0(10));
> }
>
> compile with dmd -L-lgsl -L-lgslcblas simpleGSL.d
>
>
> If you were doing this seriously you would want to create a 
> load of d or di files containing the extern(C) declarations for 
> all the different gsl things you need. Also, you might want to 
> take a look at dstep: https://github.com/jacob-carlborg/dstep 
> which might be able to auto-generate them all for you.



More information about the Digitalmars-d-learn mailing list