Skip to content

Commit 1c574d8

Browse files
committed
Back to generated version
1 parent 152952c commit 1c574d8

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/utils.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ function map_dimensions(f::F, args::AbstractDimensions...) where {F<:Function}
1111
)...
1212
)
1313
end
14-
function all_dimensions(f::F, args::AbstractDimensions...) where {F<:Function}
15-
dimension_type = promote_type(typeof(args).parameters...)
16-
dimension_names = static_fieldnames(dimension_type)
17-
return all(
18-
dim -> f((getfield(arg, dim) for arg in args)...)
19-
dimension_names
20-
)
14+
@generated function all_dimensions(f::F, args::AbstractDimensions...) where {F<:Function}
15+
# Test a function over all dimensions
16+
output = Expr(:&&)
17+
dimension_type = promote_type(args...)
18+
for dim in Base.fieldnames(dimension_type)
19+
f_expr = :(f())
20+
for i=1:length(args)
21+
push!(f_expr.args, :(args[$i].$dim))
22+
end
23+
push!(output.args, f_expr)
24+
end
25+
return output
2126
end
2227

2328
Base.float(q::AbstractQuantity{T}) where {T<:AbstractFloat} = convert(T, q)

0 commit comments

Comments
 (0)