Workspace Usage when Indexing?

General APL language issues

Workspace Usage when Indexing?

Postby Dick Bowman on Wed Feb 03, 2010 11:39 am

I greatly prefer using the indexing function to bracket-indexing, but have noticed a difference in workspace requirements.

Using some large vectors I started hitting WS FULL with ((⊂index)⌷vector)←newvalues.
However, with the same data vector[index]←newvalues executes without problems.

Anyone seen anything similar? In my state of childish innocence I'd assumed that the inner workings would be the same for either syntax.
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Re: Workspace Usage when Indexing?

Postby Phil Last on Thu Feb 04, 2010 7:54 am

Yes. Using this expression in which cf is an operator that compares the timings of its two function operands:

      {z←?(2×⍵)⍴⍵ ⋄ x←?⍵⍴⍵ ⋄ {z[x]←x}cf{((⊂x)⌷z)←x}⍵}100

I gave it increasing powers of 10 until WS FULL that hit the right operand first.
The speed comparison had been consistently in favour of the left with a factor of between 2 and 3 times as fast.
User avatar
Phil Last
 
Posts: 624
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Workspace Usage when Indexing?

Postby JohnS|Dyalog on Thu Feb 04, 2010 5:23 pm

I think that what is happening here is that, in general, with a selective specification, such as:

Code: Select all
      (f g ... h VAR) ← ...

The evaluation starts with a full index set for VAR (i.e. ⍳⍴VAR), which is modified right-to-left by successive functions. So, for example, we could have:

Code: Select all
      vec←⎕a
      (6↑,⌽⍉5 5⍴vec)←'.'
      vec
.BCDE.GHIJ.LMNO.QRST..WXYZ

whereas

Code: Select all
     VAR[x]←...


depends only on the number of items in x.

It could pay us to find some special cases, such as when there is only a single selection function, but we don't do so at the moment. I have "put it on the list", ref[5679].
JohnS|Dyalog
 


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest