www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - GNU Scientific Library in D

reply Lars Kyllingstad <public kyllingen.net> writes:
Hello,

I would like to use the GNU Scientific Library, which is written in C, in D.
While converting the header files to D modules, however I ran in to the
following problem. In gsl_math.h, the following (crucially important) struct is
defined:

struct gsl_function_struct 
{
  double (* function) (double x, void * params);
  void * params;
};

Note that the first member is named 'function', which unfortunately is a
keyword in D. Any suggestions as to how I can work around this?

-Lars
Jul 23 2007
next sibling parent reply Tomas Lindquist Olsen <tomas famolsen.dk> writes:
On Mon, 23 Jul 2007 14:05:19 -0400, Lars Kyllingstad wrote:

 Hello,
 
 I would like to use the GNU Scientific Library, which is written in C, in
 D. While converting the header files to D modules, however I ran in to the
 following problem. In gsl_math.h, the following (crucially important)
 struct is defined:
 
 struct gsl_function_struct
 {
   double (* function) (double x, void * params); void * params;
 };
 
 Note that the first member is named 'function', which unfortunately is a
 keyword in D. Any suggestions as to how I can work around this?
 
 -Lars

Renaming it to func or something else in you D header is not going to break anything. -Tomas
Jul 23 2007
parent reply Lars Kyllingstad <public kyllingen.net> writes:
Tomas Lindquist Olsen Wrote:

 On Mon, 23 Jul 2007 14:05:19 -0400, Lars Kyllingstad wrote:
 
 Hello,
 
 I would like to use the GNU Scientific Library, which is written in C, in
 D. While converting the header files to D modules, however I ran in to the
 following problem. In gsl_math.h, the following (crucially important)
 struct is defined:
 
 struct gsl_function_struct
 {
   double (* function) (double x, void * params); void * params;
 };
 
 Note that the first member is named 'function', which unfortunately is a
 keyword in D. Any suggestions as to how I can work around this?
 
 -Lars

Renaming it to func or something else in you D header is not going to break anything. -Tomas

Thanks a lot, worked like a charm. But out of curiosity I would like to know why. Aren't the functions in the GSL libraries expecting a field named 'function' there? Or don't the names of the fields matter at all, as long as the structure is the same? -Lars
Jul 23 2007
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Lars Kyllingstad" <public kyllingen.net> wrote in message 
news:f834gc$n1q$1 digitalmars.com...
 Thanks a lot, worked like a charm. But out of curiosity I would like to 
 know why. Aren't the functions in the GSL libraries expecting a field 
 named 'function' there? Or don't the names of the fields matter at all, as 
 long as the structure is the same?

Field names mean nothing after compilation; they're just there for the programmer. They get turned into a byte offset. So, as long as the structure remains the same, the code doesn't care what you call it.
Jul 23 2007
prev sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
Lars Kyllingstad wrote:
 I would like to use the GNU Scientific Library, which is written in C, in D.
While converting the header files to D modules, however I ran in to the
following problem. In gsl_math.h, the following (crucially important) struct is
defined:

When you get it done, can you contribute it to Dsource? That way, everyone can use it!
Jul 23 2007
next sibling parent reply Lars Kyllingstad <public kyllingen.net> writes:
Walter Bright Wrote:

 Lars Kyllingstad wrote:
 I would like to use the GNU Scientific Library, which is written in C, in D.


 When you get it done, can you contribute it to Dsource? That way, 
 everyone can use it!

Sure! Assuming that I am able to make it work, that is... :) -Lars
Jul 23 2007
parent reply Don Clugston <dac nospam.com.au> writes:
Lars Kyllingstad wrote:
 Walter Bright Wrote:
 
 Lars Kyllingstad wrote:
 I would like to use the GNU Scientific Library, which is written in C, in D.


 When you get it done, can you contribute it to Dsource? That way, 
 everyone can use it!

Sure! Assuming that I am able to make it work, that is... :) -Lars

What parts of the GSL are you particularly interested in? I've been gradually building up a D scientific library, and I've made sure that Tango.Math.IEEE contains all the required primitive operations.
Jul 23 2007
parent Lars Kyllingstad <public kyllingen.net> writes:
Don Clugston Wrote:

 What parts of the GSL are you particularly interested in? I've been gradually 
 building up a D scientific library, and I've made sure that Tango.Math.IEEE 
 contains all the required primitive operations.

Until now I've mostly done numerical integration and multidimensional root finding, so those are the parts of the GSL I am concentrating on first. However, I am starting on my PhD in particle physics this fall, and I am not completely sure yet what other features I will need. -Lars
Jul 24 2007
prev sibling parent reply Witold Baryluk <baryluk smp.if.uj.edu.pl> writes:
Walter Bright wrote:

 Lars Kyllingstad wrote:
 I would like to use the GNU Scientific Library, which is written in C, in
 D. While converting the header files to D modules, however I ran in to
 the following problem. In gsl_math.h, the following (crucially important)
 struct is defined:

When you get it done, can you contribute it to Dsource? That way, everyone can use it!

I was using gsl in D with out problems. This is very good C library. BTW. I started some time ago similar library for D, designed from scratch. http://tsk.ch.uj.edu.pl/wiki/onp If anyone is interested in helping me in development, I will be happy :)
Jul 26 2007
parent reply Don Clugston <dac nospam.com.au> writes:
Witold Baryluk wrote:
 Walter Bright wrote:
 
 Lars Kyllingstad wrote:
 I would like to use the GNU Scientific Library, which is written in C, in
 D. While converting the header files to D modules, however I ran in to
 the following problem. In gsl_math.h, the following (crucially important)
 struct is defined:

everyone can use it!

I was using gsl in D with out problems. This is very good C library. BTW. I started some time ago similar library for D, designed from scratch. http://tsk.ch.uj.edu.pl/wiki/onp If anyone is interested in helping me in development, I will be happy :)

It's hard to evaluate without knowledge of Polish, but the breadth of work there is very impressive. What license are you using? BTW, it seems to me that the GSL, at least originally, was just a clone of Numerical Recipes, and the code I've seen reproduces the NR bugs. There is scope for a lot of improvement, I think.
Jul 27 2007
next sibling parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Don Clugston wrote:
 Witold Baryluk wrote:
 Walter Bright wrote:

 Lars Kyllingstad wrote:
 I would like to use the GNU Scientific Library, which is written in 
 C, in
 D. While converting the header files to D modules, however I ran in to
 the following problem. In gsl_math.h, the following (crucially 
 important)
 struct is defined:

everyone can use it!

I was using gsl in D with out problems. This is very good C library. BTW. I started some time ago similar library for D, designed from scratch. http://tsk.ch.uj.edu.pl/wiki/onp If anyone is interested in helping me in development, I will be happy :)

It's hard to evaluate without knowledge of Polish, but the breadth of work there is very impressive. What license are you using? BTW, it seems to me that the GSL, at least originally, was just a clone of Numerical Recipes, and the code I've seen reproduces the NR bugs. There is scope for a lot of improvement, I think.

Really? If that's true then it sounds like a violation of the Numerical Recipes' license agreement. --bb
Jul 27 2007
next sibling parent BCS <ao pathlink.com> writes:
Reply to Bill,
 Really?  If that's true then it sounds like a violation of the
 Numerical Recipes' license agreement.
 
 --bb
 

someone could have re written it from scratch using only the non code portions of the book and a the API spec.
Jul 27 2007
prev sibling parent reply Don Clugston <dac nospam.com.au> writes:
Bill Baxter wrote:
 Don Clugston wrote:
 Witold Baryluk wrote:
 Walter Bright wrote:

 Lars Kyllingstad wrote:
 I would like to use the GNU Scientific Library, which is written in 
 C, in
 D. While converting the header files to D modules, however I ran in to
 the following problem. In gsl_math.h, the following (crucially 
 important)
 struct is defined:

everyone can use it!

I was using gsl in D with out problems. This is very good C library. BTW. I started some time ago similar library for D, designed from scratch. http://tsk.ch.uj.edu.pl/wiki/onp If anyone is interested in helping me in development, I will be happy :)

It's hard to evaluate without knowledge of Polish, but the breadth of work there is very impressive. What license are you using? BTW, it seems to me that the GSL, at least originally, was just a clone of Numerical Recipes, and the code I've seen reproduces the NR bugs. There is scope for a lot of improvement, I think.

Really? If that's true then it sounds like a violation of the Numerical Recipes' license agreement.

I don't think so. Most of the Numerical Recipes code is itself cloned from published articles. It's easy enough to clone it by going back to the original sources. I doubt that the NR license would even be enforceable, in general -- their code often even uses the same variable names as were used in the original Algol code! There's not much original code in NR. (The big contribution of NR was to collate all the algorithms).
Jul 31 2007
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Don Clugston wrote:
 I don't think so. Most of the Numerical Recipes code is itself cloned 
 from published articles. It's easy enough to clone it by going back to 
 the original sources. I doubt that the NR license would even be 
 enforceable, in general -- their code often even uses the same variable 
 names as were used in the original Algol code! There's not much original 
 code in NR. (The big contribution of NR was to collate all the algorithms).

That doesn't stop some 'tards from claiming copyright infringement. I had some people accuse me of stealing their code once upon a time. In front of an arbitrator, they couldn't explain the etymology of (supposedly) their own variable names, while I could. They lost.
Aug 03 2007
parent reply 0ffh <spam frankhirsch.net> writes:
Walter Bright wrote:
 In front of an arbitrator, they couldn't explain the etymology of 
 (supposedly) their own variable names, while I could.

Goes to prove the usefulness of slightly cryptic variable names... ^^ Regards, Frank
Aug 05 2007
parent reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
0ffh wrote:
 Walter Bright wrote:
 In front of an arbitrator, they couldn't explain the etymology of 
 (supposedly) their own variable names, while I could.

Goes to prove the usefulness of slightly cryptic variable names... ^^ Regards, Frank

Or just foreign language ones. (Russian, Irish, and Japanese are favorites of mine.) ;) return this.scaoil ? Staid.Rath : Staid.Loiceadh ; Alas the lament of the poor maintenance coder. Its a shame I can't put accents in a symbol. -- Chris Nicholson-Sauls
Aug 05 2007
parent reply Deewiant <deewiant.doesnotlike.spam gmail.com> writes:
Chris Nicholson-Sauls wrote:
 return this.scaoil ? Staid.Rath : Staid.Loiceadh ;
 
 Alas the lament of the poor maintenance coder.  Its a shame I can't put
 accents in a symbol.
 

Sure you can! class Äöå { int fõó() { return Bàr.Ë; } } enum Bàr { Ë = 2 } void main() { auto x = new Äöå(); assert (x.fõó == 2); } Just save it in a UTF format. -- Remove ".doesnotlike.spam" from the mail address.
Aug 06 2007
parent Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Deewiant wrote:
 Chris Nicholson-Sauls wrote:
 return this.scaoil ? Staid.Rath : Staid.Loiceadh ;

 Alas the lament of the poor maintenance coder.  Its a shame I can't put
 accents in a symbol.

Sure you can! class Äöå { int fõó() { return Bàr.Ë; } } enum Bàr { Ë = 2 } void main() { auto x = new Äöå(); assert (x.fõó == 2); } Just save it in a UTF format.

Huh, I remember there being some problems with doing so... then again, that was actually a few years ago now. Nifty. :) I'm off to make some people even more mad at me than they already are. -- Chris Nicholson-Sauls
Aug 06 2007
prev sibling parent reply TomD <tdemmer.web nospam.de> writes:
Don Clugston Wrote:
[...]
 BTW, it seems to me that the GSL, at least originally, was just a clone of 
 Numerical Recipes, and the code I've seen reproduces the NR bugs. There is
scope 
 for a lot of improvement, I think.

the Recipes were originally written in FORTRAN, and even the C transcript (I am avoiding the word "port" here on purpose) is ugly. It is a clone in the sense that it gives tools for solving a similar set of problems. One target actually was to be as complete as the recipes, which it does not do, but it had some other additions that the Recipes lack. Out of curiosity, which bugs are in the current version? Ciao Tom
Jul 27 2007
parent reply Don Clugston <dac nospam.com.au> writes:
TomD wrote:
 Don Clugston Wrote:
 [...]
 BTW, it seems to me that the GSL, at least originally, was just a clone of 
 Numerical Recipes, and the code I've seen reproduces the NR bugs. There is
scope 
 for a lot of improvement, I think.

the Recipes were originally written in FORTRAN, and even the C transcript (I am avoiding the word "port" here on purpose) is ugly.

It's even worse than that. Much of the FORTRAN code is actually a port from Algol!
 It is a clone in the sense that it gives tools for
 solving a similar set of problems.

The relationship is closer: it provides the same set of algorithms, organised in the same way. One target actually was to be as complete as the recipes, which it does not do, but it had some other additions that the Recipes lack. Out of curiosity,
 which bugs are in the current version?

Little things like failing to check for overflow. (eg, a-b can overflow if a is large and positive, and b is large and negative). Sometimes these errors are not present in the original Algol. Extremely poor performance for worst-case situations. Mostly pretty obscure stuff.
 
 Ciao
 Tom

Aug 01 2007
parent TomD <t_demmer nospam.web.de> writes:
Don Clugston Wrote:
[...]
 
 It's even worse than that. Much of the FORTRAN code is actually a port from
Algol!

Ahh interesting, I did not know that. [...]
 Little things like failing to check for overflow. (eg, a-b can overflow if a
is 
 large and positive, and b is large and negative). Sometimes these errors are
not 
 present in the original Algol. Extremely poor performance for worst-case 
 situations. Mostly pretty obscure stuff.

Ciao Tom
Aug 01 2007