Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Nested Index Assignments

10 views
Skip to first unread message

Aaron W. Hsu

unread,
Jan 18, 2012, 2:47:48 PM1/18/12
to
I have a data structure problem that I think I need some help on.

The goal is to have an abstraction for N arbitrarily but statically shaped
growable arrays. These arrays are in D. The Shapes of the arrays are in
Ds. I have a series of flags for each cell of the arrays Z which is a
boolean mask on D. I then have a set of data X that maps to arbitrary
cells in D. Xi should represent the mapping indexes that indicate what
cells X maps onto in D.

I have three basic operations that I need to perform here. The first is to
recognize all the flags for a given mapping Xi are set in Z. The second is
to optionally resize the arrays Z and D only if necessary based on the
mapping Xi. The third is to assign X to the cells mapped by Xi.

Right now I was thinking of initializing D and Z something like this:

Ds←(3 3) (4 4) (5 5)
D←Ds⍴¨⊂⍬
Z←Ds⍴¨0

Next, Let's say that I want to make a diagonal boolean matrix out of the
first and third matrices, but leave the second matrix alone. I could do
this manually:

{(1 ⍵⊃D)←1}¨(1 1) (2 2) (3 3)
...

But this is nasty and complex. Moreover, with a normal matrix I could just
do something like:

A[(1 1) (2 2) (3 3)]←1

However, I cannot do this using Pick (⊃).

Then, if I want to inconsiderately resize all arrays, I could do something
like this:

D[⊃¨Xi]←(⌈/¨¨1↓¨Xi)↑¨D[⊃¨Xi]

Or at least, that's the general idea. This leads to a format of Xi to
something like:

Xi←(((I ...) (I ...)) ...)

At least, if we were to use the standard ⌷ format for the inner indexes.
But obviously this combination of formats doesn't work well at all for Xi
or for doing indexed assignments, because I can't find a way to do the
equivalent of this:

D[1]
0 0 0
0 0 0
0 0 0
⎕←D[(1 ((1 3) 2))]←1
0 1 0
0 0 0
0 1 0

I wonder if someone here has some ideas about how this all might work? In
general, given that I am flexible on the whole thing, I want to be able to
do something like this:

D
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
D⊣D STORE ((1 ((1 1) (2 2) (3 3))) (2 (1,⍳3))) 1
1 0 0 0 0 0 0 1 0
0 1 0 0 0 0 0 1 0
0 0 1 0 0 0 0 1 0

I'd like to be able to be as flexible in specifying the indexes as I am
able to be normally with Index (⌷) and with Bracket indexing of various
forms.




--
Aaron W. Hsu | arc...@sacrideo.us | http://www.sacrideo.us
לֵ֤ב חֲכָמִים֙ בְּבֵ֣ית אֵ֔בֶל וְלֵ֥ב כְּסִילִ֖ים בְּבֵ֥ית שִׂמְחָֽה

Graham

unread,
Jan 19, 2012, 8:18:22 AM1/19/12
to

"Aaron W. Hsu" <arc...@sacrideo.us> wrote in message news:op.v8ao9yl80p3ku8@localhost...
I have a data structure problem that I think I need some help on.

[snip]
D⊣D STORE ((1 ((1 1) (2 2) (3 3))) (2 (1,⍳3))) 1
1 0 0 0 0 0 0 1 0
0 1 0 0 0 0 0 1 0
0 0 1 0 0 0 0 1 0

I'd like to be able to be as flexible in specifying the indexes as I am
able to be normally with Index (⌷) and with Bracket indexing of various
forms.
.........................................................................

At least in APL+WIN each element in a nested array is effectively stored sequentially in a vector of pointers. You could try using this property to recast your index system similarly and then you could use selective assign to accomplish your goal. The line below gives your result above but using sequential indices together with the enlist operator. I have also used those index values instead of ones to illustrate their position within your nested arrays:

(((⍳27)∊1 5 9 22 24 26)/∊D)←1 5 9 22 24 26

1 0 0 0 0 0 0 22 0
0 5 0 0 0 0 0 24 0
0 0 9 0 0 0 0 26 0

Graham.

Aaron W. Hsu

unread,
Jan 19, 2012, 2:04:48 PM1/19/12
to
On Thu, 19 Jan 2012 08:18:22 -0500, Graham
<h2gt2g42-mi...@yahoo.co.uk> wrote:

> The line below gives your result above but using sequential indices
> together with the enlist operator.

This is an interesting technique, and I think it will help me play with
things. Unfortunately, enlist (∊) is not supported as part of selective
assignment in Dyalog I think, nor APLX, IIRC. However, the general idea
helps a lot.

Graham

unread,
Jan 19, 2012, 2:22:42 PM1/19/12
to

"Aaron W. Hsu" <arc...@sacrideo.us> wrote in message news:op.v8chyawz0p3ku8@localhost...
> On Thu, 19 Jan 2012 08:18:22 -0500, Graham
> <h2gt2g42-mi...@yahoo.co.uk> wrote:
>
>> The line below gives your result above but using sequential indices
>> together with the enlist operator.
>
> This is an interesting technique, and I think it will help me play with
> things. Unfortunately, enlist (∊) is not supported as part of selective
> assignment in Dyalog I think, nor APLX, IIRC. However, the general idea
> helps a lot.

If that is the case then you should be able to simulate selective assignment with a function something like:

r←x Store d;ds
ds←⍴¨d
r←∊d
r[x[1;]]←x[2;]
r←ds⍴¨((×/¨ds)/⍳⍴ds)⊂r

Where the first row of x are the sequential index positions and the second the data you wish to put in those positions.

In my previous example:
x←2 6⍴1 5 9 22 24 26

and for your example:
x←2 6⍴1 5 9 22 24 26 1 1 1 1 1 1

Graham.
0 new messages