[plt-scheme] Re: More PLT Scheme as an Alternative to Matlab

From: hendrik at topoi.pooq.com (hendrik at topoi.pooq.com)
Date: Sat Aug 15 18:23:33 EDT 2009

On Sat, Aug 15, 2009 at 10:14:36AM -0600, Doug Williams wrote:
> 
> One thing that always frustrated me about NumPy is that you don't
> > really know whether you've gotten a copy or a view for many
> > operations.  Sometimes it is safe to modify the copy, but other times
> > you're trashing the original data in a view, and the same piece of
> > code can do either based on runtime arguments to the function you're
> > calling.  I believe one correct thing to do is to implement copy-on-
> > write for any shape changing operation, but that's trickier.  Treating
> > arrays as immutable is attractive (especially in a functional
> > programming language), and an efficient implementation for that is
> > probably even more complicated.  Noel Welsh mentioned the SAC
> > language, and it looks like they would be a good place from which to
> > get ideas.
> 
> 
> I am leaning toward immutability, so it shouldn't matter if it is a copy or
> not.

Algol 68 dealt with this problem by having different types for arrays 
and array variables.  You could trim or slice array variables to get 
subarrays, and they were defined to share storage.  You could trim or 
slice array values, and they wold be immutable, just like the arrays 
being sliced.  Again, they could share storage, but since they were 
immutable, that would be an optimisation.  There was room for 
considerable ingenuity in the compiler to avoid unnecessary copies when 
looking at a value obtained by dereferencing a variable.

> 
> Another frustrating thing in NumPy is the topic of zero-dimensional
> > arrays (scalars) and how they integrate with the rest of the language
> > and libraries.  Does subscripting an N-dimensional array by N
> > subscripts give you a Scheme numeric value, or a zero dimensional
> > array?  If it's a standard Scheme value, can you broadcast (or "new
> > axis") a Scheme scalar value back to an array.  Will it change it's
> > type when you do this?  Can you subscript with zero subscripts?

I suppose that's syntactically possible.  Is it useful?  Does it lead to 
simplifying generalisations?

> 
> My current implementation has a schizophrenic array-ref, if a reference is
> fully qualified (i.e., values specified for all the dimensions), it returns
> a Scheme scalar value, otherwise it returns a new array object to the
> referenced subarray (slice). It subarray shares the parent array's data if
> possible, otherwise a new data vector is made for the subarray. I will use
> broadcasting - so a scalar can look like any shape array.
...
> As a library, I can't control the Scheme side of things. [But, I've found
> the PLT Scheme implementators like to do the 'right thing' and they do
> listen.] So, comprimises at the boundary of the array collection and Scheme
> will be required.
> 
> (As a silly style suggestion, I think you should call your complex
> > floating point types cf32 and cf64 instead of c64 and c128.)

There are mathematicians who do number theory with complex integers.  
They'd want the ci types.  They'd probably want the unbounded versions 
of these, too.

PL/I I'm told even implemented complex Sterling values, but that was 
probably going too far.  Although imaginary money may make sense in the 
current economic climate, I suspect the mathematics isn't the right one.

-- hendrik


Posted on the users mailing list.