bug-apl
[Top][All Lists]

## Potential problem in diadic iota (⍳) or in Pick (⊃)

 From: Christian Robert Subject: Potential problem in diadic iota (⍳) or in Pick (⊃) Date: Thu, 6 Aug 2020 20:50:27 -0400 User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.1.0

```Can someone help me debug this function (fasteach). I'm not the author
but from what I've read it may be a faster than the "each" Operator especially
when a few unique numbers in a large array

∇z←test;⎕RL;t;i;r
⎕RL←0
i←20
Loop:
t←? 1000 ⍴ i
i,r←t ≡ 2÷⍨ {⍵×2} fasteach t
→(r=0)/Fail
i←i+1
→Loop
Fail:
''
'Failed with t←? 1000 ⍴', (⍕i)
''
z←t
∇

∇z←(F fasteach) A;shp;vec;nub;res;idx
shp←⍴A               ⍝ Shape and ...
vec←,A               ⍝ ... ravel of arg.
nub←∪ vec            ⍝ Vector of unique elements.
nub←∪ vec            ⍝ Vector of unique elements.
res←F¨nub            ⍝ Result for unique elts.
idx←nub ⍳ vec        ⍝ Indices of arg in nub ...
z←shp ⍴ idx ⊃¨⊂ res  ⍝ ... distribute result.
∇

test
20 1
21 1
22 1
23 1
24 1
25 1
26 1
27 1
28 1
29 1
30 1
31 1
32 1
33 1
34 1
35 1
36 1
37 1
38 1
39 1
40 1
41 1
42 1
43 1
44 1
45 1
46 1
47 1
48 1
49 1
50 1
51 1
52 1
53 1
54 1
55 1
56 1
57 1
58 1
59 1
60 1
61 1
62 1
63 1
64 0

Failed with t←? 1000 ⍴64

31 12 9 10 50 26 19 11 47 34 58 45 46 9 64 54 4 4 38 25 12 54 29 24 45 44 32 13
57 54 48 40 27 43 50 51 37 11 14 15 3 32 5 31 55 64 36 11 6 5 13 21 5 47 37 39
58 30 39 46 51 46 12 58 43 28 52 59 2
4 56 10 18 11 48 60 36 49 10 14 54 56 63 9 18 52 37 4 5 33 63 61 1 31 19
9 28 12 17 56 59 35 46 57 60 29 22 52 15 23 44 2 36 27 7 52 22 56 41 63 64 32
33 35 30 15 49 29 45 12 59 52 55 55 16
17 3 24 12 63 37 14 20 13 4 24 40 55 30 10 28 13 64 41 21 52 32 23 11 50
8 35 16 19 20 61 38 51 14 39 29 8 11 63 61 47 56 63 9 50 5 13 62 24 58 39 12 39
26 51 57 57 22 6 3 13 52 56 54 10 52
18 20 12 49 14 4 13 23 37 27 50 37 60 11 54 49 10 54 47 26 45 50 7 22 54
5 18 30 2 17 64 17 29 11 36 62 37 6 17 57 63 27 44 46 27 43 20 27 14 52 20 39
12 49 29 44 39 26 40 2 61 13 36 39 58 12
62 50 19 27 4 6 27 5 63 29 33 59 38 48 54 12 43 41 26 37 20 50 50 43 27
11 59 29 21 56 9 49 44 21 63 31 6 63 55 45 33 53 51 41 51 45 40 44 3 45 56 34
14 62 44 54 13 15 43 12 24 32 11 44 27 14
44 27 49 36 57 21 64 45 16 45 61 55 38 8 37 33 27 25 34 19 60 9 27 46 50
42 55 4 19 29 13 21 53 22 64 8 41 56 2 10 17 14 25 27 35 64 18 44 61 17 49 15
40 63 27 29 25 28 19 34 3 43 9 47 25 25
25 7 33 61 15 60 55 13 30 64 46 5 23 48 44 45 12 62 36 18 9 48 46 60 59
28 37 42 62 48 35 60 35 28 18 24 62 14 7 12 44 37 62 13 61 51 47 22 19 45 17 42
39 34 11 52 13 11 63 19 34 19 62 7 35
44 19 46 54 19 27 50 60 30 17 46 34 13 14 24 53 61 52 44 23 64 7 10 11 52
10 11 26 25 12 40 17 31 25 57 7 31 25 48 55 57 39 45 60 11 12 19 8 53 6 8 22 54
39 52 50 61 2 32 29 60 3 22 19 45 49
38 55 46 23 55 28 15 20 49 6 63 13 51 20 27 57 60 61 30 35 54 40 13 7 49
44 62 1 43 59 47 34 36 27 1 6 10 12 38 60 7 6 1 16 46 47 22 15 49 35 41 29 20
30 3 39 50 22 49 46 9 36 20 32 23 12 63
25 51 53 34 3 18 52 52 38 23 37 9 59 64 1 37 60 39 11 17 4 42 19 17 40 28
38 45 19 63 9 5 26 37 62 30 43 17 63 38 25 42 55 53 10 5 33 34 48 35 2 55 20 20
60 52 63 59 44 18 2 50 37 22 9 29 12
2 55 3 15 28 30 37 16 2 10 46 43 59 60 26 62 8 54 30 15 11 33 53 15 42 44
8 26 55 12 57 3 1 54 20 61 60 17 50 59 30 48 53 49 55 46 31 38 24 34 6 15 35 40
17 14 47 38 25 23 53 15 40 22 2 18 15
54 4 56 38 14 64 12 46 60 8 37 62 48 16 22 51 31 43 41 36 50 63 19 22 17
37 38 51 4 32 7 25 44 49 17 42 9 26 57 60 49 24 2 5 29 59 35 42 47 10 61 9 11
59 9 14 24 18 49 25 56 20 29 31 36 25 53
42 48 60 9 56 64 31 55 42 27 47 57 6 15 6 33 54 47 11 37 63 63 46 42 1 61
22 8 5 2 62 61 5 5 2 59 62 50 63 45 21 5 28 40 58 2 50 50 4 28 8 26 29 4 21 43
60 24 45 39 23 52 40 56 60 40 19 21 55
7 37 5 53 26 9 55 25 13 46 62 13 51 40 17 10 49 25 57 35 55 18 5 45 26 19
38 45 2 17 48 45 19 45 43 64 10 28 17 16 20 54 20 13 56 49 21 62 56 44 35 46 52
24 35 18 63 53 30 45 8 37 63 37 19 16
33 64 27 31 7 41 15 7 2 28 44 31 54 43 25 26 43 23 2 15 27 44 23 50 29 19
11 31 49 36 51 17 15 47 57 27 51 11 58 55 28 3 19 59 55 53 16 25 28 25 21 3 28
42 2 52 60 13 11 47 37 39 2 3 60 10 17

I don't know why it fail here.

I suspect an error either in "idx←nub ⍳ vec" or
in "idx ⊃¨⊂ res"

eg: in diadic iota (⍳) or in Pick (⊃)

will continue to search,
If someone can confirm it may help...

Xtian.

```