Thanks, Raul.
NB - mods to parRuskey below!
I'm not sure my latest effort (mdconst) merits much study.
If you do look, you might notice that the filtering check can be done
slightly more
efficiently by building only the first column of the new comparand and
then constructing
all columns only for required rows, but at the cost of greater code
complexity and even less
transparency. Congrats if you understand this!
Erling might like to look at this modification of his own recent amended
version of parRuskey.
It manages to avoid some recursion. The calling routine is as he posted
earlier today,
but I'll reproduce it here, with subscripts "new" for it and for the
"S" verb:
parRuskeynew =: 4 : 0
NB. L =: 0$~0, 2 + y NB. debug/understand array of call parameters
r=. (i.y) Snew (x-1),y-1
NB. R =: r NB. debug/understand output
r </."1 i.y
)
Snew =: 4 : 0
NB. L =: L, y, x NB. debug/understand array of call parameters
'k n' =. y
a =.x
r =. 0$~ 0, #a
if. k = n - 1 do. NB. replace repeated calls with k = n (on entry)
r =. (i.k+1) n }"0 1 (k+1)# ,:a NB. don't need to use recursion here!
else.
NB. is there a way to avoid recursion here, too?
r =. r, ,/ (Snew&(k,n-1))"1 (i.k+1) n }"0 1 a NB.apply "1 instead of
do loop
end.
if. k > 0 do.
r=.r, (k n } a) Snew (k-1),n-1
end.
r
)
(parRuskeynew -:parRuskey) /6 9
1
Getting more J-ish?
Cheers,
Mike
On 31/10/2017 16:31, Raul Miller wrote:
Well... I did get as far as doing basic timings:
tim=:2 :0
:
u ratetime v"0
)
ratetime=:2 :0
u NB. force x and y to be verb args
:
try.
assert. x<:y
tV=.6!:2 'rV=. x v y'
tU=.6!:2 'rU=. x u y'
tU%tV
catch.
rV=.rU=.0
_
end.
assert. rV -:&(/:~)&:(/:~"1)&:(/:~&.>) rU
)
9!:11]2 NB. shrink precision to be more social
G=:parRDM tim mdconst
(1+i.10) G table 1+i.10
┌──┬─────────────────────────────────────────────────┐
│G │ 1 2 3 4 5 6 7 8 9 10│
├──┼─────────────────────────────────────────────────┤
│ 1│0.58 0.8 1 0.67 1 0.67 1.5 0.67 1.5 0.67│
│ 2│ _ 2.7 0.15 0.14 0.22 0.21 0.29 0.23 0.42 0.45│
│ 3│ _ _ 0.83 1 1.3 1.3 0.72 1.1 1.1 0.99│
│ 4│ _ _ _ 0.8 0.85 1.2 1.2 1 1.2 1.2│
│ 5│ _ _ _ _ 0.89 0.74 0.93 1.1 1.2 1│
│ 6│ _ _ _ _ _ 0.9 0.53 0.59 0.73 0.83│
│ 7│ _ _ _ _ _ _ 0.91 0.33 0.27 0.53│
│ 8│ _ _ _ _ _ _ _ 0.83 0.17 0.16│
│ 9│ _ _ _ _ _ _ _ _ 0.78 0.082│
│10│ _ _ _ _ _ _ _ _ _ 0.75│
└──┴─────────────────────────────────────────────────┘
(Beware proportionally spaced fonts: they are messy...)
parRDM from http://jsoftware.com/pipermail/programming/2017-October/049451.html
mdconst from http://jsoftware.com/pipermail/programming/2017-October/049453.html
I did sort of like the idea of pre-computing partition sizes and
building up from there, But I have not deeply studied your code yet.
(It is on my todo list, though...)
Thanks,
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm