Skip to content

Commit

Permalink
Back to generated version
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Jun 14, 2023
1 parent 41f6257 commit 68941b8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ function map_dimensions(f::F, args::AbstractDimensions...) where {F<:Function}
)...
)
end
function all_dimensions(f::F, args::AbstractDimensions...) where {F<:Function}
dimension_type = promote_type(typeof(args).parameters...)
dimension_names = static_fieldnames(dimension_type)
for dim in dimension_names
f((getfield(arg, dim) for arg in args)...) || return false
@generated function all_dimensions(f::F, args::AbstractDimensions...) where {F<:Function}
# Test a function over all dimensions
output = Expr(:&&)
dimension_type = promote_type(args...)
for dim in Base.fieldnames(dimension_type)
f_expr = :(f())
for i=1:length(args)
push!(f_expr.args, :(args[$i].$dim))
end
push!(output.args, f_expr)
end
return true
return output
end

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

0 comments on commit 68941b8

Please sign in to comment.