Wohoo 14

General APL language issues

Wohoo 14

Postby Tomas Gustafsson on Thu Jan 29, 2015 8:32 am

      (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! :-)
Tomas Gustafsson
 
Posts: 91
Joined: Mon Sep 19, 2011 6:43 pm

Re: Wohoo 14

Postby AndyS|Dyalog on Thu Jan 29, 2015 5:14 pm

:-)

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/.
User avatar
AndyS|Dyalog
 
Posts: 245
Joined: Tue May 12, 2009 6:06 pm

Re: Wohoo 14

Postby Veli-Matti on Fri Jan 30, 2015 6:57 am

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
Veli-Matti
 
Posts: 75
Joined: Sat Nov 28, 2009 3:12 pm

Re: Wohoo 14

Postby paulmansour on Fri Jan 30, 2015 9:16 pm

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
paulmansour
 
Posts: 375
Joined: Fri Oct 03, 2008 4:14 pm

Re: Wohoo 14

Postby Tomas Gustafsson on Sat Jan 31, 2015 12:59 pm

Make the arguments smaller, do the iota as rarely as possible and when the user looks elsewhere? :-)
Tomas Gustafsson
 
Posts: 91
Joined: Mon Sep 19, 2011 6:43 pm

Re: Wohoo 14

Postby stignielsen on Tue Feb 03, 2015 9:45 am

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?
User avatar
stignielsen
 
Posts: 4
Joined: Mon Sep 20, 2010 12:58 pm

Re: Wohoo 14

Postby Tomas Gustafsson on Tue Feb 03, 2015 11:06 am

Don't know... just so hard to focus on your code when your comments aren't vertically aligned. :-)
Tomas Gustafsson
 
Posts: 91
Joined: Mon Sep 19, 2011 6:43 pm

Re: Wohoo 14

Postby paulmansour on Tue Feb 03, 2015 5:06 pm

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.
paulmansour
 
Posts: 375
Joined: Fri Oct 03, 2008 4:14 pm

Re: Wohoo 14

Postby paulmansour on Tue Feb 03, 2015 5:14 pm

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.
paulmansour
 
Posts: 375
Joined: Fri Oct 03, 2008 4:14 pm

Re: Wohoo 14

Postby Roger|Dyalog on Wed Feb 04, 2015 7:40 am

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.
Roger|Dyalog
 
Posts: 238
Joined: Thu Jul 28, 2011 10:53 am

Next

Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest