unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Matrix or array operations library
       [not found] <c2172031-a0a6-9dd3-6ceb-7b6d94648475@gmail.com>
@ 2018-12-24 22:01 ` Zelphir Kaltstahl
  2018-12-24 23:06   ` Tk
                     ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Zelphir Kaltstahl @ 2018-12-24 22:01 UTC (permalink / raw)
  To: Guile User

Hello Guile Users,

Is there some library, that enables high performance matrix operations
or even n-dimensional array operations? I am thinking of something like
NumPy in the Python ecosystem. I think NumPy in turn also uses some
lower level thing to do what it does. I think OpenBLAS or MKL, depending
on the architecture. I wonder if there is any wrapper around OpenBLAS
for Guile or something similar.

I am writing a little code for matrix operations and currently I am
using Guile arrays, as they are made of vectors and have constant access
time, which is already great. My guess is, that this would be the right
choice if using pure Guile. I am writing data abstraction procedures, so
that later on I could exchange what is used to represent the data.

Maybe, if there is something like NumPy or lower level, I should use
that instead? (Would I have to learn how to use FFI first?)

Or maybe Guile's implementation is already so fast, that it would not
make that much difference to use a lower level thing?

Currently I have only a little experimental program, started today, so
no huge plan. OK, one can fantasize about stuff like Pandas data frames
in Guile, but I have no illusion, that it is a work of a few days or
even weeks. It would be nice to learn, how to use a low level thing or
maybe even Pandas, if there are any such bindings for Guile. I could
make the implementation use different representations, depending on a
parameter or something like that.

Regards,

Zelphir




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

* Re: Matrix or array operations library
  2018-12-24 22:01 ` Matrix or array operations library Zelphir Kaltstahl
@ 2018-12-24 23:06   ` Tk
  2018-12-25  0:21   ` Matt Wette
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Tk @ 2018-12-24 23:06 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: guile-user@gnu.org

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Monday, 24 December 2018 23:01, Zelphir Kaltstahl <zelphirkaltstahl@gmail.com> wrote:

> Hello Guile Users,
>
> Is there some library, that enables high performance matrix operations
> or even n-dimensional array operations? I am thinking of something like
> NumPy in the Python ecosystem. I think NumPy in turn also uses some
> lower level thing to do what it does. I think OpenBLAS or MKL, depending
> on the architecture. I wonder if there is any wrapper around OpenBLAS
> for Guile or something similar.
>
> I am writing a little code for matrix operations and currently I am
> using Guile arrays, as they are made of vectors and have constant access
> time, which is already great. My guess is, that this would be the right
> choice if using pure Guile. I am writing data abstraction procedures, so
> that later on I could exchange what is used to represent the data.
>
> Maybe, if there is something like NumPy or lower level, I should use
> that instead? (Would I have to learn how to use FFI first?)
>
> Or maybe Guile's implementation is already so fast, that it would not
> make that much difference to use a lower level thing?
>
> Currently I have only a little experimental program, started today, so
> no huge plan. OK, one can fantasize about stuff like Pandas data frames
> in Guile, but I have no illusion, that it is a work of a few days or
> even weeks. It would be nice to learn, how to use a low level thing or
> maybe even Pandas, if there are any such bindings for Guile. I could
> make the implementation use different representations, depending on a
> parameter or something like that.
>
> Regards,
>
> Zelphir


I took a different route. Instead of merely binding functionality in a lower level language, I use Guile to generate lean-and-mean modern Fortran code. The building blocks can be found here: https://gitlab.com/codetk/schemetran (wanted to save this for potluck, but here it goes ... ). Fortran compilers take care of efficient execution on HPC platforms. Actually, it is beyond me why anyone would bother with any other programming language when it comes to expressing maths efficiently.

I built a pseudo-spectral Navier-stokes solver that can work on MPI, shared-mem (OpenMP), and hopefully soon GPU/Xeon accelerators (OpenMP 4) atop of schemetran. I still need to see about publishing it under an Libre licence.







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

* Re: Matrix or array operations library
  2018-12-24 22:01 ` Matrix or array operations library Zelphir Kaltstahl
  2018-12-24 23:06   ` Tk
@ 2018-12-25  0:21   ` Matt Wette
  2018-12-25  0:32     ` ndarray [was: Matrix or array operations library] Matt Wette
  2018-12-25 17:12   ` Matrix or array operations library David Pirotte
  2019-06-02 21:44   ` Linas Vepstas
  3 siblings, 1 reply; 6+ messages in thread
From: Matt Wette @ 2018-12-25  0:21 UTC (permalink / raw)
  To: guile-user

On 12/24/18 2:01 PM, Zelphir Kaltstahl wrote:

> Hello Guile Users,
>
> Is there some library, that enables high performance matrix operations
> or even n-dimensional array operations? I am thinking of something like
> NumPy in the Python ecosystem. I think NumPy in turn also uses some
> lower level thing to do what it does. I think OpenBLAS or MKL, depending
> on the architecture. I wonder if there is any wrapper around OpenBLAS
> for Guile or something similar.
>
> I am writing a little code for matrix operations and currently I am
> using Guile arrays, as they are made of vectors and have constant access
> time, which is already great. My guess is, that this would be the right
> choice if using pure Guile. I am writing data abstraction procedures, so
> that later on I could exchange what is used to represent the data.
>
> Maybe, if there is something like NumPy or lower level, I should use
> that instead? (Would I have to learn how to use FFI first?)
>
> Or maybe Guile's implementation is already so fast, that it would not
> make that much difference to use a lower level thing?
>
> Currently I have only a little experimental program, started today, so
> no huge plan. OK, one can fantasize about stuff like Pandas data frames
> in Guile, but I have no illusion, that it is a work of a few days or
> even weeks. It would be nice to learn, how to use a low level thing or
> maybe even Pandas, if there are any such bindings for Guile. I could
> make the implementation use different representations, depending on a
> parameter or something like that.
>
> Regards,
>
> Zelphir
>
IMO, Guile probably needs something like ndarray, the base for numpy,
if matrix operations are going to go anywhere.

As far as using blas or others, I have developed a package for helping
to use the FFI API for C libraries.  It may be of interest to you.

ffi-helper: https://www.nongnu.org/nyacc/ffi-help.html

Matt




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

* ndarray [was: Matrix or array operations library]
  2018-12-25  0:21   ` Matt Wette
@ 2018-12-25  0:32     ` Matt Wette
  0 siblings, 0 replies; 6+ messages in thread
From: Matt Wette @ 2018-12-25  0:32 UTC (permalink / raw)
  To: guile-user

On 12/24/18 4:21 PM, Matt Wette wrote:

> IMO, Guile probably needs something like ndarray, the base for numpy,
> if matrix operations are going to go anywhere.

https://docs.scipy.org/doc/numpy-1.13.0/reference/internals.html





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

* Re: Matrix or array operations library
  2018-12-24 22:01 ` Matrix or array operations library Zelphir Kaltstahl
  2018-12-24 23:06   ` Tk
  2018-12-25  0:21   ` Matt Wette
@ 2018-12-25 17:12   ` David Pirotte
  2019-06-02 21:44   ` Linas Vepstas
  3 siblings, 0 replies; 6+ messages in thread
From: David Pirotte @ 2018-12-25 17:12 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: Guile User

[-- Attachment #1: Type: text/plain, Size: 1479 bytes --]

Hello,

> Is there some library, that enables high performance matrix operations
> or even n-dimensional array operations? I am thinking of something like
> NumPy in the Python ecosystem. I think NumPy in turn also uses some
> lower level thing to do what it does. I think OpenBLAS or MKL, depending
> on the architecture. I wonder if there is any wrapper around OpenBLAS
> for Guile or something similar.
> ...

There are quite a few libs you might look at before you start to code your own:

	https://notabug.org/lloda
		...
		guile-newra
		guile-ffi-cblas
		...
		guile-ploy
		...

	AIscm
	http://wedesoft.github.io/aiscm

I also wrote a set of n-dim array math ops (including matrix ops) for Guile-CV:

	https://www.gnu.org/software/guile-cv/
		the manual is available online, math and matrix ops are described in
		the 'Processing' section

	mentioning Guile-CV because images are just a collection of n-dim arrays.
	(see 'Image Structure and Accessors' in the manual).

	in Guile-CV, all (almost all) arrays are f32vectors - see (srfi srfi-4) in
	the Guile manual - math and matrix ops are written in C (but memory
	allocation entirely kept in scheme). multi channel ops are multi-threaded

	some of these math and matrix ops also work on s32 and f64 (undocumented so
	far): it would not take much to actually fully generalize all guile-cv math
	and matrix ops for the full set of (srfi srfi-4 ) types.

Cheers,
David




	


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: Matrix or array operations library
  2018-12-24 22:01 ` Matrix or array operations library Zelphir Kaltstahl
                     ` (2 preceding siblings ...)
  2018-12-25 17:12   ` Matrix or array operations library David Pirotte
@ 2019-06-02 21:44   ` Linas Vepstas
  3 siblings, 0 replies; 6+ messages in thread
From: Linas Vepstas @ 2019-06-02 21:44 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: Guile User

Me too.

With one significant difference: I have extremely sparse arrays. Like, only
one-in-a-million array entries are non-zero.  And my arrays are hug -- say
2M by 2M, for a total of 4 tera-entries, of which only one in a million are
non-zero, so in fact, my data might fit in a gigabyte or less. (instead of
32 terabytes of RAM)

I solved this by writing my own ad-hoc library. The library user needs to
declare a half-dozen methods, indicating how to fetch the matrix entries,
what the dimensions of the array are, and methods to loop over the non-zero
row and column entries.  The library does the rest.

My code is quasi-special-purpose, and, well, just right for me, but a
serious dedicated library programmer could do a much better job than I
can.  My code is here:

https://github.com/opencog/atomspace/tree/master/opencog/matrix

The low-level API that the user must declare is here:
https://github.com/opencog/atomspace/blob/master/opencog/matrix/object-api.scm

Hmm, maybe I should pull this out of the project, and make it generic....

-- Linas


On Mon, Dec 24, 2018 at 4:01 PM Zelphir Kaltstahl <
zelphirkaltstahl@gmail.com> wrote:

> Hello Guile Users,
>
> Is there some library, that enables high performance matrix operations
> or even n-dimensional array operations? I am thinking of something like
> NumPy in the Python ecosystem. I think NumPy in turn also uses some
> lower level thing to do what it does. I think OpenBLAS or MKL, depending
> on the architecture. I wonder if there is any wrapper around OpenBLAS
> for Guile or something similar.
>
> I am writing a little code for matrix operations and currently I am
> using Guile arrays, as they are made of vectors and have constant access
> time, which is already great. My guess is, that this would be the right
> choice if using pure Guile. I am writing data abstraction procedures, so
> that later on I could exchange what is used to represent the data.
>
> Maybe, if there is something like NumPy or lower level, I should use
> that instead? (Would I have to learn how to use FFI first?)
>
> Or maybe Guile's implementation is already so fast, that it would not
> make that much difference to use a lower level thing?
>
> Currently I have only a little experimental program, started today, so
> no huge plan. OK, one can fantasize about stuff like Pandas data frames
> in Guile, but I have no illusion, that it is a work of a few days or
> even weeks. It would be nice to learn, how to use a low level thing or
> maybe even Pandas, if there are any such bindings for Guile. I could
> make the implementation use different representations, depending on a
> parameter or something like that.
>
> Regards,
>
> Zelphir
>
>
>

-- 
cassette tapes - analog TV - film cameras - you


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

end of thread, other threads:[~2019-06-02 21:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <c2172031-a0a6-9dd3-6ceb-7b6d94648475@gmail.com>
2018-12-24 22:01 ` Matrix or array operations library Zelphir Kaltstahl
2018-12-24 23:06   ` Tk
2018-12-25  0:21   ` Matt Wette
2018-12-25  0:32     ` ndarray [was: Matrix or array operations library] Matt Wette
2018-12-25 17:12   ` Matrix or array operations library David Pirotte
2019-06-02 21:44   ` Linas Vepstas

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).