Page 1 of 2
Wohoo 14
Posted: Thu Jan 29, 2015 8:32 am
by Tomas Gustafsson
(3 2⍴⍳6)⍳2 2⍴⍳6
1 2
Thanks @ Dyalog!!!
Tried that as a feeler, and it worked!! Not even axis indication needed.
Saves long moments of waiting time at program startup & geocache refresh (a huge seek and match), compared to (optionally with compose variations of):
(↓3 2⍴⍳6)⍳↓2 2⍴⍳6
Found and taken! :-)
Re: Wohoo 14
Posted: Thu Jan 29, 2015 5:14 pm
by AndyS|Dyalog
:-)
If you try Tomas' example in 13.2 or earlier you'll get a RANK ERROR .. this is a feature introduced in Dyalog 14.0 and is documented in the Release Notes under
Extention to Dyadic Iota (
http://help.dyalog.com/14.0/index_Left.htm#StartTopic=Content%2FRelNotes14.0%2FIndex%20Of%20Extension.htm).
You might also find
Inverted Table Index Of (
http://help.dyalog.com/14.0/index_Left.htm#StartTopic=Content%2FLanguage%2FPrimitive%20Operators%2FInverted%20Table%20Index%20Of.htm) of interest.
It's worth pointing out that a key insight about ⍳ is that:
"
x⍳x are like ID numbers; questions of identity on x can often be answered more efficiently on x⍳x than on x itself."
This is a quote from the blog post
A Speed-Up Story http://www.dyalog.com/blog/2014/11/a-speed-up-story-2/.
Re: Wohoo 14
Posted: Fri Jan 30, 2015 6:57 am
by Veli-Matti
Hmm.. sometimes reading the manual has been worth it - especially the Idiom Recognition part. I think that the speedy idiom {(↓⍺)⍳↓⍵} works as quickly as the extended iota, and is available in 13.2 as well.
-Veli-Matti
Re: Wohoo 14
Posted: Fri Jan 30, 2015 9:16 pm
by paulmansour
Veli-Matti wrote:Hmm.. sometimes reading the manual has been worth it - especially the Idiom Recognition part. I think that the speedy idiom {(↓⍺)⍳↓⍵} works as quickly as the extended iota, and is available in 13.2 as well.
-Veli-Matti
It is becoming a bit of a full time job to keep up with the best way to do char matrix iota these days. I recently spent some time trying to find the fastest method (in V14).
Anyone want to guess what the answer is?
Paul
Re: Wohoo 14
Posted: Sat Jan 31, 2015 12:59 pm
by Tomas Gustafsson
Make the arguments smaller, do the iota as rarely as possible and when the user looks elsewhere? :-)
Re: Wohoo 14
Posted: Tue Feb 03, 2015 9:45 am
by stignielsen
The new matrix iota was one of the first thing I tried out, to see if it is faster than {(↓⍺)⍳↓⍵}. I couldn't see any difference, but still both methods have a problem with floats. So we stick to our good old cover function to take any type of matrix and look up rows. If floats exists, they are converted to an integer index, i.e. several lookups are made and still this function is much faster than {(↓⍺)⍳↓⍵};-!
NB! You APL guys will probably wonder why there is a :For loop, but I couldn't find any compact APL constructions as fast as this construction! Any suggestions?
xFindn ⍝ ... SimCorp matrix row lookup
:If (2⊃⍴y)=2⊃⍴x←(¯2↑1 1,⍴x)⍴x
:AndIf ~∧/(⎕DR¨y x)∊11 83 163 323 ⍝ ... If not homogeneous integer array
:AndIf ∨/lx←⊃∨/(⎕DR¨¨↓[1]¨y x)∊¨⊂645 1287 ⍝ ... check for presence of floats/decimals
:For i :In {⍵/⍳⍴⍵} lx ⍝ ... and if they exists
floats←y[;i] ⍝ ... make a column wise lookup
y[;i]←floats⍳floats ⍝ ... and store the indices
x[;i]←floats⍳x[;i] ⍝ ... as this will make the final row lookup much much faster!?
:EndFor ⍝ ... However, it slows down a bit if texts are present and no floats!
:EndIf
r←y{(↓⍺)⍳↓⍵}x
It could perhaps be an idea to build in this logic in Dyalog whenever a matrix lookup is performed with either method?
Re: Wohoo 14
Posted: Tue Feb 03, 2015 11:06 am
by Tomas Gustafsson
Don't know... just so hard to focus on your code when your comments aren't vertically aligned. :-)
Re: Wohoo 14
Posted: Tue Feb 03, 2015 5:06 pm
by paulmansour
I assumed that the old matrix iota idiom
{(↓⍺)⍳↓⍵}
only "worked" (was optimized for) simple character matrices.
Does it do anything special for general, possibly nested matrices? I don't think you get any advantage here.
In the code above, I assume the arguments are matrices where each column is of the same type, and there are possibly character columns as well?
Wouldn't you be better off converting all columns to text, laminating, and then using the idiom? Or better yet, using v14, allowing Roger Hui to do it for you with 8 i-beam?
The only thing you would need to do is pre-process the floats somehow.
Re: Wohoo 14
Posted: Tue Feb 03, 2015 5:14 pm
by paulmansour
And the answer to the question "what is the fastest way to do (simple) matrix iota these days?" is to pretend you have a one-column inverted table and use i-beam!
{(,⊂⍺)(8⌶),⊂⍵}
For now. I think.
Re: Wohoo 14
Posted: Wed Feb 04, 2015 7:40 am
by Roger|Dyalog
I just noticed the lively discussion. Thanks everyone for your questions and observations. Index-of is a complex topic, and it is too late in my day (23:40) to compose a proper reply. I will respond tomorrow.