The problem is in sparse (x i. y):
s =. $.,1
s
0 | 1
s =. 0 (0}) s
s
0 | 0
s i. 1
1
(8 $. s) i. 1 NB. should be 1
0
I need some fortification before venturing into the code for sparse i.
. It appears that when there are no elements it returns 0 rather than
the length of the leading axis.
Henry Rich
On 8/26/2022 9:51 PM, Raul Miller wrote:
I'm seeing strange behavior with sparse arrays, and I have been mostly
unsuccessful in simplifying code exhibiting the problem. Thus:
pritch=: {{
spokes=. $.,1
primes=. i.0
while. y > #spokes do.
primes=. primes, p=. 2+(}.spokes) i.1 NB. find next prime
rim=. #spokes NB. "length" of "circumference" of wheel
spokes=. (y<.p*rim)$spokes NB. roll next larger wheel
spokes=. 0 ((#~ y>])_1+p*1+i.rim)} spokes
end.
NB. elided code here
primes,1+}.,I.spokes
}}
pritchard 20
2 3 5 7 11 13 17 19
pritch8=: {{
spokes=. $.,1
primes=. i.0
while. y > #spokes do.
primes=. primes, p=. 2+(}.spokes) i.1 NB. find next prime
rim=. #spokes NB. "length" of "circumference" of wheel
spokes=. (y<.p*rim)$spokes NB. roll next larger wheel
spokes=. 8 $. 0 ((#~ y>])_1+p*1+i.rim)} spokes
end. NB. elided code here
primes,1+}.,I.spokes
}}
pritch8 20
2 2 3 5 7 11 13 17 19
Somehow the value for p is different when 8 $. is present in this
particular implementation (though I don't observe similar behavior in
similar uses of 8 $. y).
I'm reporting this on the beta forum, but it's an issue in J903 (and,
probably, earlier versions of J).
FYI,
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm