Flattening a nested matrix

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

Re: Flattening a nested matrix

Postby Stu on Wed Jan 27, 2016 11:18 pm

The first example, where you tessellate the 4×6 array, is exactly what I wanted. Since in my case the original array and the tessellated array will always have identical contents, I don't have to worry about padding.

The solution is more complicated than I initially thought it would be, which is why I ask the experts on this forum.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: Flattening a nested matrix

Postby Stu on Sat Feb 20, 2016 7:06 pm

This function does exactly what I wanted; however, can the definition be modified so that it doesn't depend on ⎕ML?
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: Flattening a nested matrix

Postby Veli-Matti on Sat Feb 20, 2016 8:22 pm

The tessellate code's not []ML dependent, so it should work fine when using in the APL2 friendly environment, too (just leave the []ML part off).

<offtopic>
I personally detest seeing something like r c <- .. - it should _always_ be with parens: (r c) <-.. *sigh*
</offtopic>

-Veli-Matti
Veli-Matti
 
Posts: 56
Joined: Sat Nov 28, 2009 3:12 pm

Re: Flattening a nested matrix

Postby Stu on Sun Feb 21, 2016 3:24 am

I think the problem is that in some APL's monadic "↑" doesn't denote Mix. ⎕ML←0 guarantees that it does in Dyalog. Is there a way to simulate monadic "↑" that doesn't depend on Migration Level?
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: Flattening a nested matrix

Postby DanB|Dyalog on Sun Feb 21, 2016 2:01 pm

Monadic UP-arrow (↑) means Mix in ⎕ML 0 or 1.
1 is the default in Dyalog today.
If your application only contains utilities written by Dyalog you shouldn't have to worry about setting ⎕ML before using Mix.
OTOH if you think there could be ANYTHING changing ⎕ML you should account for that and e.g. use
Code: Select all
Mix←{⎕ML←1 ⋄ ↑⍵}

Unfortunately, there is no simple way around it.

⊃ is similar. It means (monadic) First or (dyadic) Pick. You can't get around the ⎕ML problem with First but you can work around some cases with Pick. I personally use 1⊃V instead of ⊃V if I know that ⎕ML may change, that V is a vector with at least one element and that ⎕IO is 1 (or I can use ⎕IO⊃V).
Like this, if ⎕ML is changed underfoot, the expression will still work.
DanB|Dyalog
 

Re: Flattening a nested matrix

Postby Phil Last on Sun Feb 21, 2016 10:54 pm

      mix←↑⍤0
mix←⊃⍤0
are both identical to
      mix←{⎕ML←0 ⋄ ↑⍵}
It works because both and merely disclose scalars in any migration level. f⍤0 applies f to the scalars in its argument. The required mix operation is being done as a tidy-up after the fact.

Not guaranteed to be quicker although I'm sure it could be made to be as quick.
User avatar
Phil Last
 
Posts: 557
Joined: Thu Jun 18, 2009 6:29 pm

Re: Flattening a nested matrix

Postby Phil Last on Mon Feb 22, 2016 10:50 am

Similarly
      first←⊃⍬∘⍴
first←↑⍬∘⍴
are both identical to
      first←{⎕ML←0 ⋄ ⊃⍵}
in any migration level and for the same reason that mix on a scalar is equivalent to first as there is an empty frame to be catenated to the single cell shape. Again, whichever of and is mix takes marginally longer as it has the overhead of preparing the frame even though it is empty.
User avatar
Phil Last
 
Posts: 557
Joined: Thu Jun 18, 2009 6:29 pm

Previous

Return to New to Dyalog?

Who is online

Users browsing this forum: No registered users and 1 guest