Pointer SNodes Active Flag


I have been reading through the Examples and Tests in order to find out more about Pointer SNodes. From what I understand this type of node also maintains memory sparsity, where memory is only allocated when a specific section of the domain is needed/ assigned a value. Do I understand this correctly?
For example, similar to the tests

x = ti.var(dt=ti.f32)
ti.root.pointer(ti.i, 16).dense(ti.i, 16).place(x)
x[0] = 1

This would allocate memory for the first pointer to the first 16 entries of x correct? In the tests you verify this by checking ti.is_active for individual elements.

What I’m not clear on however, is how you use the ti.is_active in the examples/taichi_sparse.py example. Specifically

These blocks have sizes

but are accessed using indices i = [0,n). What am I missing here? How can you check if the blocks are active using these indices? I thought that maybe the calls propagate to the children of that block/ node (not sure what to call it), but that would be ambiguous as soon as you have multiple children.

Any help or explanation on this would be much appreciated, since I also did not easily find an answer by looking through the source.

I think what’s happening is that levels of the tree are created on demand when assigning to x as you point out, but the blocks (snodes) are a separate tree of just the data layout. So imagine index [I,j] coming in at the root. i and j are divided by 64 to find the pointer for the next level down, but the layout of the block1 is the same for all those children so you don’t have to actually construct 64 copies of block1. Each snode keeps track of its parent, so is_active(block, [I,j]) can figure out the actual tree path and check if it exists. If so, then it returns True.