@@ -49,6 +49,27 @@ function _setindex!(x, value, sizes::Sizes, k::Int, j)
49
49
return x[sizes. storage_offset[k]+ j] = value
50
50
end
51
51
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
+
52
73
# /!\ Can only be called in decreasing `k` order
53
74
function _add_size! (sizes:: Sizes , k:: Int , size:: Tuple )
54
75
sizes. ndims[k] = length (size)
0 commit comments