Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/ModelingToolkitBase/src/systems/parameter_buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,9 @@ end
# For type-inference when using `SII.setp_oop`
@generated function _remake_buffer(
indp, oldbuf::MTKParameters{T, I, D, C, N, H},
idxs::Union{Tuple{Vararg{ParameterIndex}}, AbstractArray{<:ParameterIndex{P}}},
idxs::Union{Tuple{Vararg{ParameterIndex}}, AbstractArray{<:ParameterIndex}},
vals::Union{AbstractArray, Tuple}; validate = true
) where {T, I, D, C, N, H, P}
) where {T, I, D, C, N, H}

# fallback to non-generated method if values aren't type-stable
if vals <: AbstractArray && !isconcretetype(eltype(vals))
Expand Down Expand Up @@ -1008,10 +1008,8 @@ end
Base.size(::NestedGetIndex) = ()

function SymbolicIndexingInterface.with_updated_parameter_timeseries_values(
::AbstractSystem, ps::MTKParameters, args::Pair{A, B}...
) where {
A, B <: NestedGetIndex,
}
::AbstractSystem, ps::MTKParameters, args::Pair{<:Any, <:NestedGetIndex}...
)
for (i, ngi) in args
for (j, val) in enumerate(ngi.x)
copyto!(view(ps.discrete[j], Block(i)), val)
Expand Down
6 changes: 1 addition & 5 deletions lib/ModelingToolkitBase/src/systems/problem_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1767,9 +1767,6 @@ function maybe_build_initialization_problem(
)
end

rm_union(::Type{Union{T, Nothing}}) where {T} = T
rm_union(::Type{T}) where {T} = T

"""
$(TYPEDSIGNATURES)

Expand All @@ -1783,8 +1780,7 @@ function float_type_from_varmap(varmap, floatT = Bool)
is_array_of_symbolics(v) && continue
v = unwrap_const(v)
if v isa AbstractArray
# Remove union in case some elements of the array are `nothing`
floatT = promote_type(floatT, rm_union(eltype(unwrap_const(v))))
floatT = promote_type(floatT, typeintersect(eltype(v), Number))
elseif v isa Number
floatT = promote_type(floatT, typeof(unwrap_const(v)))
end
Expand Down
8 changes: 8 additions & 0 deletions lib/ModelingToolkitBase/test/variable_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ using ModelingToolkitBase: value, parse_variable
using SymbolicUtils: <ₑ
import SymbolicUtils as SU

@variables x
@test ModelingToolkitBase.float_type_from_varmap(
[x => Union{Nothing, BigFloat}[nothing]]
) == BigFloat
@test ModelingToolkitBase.float_type_from_varmap(
[x => Union{Nothing, Float32}[nothing]]
) == Float32

@parameters α β δ
expr = (((1 / β - 1) + δ) / α)^(1 / (α - 1))
ref = sort([β, δ, α], lt = <ₑ)
Expand Down
Loading