Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
BigBobio
May 1, 2009
So I actually program use APL at work. Once you get past the syntax and the special characters, its quite nice. Prototyping is a breeze

Also, as you could imagine, the user community is quite idiosyncratic.

Adbot
ADBOT LOVES YOU

BigBobio
May 1, 2009

Symbolic Butt posted:

I need help from someone more fluent in APL than I am lol

I've been looking up where the mathproglangy convention of treating the dot product as the same as matrix multiplication came from and it seems like APL was a big influence.

http://stackoverflow.com/questions/20424228/how-come-x-in-apl-works-for-both-matrices-and-vectors/20704876#20704876

So there's this answer and I wanted to know what part of the code corresponds to these 2 steps: "cut A into slices along its last axis, do the same with B along its first axis"

It looks like he skipped over how he broke up A and B each into a vector of vectors. It was with the enclose operations (the ⊂ commands on the first line). The [x] direct which axis of the matrix to do the enclose along. Although I'm not sure why he uses a zilde and a 1 for axes, it should be a 1 and a 2 (different flavor of APL maybe?)

BigBobio
May 1, 2009

Athas posted:

Congratulations on the job!

I've become involved in writing an APL compiler targeting GPU execution. As a result, I figured I should probably get some more experience with APL by itself. Is there a nice way to write stencils? Currently we do it by a mess of concatenations and transposes, for example here, for the core of a 2D stencil:

pre:
  iter ← {
    temp ← ⍵
    m1 ← (⍉1↓⍉temp),row 1⍴0
    m2 ← (row 1⍴0),⍉¯1↓⍉temp
    x ← (m1 + m2) - c1 × temp

    n1 ← ⍉(⍉1↓temp),col⍴0
    n2 ← ⍉(col⍴0),⍉¯1↓temp
    y ← (n1 + n2) - c2 × temp

    delta ← (step ÷ Cap) × (power + (y ÷ Ry) + (x ÷ Rx) + (amb_temp - temp) ÷ Rz)
    temp + delta
  }
Row, step, Cap and the like are constants. Everything interesting happens in the definitions of m1, m1, n1, and n2. What this code basically does is take the 2D-array temp, and for each of the four cardinal directions, split off a row/column, then add a row/column of zeroes on the opposite side. I think this code would be more concise and simpler in Python+Numpy, which is unusual. Maybe stencils just haven't been a priority for the domains where APL is usually applied? We managed to get this to run pretty fast, but I don't much like the way it looks.

Two things i noticed:
-You can use the [x] modifier on ↓ (e.g. ↓[1] and ↓[2]) to control whether you drop the first row or column from the matrix, instead of doing all those transpose operations.↓[1] will drop by rows, and ↓[2] by columns
-If you're appending a row or column that is a single value to a matrix, you don't need to add it as a vector. You just need to concatenate the value of interest with the matrix using the , function (and again, you can control whether you append as a row or column by using the [x] modifier on ,). So, matrix,0 will add a whole column of zeros to the right of the matrix, and 0,matrix will add it to the left.

No idea if this will make it faster, but it will be easier to read.

  • Locked thread