[sac-user] Fwd: [sac-devel] Cartesian products in SAC

Sven-Bodo Scholz S.Scholz at herts.ac.uk
Fri Dec 2 18:12:51 CET 2005

I think this email belongs into sac-user 
rather than sac-devel....

----- Forwarded message from Robert Bernecky <bernecky at rogers.com> -----

Envelope-to: comqss at tucana.herts.ac.uk
Delivery-date: Thu, 01 Dec 2005 23:33:43 +0000
Delivered-To: sbs at sac-home.org
X-Original-To: sac-devel at sac-home.org
Delivered-To: sac-devel at sac-home.org
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=rogers.com;
Date: Thu, 1 Dec 2005 18:30:00 -0500 (EST)
From: Robert Bernecky <bernecky at rogers.com>
X-X-Sender: rbe at rattler.snakeisland.com
To: sac-devel at sac-home.org
Reply_to: "Robert Bernecky" <bernecky at acm.org>
X-Envelope-To: sac-devel at sac-home.org
Subject: [sac-devel] Cartesian products in SAC
X-BeenThere: sac-devel at sac-home.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: sac developer mailing list <sac-devel.sac-home.org>
List-Unsubscribe: <http://www.sac-home.org/mailman/listinfo/sac-devel>,
	<mailto:sac-devel-request at sac-home.org?subject=unsubscribe>
List-Archive: <http://www.sac-home.org/pipermail/sac-devel>
List-Post: <mailto:sac-devel at sac-home.org>
List-Help: <mailto:sac-devel-request at sac-home.org?subject=help>
List-Subscribe: <http://www.sac-home.org/mailman/listinfo/sac-devel>,
	<mailto:sac-devel-request at sac-home.org?subject=subscribe>
Errors-To: sac-devel-bounces at sac-home.org
X-H-UH-MailScanner: No Virus detected
X-UH-MailScanner-From: sac-devel-bounces at sac-home.org
X-UH-MailScanner-Information: UH-mail
X-UH-MailScanner: No Virus detected

I have an interesting problem, and am looking for
spiffy ideas on how to solve it:

The problem is that of "dyadic transpose" in APL,
which does more than it really should:

 - It provides a way to permute array axes, as
   a general transpose. For example,
   the transpose([2,0,1,3], genarray([2,3,4,5],6))
   produces a result of shape [3,4,2,5].
 - It provides a general "main diagonal" capability
   if you include duplicates in the left argument.
   For example transpose([0,0], rank2matrix) gives
   the main diagonal vector. On the above example,
   the result of a [2 0 0 1] transpose would be an
   array of shape [3,5,2]: axes 1 and 2 would
   be collapsed into a single axis.

A bit of analyzis on the left argument value and
right argument shape yields two vectors:

   - result shape
   - index steps.

Successive pairs of elements form a nest of FOR
loops, e.g:

    result shape: [3,4,2.5]
    steps: [20, 5, 60, 1]

The actual work can be viewed as a nest of FOR loops:
   for i    in 20*iota 3
    for j   in 5 *iota 4
     for k  in 60*iota 2
      for L in  1*iota 5
       z[...] = ravel(rightargument)[i+j+k+L];

It can also be viewed as a Cartesian product:

  (20*iota 3)outerproduct+ (5*iota 4) outerproduct+
  (60*iota 2)outerproduct+ (1*iota 5)

where outerproduct+(x,y) is an array of
shape ((shape(x)++shape(y)), composed of

How do I express this nicely in SAC?
And, how do I express it nicely in SAC when I don't know
the shape of the above result shape and index steps
vectors until run-time?

I can flatten the nested loops into a nasty sort of single loop, with
end-of-innermore loop index corrections, but I'd rather not, if
someone has a nicer way to do it.

sac-devel mailing list
sac-devel at sac-home.org

----- End forwarded message -----

More information about the sac-user mailing list