Skip to content

Commit 6665eb0

Browse files
feat: allow swapping out argument name function in array_variable_assignments
1 parent e735b4f commit 6665eb0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/systems/codegen_utils.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ end
1212
1313
Given the arguments to `build_function_wrapper`, return a list of assignments which
1414
reconstruct array variables if they are present scalarized in `args`.
15+
16+
# Keyword Arguments
17+
18+
- `argument_name` a function of the form `(::Int) -> Symbol` which takes the index of
19+
an argument to the generated function and returns the name of the argument in the
20+
generated function.
1521
"""
16-
function array_variable_assignments(args...)
22+
function array_variable_assignments(args...; argument_name = generated_argument_name)
1723
# map array symbolic to an identically sized array where each element is (buffer_idx, idx_in_buffer)
1824
var_to_arridxs = Dict{BasicSymbolic, Array{Tuple{Int, Int}}}()
1925
for (i, arg) in enumerate(args)
@@ -60,12 +66,12 @@ function array_variable_assignments(args...)
6066
end
6167
# view and reshape
6268

63-
expr = term(reshape, term(view, generated_argument_name(buffer_idx), idxs),
69+
expr = term(reshape, term(view, argument_name(buffer_idx), idxs),
6470
size(arrvar))
6571
else
6672
elems = map(idxs) do idx
6773
i, j = idx
68-
term(getindex, generated_argument_name(i), j)
74+
term(getindex, argument_name(i), j)
6975
end
7076
# use `MakeArray` syntax and generate a stack-allocated array
7177
expr = term(SymbolicUtils.Code.create_array, SArray, nothing,

0 commit comments

Comments
 (0)