From: Noah Lavine <noah.b.lavine@gmail.com>
To: Daniel Llorens <daniel.llorens@bluewin.ch>
Cc: Andy Wingo <wingo@pobox.com>, guile-devel <guile-devel@gnu.org>
Subject: Re: propose deprecation of generalized-vector-*
Date: Thu, 21 Feb 2013 19:22:52 -0500 [thread overview]
Message-ID: <CA+U71=Pj1Ywr1Ay+w-u1jWd4ZZ8Xk1b27YEg-ME8JRVchYRuCA@mail.gmail.com> (raw)
In-Reply-To: <96617E9F-D83C-48EE-B84D-7CD45C4181C2@bluewin.ch>
[-- Attachment #1: Type: text/plain, Size: 5440 bytes --]
Hello,
On Wed, Feb 20, 2013 at 8:13 PM, Daniel Llorens
<daniel.llorens@bluewin.ch>wrote:
>
> On Feb 18, 2013, at 16:55, Andy Wingo wrote:
>
> > It could make sense, yes. What do others think? What happens for
> > array-set!? Care to propose a patch?
>
> Patch is attached. It looks a bit unwieldy because I am duplicating
> scm_array_handle_pos(), and I also had to fix the recent array_ref_1
> optimization, but it shouldn't be slower for the old use.
>
Thanks for working on this!
> ...
>
> ---
>
> It was interesting to read the other replies, thank you (plural). It was
> disappointing that nobody seems to be using arrays, but not very
> surprising. I use them a fair amount, but mostly for interfacing with
> C/C++. I do little with them in Guile since 1) the facilities are really
> not there or they are inconvenient to use, 2) when I need arrays I need
> speed and Guile isn't there either (yet!).
>
I agree about the speed issue, but I hope it will get better soon. The RTL
VM will fix some of it, and native compilation will fix more.
> More than getting this patch accepted (as it is or with different function
> names), my concern is that what this patch does cannot be done on the user
> side except through make-shared-array, which is too slow. So I think
> there's a good argument that scm_i_make_array(), SCM_I_ARRAY_V(),
> SCM_I_ARRAY_BASE() and SCM_I_ARRAY_DIMS() should be published.
>
> Now some optional motivation:
>
> In other languages that have arrays, rank-0 arrays are not differentiated
> from the scalar inside. This is the right approach if you want to treat
> arrays of any rank as values. Then you can say that a rank-n array is
>
> -------------------
> a rank-n array of rank-0 cells
> a rank-(n-1) array of rank-1 cells
> ...
> a rank-1 array of rank-(n-1) cells
> a rank-0 array of rank-n cells = a rank-n cell.
>
> Figure 1.
> -------------------
>
> The extended versions of array-ref and array-set! allow you to use a
> rank-n array as any of these.
>
I'm actually not very enthusiastic about this, not because you shouldn't be
able to do this, but because in order to enable the automatic de-ranking,
you have to have Guile assume which dimensions you want to map over. That's
how C, C++ and Fortran do it because that's how arrays are actually stored
in memory, so maybe that is the right way. It just seems too low-level for
me - I'd rather see an array-slice function that can split along any
dimensions.
> Old Guile used to have something called ‘enclosed arrays’, they are
> described in the 1.6 manual. This is a mechanism inspired by APL that
> allows one to split an array as in Figure 1, so that if you have a function
> that operates on rank-k arrays, you can array-map! it on arrays of any rank
> >= k.
>
> Example:
>
> (define A #((1 2) (3 4) (5 6))
> (define (sqr x) (* x x))
> (define (norm v) (+ (sqr (array-ref v 0)) (sqr (array-ref v 1))))
> (define out #(0 0 0))
> (array-map! out norm (enclosed-array A 1))
>
> out => #(5 25 61), hopefully (I don't have Guile 1.6 here to try).
>
> In later versions of APL (and most obviously in J) people realized that
> this is a bad way to go about things, since the reason you want to split A
> in rank-1 cells is ‘norm’. That is, rank-1 is a property of the function
> ‘norm’. And you don't need to do any conversions to iterate over the rank-1
> cells of A; you only need to move a pointer on each iteration, but to do
> this array-map! should be aware of the rank of the procedure in each of its
> arguments.
>
This gets at the heart of my issue with the array functionality. As far as
I can tell, in Guile, there is no way to figure out what the rank of a
function is. That's why you have to be explicit about what you're mapping
over.
I suppose the Common Lisp-y approach would be to make an object property
called 'rank', set it for all of the built-in arithmetic functions, and
maybe have some way to infer the rank of new functions That might be
interesting, but I'm skeptical.
> ...
>
> Finally, to fuel the discussion of what kind of array operations Guile
> should provide, here is a list similar things that I have read about. I
> imagine there are many more. The software is all open source.
>
> ...
>
Thanks a lot for starting the conversation. I would like to see Guile
provide enough array functionality for serious scientific computing, and it
sounds like you want the same thing. I don't really know what's missing
yet, though, because I haven't tried to write a program that would use it.
I think the idea of splitting arrays is great. My only concern is making it
part of array-ref. I still think that's a really bad idea, because it
introduces a new class of errors that are really easy to make -
accidentally getting an array when you expected whatever was inside the
array. I'm coming at this as a user of Matlab and Fortran. In those
languages, this isn't a problem, because operations automatically map over
arrays, so having an array where you expected a value doesn't lead to new
errors. But in Scheme, operations *don't* automatically map, so getting an
array could lead to an exception at some point later in a program when
really the error was that you didn't give enough indices to array-ref.
Other than that, I'm excited about having this.
Best,
Noah
[-- Attachment #2: Type: text/html, Size: 6680 bytes --]
next prev parent reply other threads:[~2013-02-22 0:22 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.153.1351958430.10005.guile-devel@gnu.org>
2012-11-03 16:52 ` propose deprecation of generalized-vector-* Daniel Llorens
2012-11-03 21:10 ` Ludovic Courtès
2013-01-21 16:11 ` Andy Wingo
2013-01-22 14:31 ` Daniel Llorens
2013-01-22 18:31 ` Daniel Llorens
2013-01-22 20:52 ` Andy Wingo
2013-01-22 23:27 ` Daniel Llorens
2013-01-23 9:20 ` Andy Wingo
2013-01-23 14:55 ` Ludovic Courtès
2013-01-23 9:06 ` Andy Wingo
2013-01-23 12:20 ` Daniel Llorens
2013-02-18 15:55 ` Andy Wingo
2013-02-18 16:05 ` Noah Lavine
2013-02-18 16:25 ` Mike Gran
2013-02-18 16:29 ` Noah Lavine
2013-02-18 17:11 ` David Pirotte
2013-02-18 17:17 ` Mike Gran
2013-02-18 23:57 ` Daniel Hartwig
2013-02-18 23:12 ` Problems with 'number->string' (was Re: propose deprecation of generalized-vector-*) Mark H Weaver
2013-02-21 1:13 ` propose deprecation of generalized-vector-* Daniel Llorens
2013-02-22 0:22 ` Noah Lavine [this message]
2013-02-28 19:10 ` Daniel Llorens
2013-03-01 2:42 ` Noah Lavine
2013-03-01 3:46 ` Noah Lavine
2013-03-01 9:01 ` Daniel Llorens
2013-03-01 9:44 ` Andy Wingo
2013-03-04 2:27 ` Noah Lavine
2013-03-08 23:42 ` array operations Daniel Llorens
2013-02-18 15:40 ` propose deprecation of generalized-vector-* Andy Wingo
2013-02-28 23:04 Nelson H. F. Beebe
2013-03-04 12:48 ` Aharon Robbins
[not found] <mailman.191.1348070449.18828.guile-devel@gnu.org>
2012-09-19 17:20 ` Daniel Llorens
-- strict thread matches above, loose matches on Subject: below --
2012-09-18 14:49 Daniel Llorens
2012-09-19 12:02 ` Peter TB Brett
2012-11-02 23:27 ` Ludovic Courtès
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='CA+U71=Pj1Ywr1Ay+w-u1jWd4ZZ8Xk1b27YEg-ME8JRVchYRuCA@mail.gmail.com' \
--to=noah.b.lavine@gmail.com \
--cc=daniel.llorens@bluewin.ch \
--cc=guile-devel@gnu.org \
--cc=wingo@pobox.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).