unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Daniel Llorens <daniel.llorens@bluewin.ch>
To: John Cowan <cowan@ccil.org>
Cc: guile-user <guile-user@gnu.org>, Matt Wette <matt.wette@gmail.com>
Subject: Re: Matrix or array operations library
Date: Sat, 29 Dec 2018 01:17:37 +0100	[thread overview]
Message-ID: <2D1247B3-4B56-45C3-9AC4-5EA5E1B0858B@bluewin.ch> (raw)
In-Reply-To: <CAD2gp_QNTymH4d8nVJ4s5Jzc61YjCLHDy=tyiJ_rpAwCbJTOyw@mail.gmail.com>



> On 29 Dec 2018, at 00:16, John Cowan <cowan@ccil.org> wrote:

> If array objects don't have an offset (the index in the backing store of the [0,0, ... 0] element), you can't do arbitrary translations, unfortunately.  If Guile doesn't have that, it should.

It does; I just forgot to mention it. make-shared-array accepts any affine function of indices. There's even a function to get at the offset directly  (shared-array-offset). All this is in the manual and has been in Guile for a long time.

> Layering a Guile compatibility mode over SRFI 122 might be a Good Thing.  Arrays there allow arbitrary affine transformations of the indices, provide lazy elementwise mapping (you can get eager mapping by composing mapping with copying), and have fast paths for arrays of up to 4 dimensions.  Read-only and read-write arrays defined by arbitrary getter and setter functions are also provided, and work exactly like storage-based arrays.  SRFI 122's only major limitation, which IMO is not a serious one, is that it doesn't handle 0-dimensional arrays (with one element) or degenerate arrays with non-positive dimensional ranges (with zero elements).  The code is in Gambit Scheme, but translating it to portable Scheme is an easy matter (I just haven't gotten around to it).  The main Gambit-specific dependency is define-macro (non-hygienic) macros, but nothing very bad is done with them.

Rank 0 arrays and empty arrays happen all the time if you work with arrays. I think it would be annoying to have to look out for special cases.

To be honest I find it strange that SRFI-122 doesn't support those you since you shouldn't need to do anything special (Guile supports them for free, other than a special case in the read syntax iirc). 

Guile only has the type and a few low level functions. My library guile-ploy provides arbitrary arity and arbitrary rank rank extension on top of Guile, plus a bunch of array functions, including full APL-style slicing. Still no lazy mapping, that would be nice to have. You probably want operator overloading as well.

One thing that is needed is a linear range generator of some kind, like a:b in Python. It's not enough to provide a procedure for this, since the slicing function must be able to recognize this linear range in order to avoid copying. For instance x[a:b], should produce another array with different strides, not a copy and not a lazy map either. In guile-ploy this is written (from x (range a b)), where (range a b) is a special type. In guile-newra this linear range is one of the basic vector types (along with vectors, bytevectors, and srfi-4 vectors). Does srfi-122 provide something like this? I suppose if you have lazy maps the linear range can be done with those and then the slicing function can be written to recognize it.

I shall try and have a look.

	Daniel


> There is a post-SRFI fork at https://github.com/gambiteer/srfi-122/ <https://github.com/gambiteer/srfi-122/> which will fairly soon become an updated SRFI.
> 
> -- 
> John Cowan          http://vrici.lojban.org/~cowan <http://vrici.lojban.org/~cowan>        cowan@ccil.org <mailto:cowan@ccil.org>
> Yakka foob mog.  Grug pubbawup zink wattoom gazork.  Chumble spuzz.
>     --Calvin, giving Newton's First Law "in his own words"
> 



  reply	other threads:[~2018-12-29  0:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.32929.1546007691.1283.guile-user@gnu.org>
2018-12-28 20:23 ` Matrix or array operations library Daniel Llorens
2018-12-28 23:16   ` John Cowan
2018-12-29  0:17     ` Daniel Llorens [this message]
2019-01-27 18:41       ` Matt Wette
2018-12-28 23:24   ` Matt Wette
     [not found] <mailman.108.1545930019.12294.guile-user@gnu.org>
2018-12-27 18:43 ` Daniel Llorens
2018-12-27 21:24   ` John Cowan
2018-12-27 22:24   ` Matt Wette
     [not found] <mailman.73.1545757221.8862.guile-user@gnu.org>
2018-12-26 11:38 ` Zelphir Kaltstahl
2018-12-27 14:20   ` Matt Wette
2018-12-27 14:38     ` Mike Gran
     [not found] <c2172031-a0a6-9dd3-6ceb-7b6d94648475@gmail.com>
2018-12-24 22:01 ` 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2D1247B3-4B56-45C3-9AC4-5EA5E1B0858B@bluewin.ch \
    --to=daniel.llorens@bluewin.ch \
    --cc=cowan@ccil.org \
    --cc=guile-user@gnu.org \
    --cc=matt.wette@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).