@@ -49,6 +49,27 @@ function _setindex!(x, value, sizes::Sizes, k::Int, j)
4949 return x[sizes. storage_offset[k]+ j] = value
5050end
5151
52+ """
53+ @j(storage[node]) -> _getindex(storage, f.sizes, node, j)
54+ @j(storage[node] = value) -> _setindex!(storage, value, f.sizes, node, j)
55+
56+ This "at `j`" converts `getindex` and `setindex!` calls to access
57+ the sub-array in a vector corresponding to a node at its `j`th index.
58+ """
59+ macro j (expr)
60+ if Meta. isexpr (expr, :(= )) && length (expr. args) == 2
61+ lhs, rhs = expr. args
62+ @assert Meta. isexpr (lhs, :ref )
63+ @assert length (expr. args) == 2
64+ return Expr (:call , :_setindex! , esc (lhs. args[1 ]), esc (rhs), esc (:(f. sizes)), esc (lhs. args[2 ]), esc (:j ))
65+ elseif Meta. isexpr (expr, :ref ) && length (expr. args) == 2
66+ arr, idx = expr. args
67+ return Expr (:call , :_getindex , esc (arr), esc (:(f. sizes)), esc (idx), esc (:j ))
68+ else
69+ error (" Unsupported expression `$expr `" )
70+ end
71+ end
72+
5273# /!\ Can only be called in decreasing `k` order
5374function _add_size! (sizes:: Sizes , k:: Int , size:: Tuple )
5475 sizes. ndims[k] = length (size)
0 commit comments