[racket] Math library ready for testing

From: Neil Toronto (neil.toronto at gmail.com)
Date: Fri Dec 7 18:09:40 EST 2012

On 12/07/2012 03:14 PM, Hendrik Boom wrote:
> On Fri, Dec 07, 2012 at 01:33:22PM -0700, Neil Toronto wrote:
>>
>>    Also, I've been considering allowing negative axis numbers and row
>>    indexes. Need feedback on how helpful it would be vs. confusing and
>>    error-hiding.
>
> The last big matrix library I've been in any way associated with was
> Torrix, a library for Algol 68.  The convention that they used there was
> that matrices had infinitely many rows and columns, indexed by the
> integers, but that all but a finite number of entries were zero.  This
> operations on what the user thought of as 7x7 matrices acted as if they
> were infinite-extent matrices instead.  The difference came in the ease
> which which they could handle matrices of different sizes (even with
> different index origins) in a semantically simple way.  That apparently
> was appreciated by its users, though I might have considered some of
> these machinations to be usefully reported as type violations.

Oh, Typed Racket would never let us get away with that, except with the 
FlArray and FCArray subtypes. Unless every array somehow knew what its 
"default" or "zero" value was, or every (Array A) was actually an (Array 
(U Zero A)). The latter approach is truly icky, and I don't like the 
former much, either.

FWIW, the `flomap' type from `images/flomap' does this. With color 
components premultiplied by alpha, it makes all the image operations 
Just Work near the borders without treating them as special cases.

Anyway, I should have been more clear. Negative indexes would count 
backwards from the size of whatever they're indexing. For a 
5-dimensional array, axis number -1 would be the same as axis number 4. 
For an array with 10 rows, row -1 would be the same as row 9. It can be 
useful to write code that says, "Give me the last row; I don't care how 
many there are," or "fold over the second-to-last axis."

I'm more sold on doing this for axis numbers, but still waffling. It's 
an irreversible decision. For row indexes, it matches perfectly with 
permissive broadcasting rules, but those aren't the default rules.

Neil ⊥


Posted on the users mailing list.