Skip to content

Commit 68941b8

Browse files
committed
Back to generated version
1 parent 41f6257 commit 68941b8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/utils.jl

Lines changed: 11 additions & 6 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-
for dim in dimension_names
18-
f((getfield(arg, dim) for arg in args)...) || return false
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)
1924
end
20-
return true
25+
return output
2126
end
2227

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

0 commit comments

Comments
 (0)