Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompatHelper: bump compat for DynamicQuantities to 0.10 #264

Merged
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SymbolicRegressionSymbolicUtilsExt = "SymbolicUtils"
[compat]
Compat = "^4.2"
DynamicExpressions = "0.13"
DynamicQuantities = "0.7"
DynamicQuantities = "0.9"
JSON3 = "1"
LineSearches = "7"
LossFunctions = "0.10, 0.11"
Expand Down
8 changes: 4 additions & 4 deletions src/DimensionalAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module DimensionalAnalysisModule

import DynamicExpressions: Node
import DynamicQuantities:
Quantity, DimensionError, AbstractQuantity, dimension, ustrip, uparse, constructor_of
Quantity, DimensionError, AbstractQuantity, dimension, ustrip, uparse, constructorof
import Tricks: static_hasmethod

import ..CoreModule: Options, Dataset
Expand Down Expand Up @@ -75,14 +75,14 @@ for op in (:(Base.:+), :(Base.:-))
return W($(op)(l.val, r.val), l.wildcard && r.wildcard, false)
elseif l.wildcard && r.wildcard
return W(
constructor_of(Q)($(op)(ustrip(l), ustrip(r)), typeof(dimension(l))),
constructorof(Q)($(op)(ustrip(l), ustrip(r)), typeof(dimension(l))),
true,
false,
)
elseif l.wildcard
return W($(op)(constructor_of(Q)(ustrip(l), dimension(r)), r.val), false, false)
return W($(op)(constructorof(Q)(ustrip(l), dimension(r)), r.val), false, false)
elseif r.wildcard
return W($(op)(l.val, constructor_of(Q)(ustrip(r), dimension(l))), false, false)
return W($(op)(l.val, constructorof(Q)(ustrip(r), dimension(l))), false, false)
else
return W(one(Q), false, true)
end
Expand Down
14 changes: 9 additions & 5 deletions src/MLJInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Optim: Optim
import MLJModelInterface as MMI
import DynamicExpressions: eval_tree_array, string_tree, Node
import DynamicQuantities:
AbstractQuantity,
UnionAbstractQuantity,
AbstractDimensions,
SymbolicDimensions,
Quantity,
Expand Down Expand Up @@ -307,21 +307,25 @@ function prediction_fallback(
end
end

function unwrap_units_single(A::AbstractMatrix{T}, ::Type{D}) where {D,T<:Number}
function unwrap_units_single(A::AbstractMatrix, ::Type{D}) where {D}
return A, [D() for _ in eachrow(A)]
end
function unwrap_units_single(A::AbstractMatrix, ::Type{D}) where {D}
function unwrap_units_single(
A::AbstractMatrix{T}, ::Type{D}
) where {D,T<:UnionAbstractQuantity}
for (i, row) in enumerate(eachrow(A))
allequal(Base.Fix2(dimension_fallback, D).(row)) ||
error("Inconsistent units in feature $i of matrix.")
end
dims = map(Base.Fix2(dimension_fallback, D) ∘ first, eachrow(A))
return stack([ustrip.(row) for row in eachrow(A)]; dims=1), dims
end
function unwrap_units_single(v::AbstractVector{T}, ::Type{D}) where {D,T<:Number}
function unwrap_units_single(v::AbstractVector, ::Type{D}) where {D}
return v, D()
end
function unwrap_units_single(v::AbstractVector, ::Type{D}) where {D}
function unwrap_units_single(
v::AbstractVector{T}, ::Type{D}
) where {D,T<:UnionAbstractQuantity}
MilesCranmer marked this conversation as resolved.
Show resolved Hide resolved
allequal(Base.Fix2(dimension_fallback, D).(v)) || error("Inconsistent units in vector.")
dims = dimension_fallback(first(v), D)
v = ustrip.(v)
Expand Down
Loading