unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Integrate Guile with GNU Scientific Library
@ 2019-10-03  7:28 Freeduck via General Guile related discussions
  2019-10-04  1:10 ` Matt Wette
  0 siblings, 1 reply; 5+ messages in thread
From: Freeduck via General Guile related discussions @ 2019-10-03  7:28 UTC (permalink / raw)
  To: guile-user@gnu.org

Hi All,

I am trying to integrate Guile with a part of GNU Scientific Library and have found SWIG, which seems very easy to use, but only supports Guile 2.0. I have Guile 2.2 installed.
The Guile homepage has a tutorial on integrating Guile into C, and the manual has a section on dynamic ffi, but it I find it hard to get started, maybe it is just lack of experience.

My main problem is not integrating with GSL, but doing polynomial regression. I have been working in Racket for a while which has allot of maths integrated. Is there something like numpy/scipy for Guile.

Kind regards

Kristian

Sent with [ProtonMail](https://protonmail.com) Secure Email.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Integrate Guile with GNU Scientific Library
  2019-10-03  7:28 Integrate Guile with GNU Scientific Library Freeduck via General Guile related discussions
@ 2019-10-04  1:10 ` Matt Wette
  2019-10-04 14:32   ` Unknown
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Matt Wette @ 2019-10-04  1:10 UTC (permalink / raw)
  To: guile-user

On 10/3/19 12:28 AM, Freeduck via General Guile related discussions wrote:
> Hi All,
>
> I am trying to integrate Guile with a part of GNU Scientific Library and have found SWIG, which seems very easy to use, but only supports Guile 2.0. I have Guile 2.2 installed.
> The Guile homepage has a tutorial on integrating Guile into C, and the manual has a section on dynamic ffi, but it I find it hard to get started, maybe it is just lack of experience.
>
> My main problem is not integrating with GSL, but doing polynomial regression. I have been working in Racket for a while which has allot of maths integrated. Is there something like numpy/scipy for Guile.
>
> Kind regards
>
> Kristian
>
> Sent with [ProtonMail](https://protonmail.com) Secure Email.
The FFI Helper in nyacc (https://savannah.nongnu.org/projects/nyacc) 
provides the functionality of swig.  You can try that.  I'd be 
interested in how you like that compared to swig.

A quick hack to see if I could get it to work for gsl failed:

$ cat gsl-sort.ffi
(define-ffi-module (gsl-sort)
   #:pkg-config "gsl"
   #:include '("gsl/gsl_sort.h"))
$ guild compile-ffi gsl-sort.ffi
...
ERROR: In procedure dynamic-link:
In procedure dynamic-link: file: "libm", message: "file not found"

So for some reason the linker is not finding libm.so on my Unbuntu.
I will need to look into that.

You can check the examples in examples/nyacc/lang/ffi-help.






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Integrate Guile with GNU Scientific Library
  2019-10-04  1:10 ` Matt Wette
@ 2019-10-04 14:32   ` Unknown
  2019-10-04 22:41   ` Matt Wette
  2019-10-05 16:55   ` (dynamic-link "libm") fails [was Re: Integrate Guile with GNU Scientific Library] Matt Wette
  2 siblings, 0 replies; 5+ messages in thread
From: Unknown @ 2019-10-04 14:32 UTC (permalink / raw)
  To: matt.wette, guile-user

On 4 Oct 2019, 03:10, Matt Wette < matt.wette@gmail.com> wrote:

On 10/3/19 12:28 AM, Freeduck via General Guile related discussions wrote:

> Hi All,

>

> I am trying to integrate Guile with a part of GNU Scientific Library and have found SWIG, which seems very easy to use, but only supports Guile 2.0. I have Guile 2.2 installed.

> The Guile homepage has a tutorial on integrating Guile into C, and the manual has a section on dynamic ffi, but it I find it hard to get started, maybe it is just lack of experience.

>

> My main problem is not integrating with GSL, but doing polynomial regression. I have been working in Racket for a while which has allot of maths integrated. Is there something like numpy/scipy for Guile.

>

> Kind regards

>

> Kristian

>

> Sent with [ProtonMail](https://protonmail.com) Secure Email.

The FFI Helper in nyacc (https://savannah.nongnu.org/projects/nyacc)

provides the functionality of swig.  You can try that.  I'd be

interested in how you like that compared to swig.

A quick hack to see if I could get it to work for gsl failed:

$ cat gsl-sort.ffi

(define-ffi-module (gsl-sort)

  #:pkg-config "gsl"

  #:include '("gsl/gsl_sort.h"))

$ guild compile-ffi gsl-sort.ffi

...

ERROR: In procedure dynamic-link:

In procedure dynamic-link: file: "libm", message: "file not found"

So for some reason the linker is not finding libm.so on my Unbuntu.

I will need to look into that.

You can check the examples in examples/nyacc/lang/ffi-help.

First, sorry if I'm messing up bottom posting and formatting ... I'm responding using a non-free mobile phone app :)

Second, the answer might be totally off-topic, but I always found it easier to generate math programs by Guile and then compile them, then a full, seamless library level integration into a Guile program itself. See, e.g.

https://gitlab.com/codetk/schemetran

for a naive implementation of fortran wrappers and compiler helpers in Guile. It is naive, but I managed to do a lot of sophisticated linear algebra with it.

Anyway, good luck :) .

T

PS also in mine previous experiences when trying to link stuff using ffi, looking at the symbols in libraries directly helped.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Integrate Guile with GNU Scientific Library
  2019-10-04  1:10 ` Matt Wette
  2019-10-04 14:32   ` Unknown
@ 2019-10-04 22:41   ` Matt Wette
  2019-10-05 16:55   ` (dynamic-link "libm") fails [was Re: Integrate Guile with GNU Scientific Library] Matt Wette
  2 siblings, 0 replies; 5+ messages in thread
From: Matt Wette @ 2019-10-04 22:41 UTC (permalink / raw)
  To: guile-user



On 10/3/19 6:10 PM, Matt Wette wrote:
> The FFI Helper in nyacc (https://savannah.nongnu.org/projects/nyacc) 
> provides the functionality of swig.  You can try that.  I'd be 
> interested in how you like that compared to swig.
>

I found cpp-defs may be necessary for gsl:

(define-ffi-module (gsl-multifit)
   #:pkg-config "gsl"
   #:cpp-defs '("_Float128=long double")
   #:include '("gsl/gsl_multifit.h"))

I don't know where _Float128 comes from.  The "long double" is a guess.

Matt




^ permalink raw reply	[flat|nested] 5+ messages in thread

* (dynamic-link "libm") fails [was Re: Integrate Guile with GNU Scientific Library]
  2019-10-04  1:10 ` Matt Wette
  2019-10-04 14:32   ` Unknown
  2019-10-04 22:41   ` Matt Wette
@ 2019-10-05 16:55   ` Matt Wette
  2 siblings, 0 replies; 5+ messages in thread
From: Matt Wette @ 2019-10-05 16:55 UTC (permalink / raw)
  To: guile-user

   scheme@(guile-user)> (dynamic-link "libffi")
   $1 = #<dynamic-object "libffi">

   scheme@(guile-user)> (dynamic-link "libm")
   ERROR: In procedure dynamic-link:
   In procedure dynamic-link: file: "libm", message: "file not found"

Both libraries are linked into guile, so being already linked is not an 
issue.

However:

   mwette$ file /usr/lib/x86_64-linux-gnu/libm.so
/usr/lib/x86_64-linux-gnu/libm.so: ASCII text

mwette$ cat /usr/lib/x86_64-linux-gnu/libm.so
/* GNU ld script
*/
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib/x86_64-linux-gnu/libm.so.6  AS_NEEDED ( 
/usr/lib/x86_64-linux-gnu/libmvec_nonshared.a 
/lib/x86_64-linux-gnu/libmvec.so.1 ) )

This is an apparent redirection.   I think this is a bug (or feature) of 
dlopen:

   mwette$ cat z2.c
   #include <stdio.h>
   #include <dlfcn.h>

   int main() {
     void *p;

     p = dlopen("/usr/lib/x86_64-linux-gnu/libm.so", RTLD_NOW);
     printf("%p\n", p);
   }
   mwette$ gcc z2.c -ldl
   mwette$ ./a.out
   (nil)


Matt

On 10/3/19 6:10 PM, Matt Wette wrote:
> $ guild compile-ffi gsl-sort.ffi
> ...
> ERROR: In procedure dynamic-link:
> In procedure dynamic-link: file: "libm", message: "file not found"
>
> So for some reason the linker is not finding libm.so on my Unbuntu.
> I will need to look into that.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-05 16:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-03  7:28 Integrate Guile with GNU Scientific Library Freeduck via General Guile related discussions
2019-10-04  1:10 ` Matt Wette
2019-10-04 14:32   ` Unknown
2019-10-04 22:41   ` Matt Wette
2019-10-05 16:55   ` (dynamic-link "libm") fails [was Re: Integrate Guile with GNU Scientific Library] Matt Wette

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).