Hi all!

Here is a new parRuskey, slightly slower but written in a normal way for J code.

From here we can apply our normal tricks to make it faster and better.

k and n in S is one less than in the original, because of the index origin of J.

I removed the global variables. This had a negative performance impact.

Changing the index had a small positive performance impact.

ts=: 6!:2 , 7!:2@]       NB. Time and space

parRuskey =: 4 : 0
r=. (i.y) S (x-1);y-1
r </."1 i.y
)

S =: 4 : 0
'k n' =. y
a=.x
r=. (0,_1{.$a)$0
if. k=n do.
  r=.a
else.
  for_i. i.k+1 do.
    r=.r, (i n } a) S k;n-1
  end.
  if. k > 0 do.
    r=.r, (k n } a) S (k-1);n-1
  end.
end.
r
)

2 parRuskey 4
3 parRuskey 5

ts'5 parRuskey 10'

Cheers,

Erling Hellenäs



Den 2017-10-30 kl. 16:20, skrev Erling Hellenäs:
The original prints each a, accumulates nothing. /Erling


Den 2017-10-30 kl. 16:17, skrev Erling Hellenäs:
Maybe. I wouldn't know how to measure this. I tried having three r in different sizes, but it was slower :) /Erling


Den 2017-10-30 kl. 16:06, skrev Raul Miller:
I suspect not.. (but take my timings with a grain of salt - or better
yet, do them yourself - I was working with a modified version of S
which is quite a bit slower, actually).

But I expect that (except for the edge cases where most of the
instances of a are used) most of the time in S is spent in incremental
updates of a. There are a lot of them.

Thanks,


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to