I have encountered strange behaviour:
ParentIdxAll
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ... 345 346
ParentIndex
1 3 4 5 11 31 32 33 63 65 68 98 112 113 114 154 155 156 ... 329 330
ParentIdxAll i. ~. ParentIndex NB. Unexpected result!
346 346 346 346 346 346 346 346 346 346 346 346 ... 346
ParentIdxAll i. ParentIndex NB. behaves as expected
0 2 3 4 10 30 31 32 62 64 67 97 111 112 113 153 154 155 ... 328 329
NB. Workaround
ParentIndexUnique =. ~. ParentIndex
ParentIdxAll i. ParentIndexUnique NB. gives desired proper result
0 2 3 4 10 30 31 32 62 64 67 97 111 112 113 153 154 155 ...328 329
The calling code is a bit convoluted, and is inside an object, so it is not easy to reproduce:
NB.*invertParents v build a table for immediately finding the children of a node
NB.-syntax:
NB.- invertParents__Data childTable
NB.-note:
NB.-Result is parent table name ; boxed matrix of children, in same order as the index of the parent table
invertParents=: 3 : 0
ChildTable=.y
'Index ParentTable ParentIndex'=.(< 3 4 5 ; 1) { ('Metadata_',ChildTable)~
ParentTable =. unslashTableName ParentTable
ParentIdxAll=. 3 1 {:: ('Metadata_',ParentTable)~
PClas=.ParentIndex </. Index
Res=.(# ParentIdxAll) # a:
Res=. PClas (ParentIdxAll i. ~. ParentIndex) } Res
ParentTable ; < Res
)
Unfortunately i do not have a strict unittest for this verb. It works on some datasets but not all. I suspect that this has something to do with unaliasing and indirect names that make i. ~. behave like (i. ~.) ?