Flattening a nested matrix
17 posts
• Page 2 of 2 • 1, 2
Re: Flattening a nested matrix
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.
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
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
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
<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
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
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
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.
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
mix←↑⍤0are both identical to
mix←⊃⍤0
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.
-
Phil Last - Posts: 557
- Joined: Thu Jun 18, 2009 6:29 pm
Re: Flattening a nested matrix
Similarly
first←⊃⍬∘⍴are both identical to
first←↑⍬∘⍴
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.
-
Phil Last - Posts: 557
- Joined: Thu Jun 18, 2009 6:29 pm
17 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group