Skip to content

Commit d31e990

Browse files
Fix ModelingToolkitBase unbound signatures
Remove unnecessary static parameters from parameter-buffer methods and use public type intersection for numeric array element types. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
1 parent aa4afff commit d31e990

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

lib/ModelingToolkitBase/src/systems/parameter_buffer.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,9 @@ end
780780
# For type-inference when using `SII.setp_oop`
781781
@generated function _remake_buffer(
782782
indp, oldbuf::MTKParameters{T, I, D, C, N, H},
783-
idxs::Union{Tuple{Vararg{ParameterIndex}}, AbstractArray{<:ParameterIndex{P}}},
783+
idxs::Union{Tuple{Vararg{ParameterIndex}}, AbstractArray{<:ParameterIndex}},
784784
vals::Union{AbstractArray, Tuple}; validate = true
785-
) where {T, I, D, C, N, H, P}
785+
) where {T, I, D, C, N, H}
786786

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

10101010
function SymbolicIndexingInterface.with_updated_parameter_timeseries_values(
1011-
::AbstractSystem, ps::MTKParameters, args::Pair{A, B}...
1012-
) where {
1013-
A, B <: NestedGetIndex,
1014-
}
1011+
::AbstractSystem, ps::MTKParameters, args::Pair{<:Any, <:NestedGetIndex}...
1012+
)
10151013
for (i, ngi) in args
10161014
for (j, val) in enumerate(ngi.x)
10171015
copyto!(view(ps.discrete[j], Block(i)), val)

lib/ModelingToolkitBase/src/systems/problem_utils.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,9 +1767,6 @@ function maybe_build_initialization_problem(
17671767
)
17681768
end
17691769

1770-
rm_union(::Type{Union{T, Nothing}}) where {T} = T
1771-
rm_union(::Type{T}) where {T} = T
1772-
17731770
"""
17741771
$(TYPEDSIGNATURES)
17751772
@@ -1783,8 +1780,7 @@ function float_type_from_varmap(varmap, floatT = Bool)
17831780
is_array_of_symbolics(v) && continue
17841781
v = unwrap_const(v)
17851782
if v isa AbstractArray
1786-
# Remove union in case some elements of the array are `nothing`
1787-
floatT = promote_type(floatT, rm_union(eltype(unwrap_const(v))))
1783+
floatT = promote_type(floatT, typeintersect(eltype(v), Number))
17881784
elseif v isa Number
17891785
floatT = promote_type(floatT, typeof(unwrap_const(v)))
17901786
end

lib/ModelingToolkitBase/test/variable_utils.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ using ModelingToolkitBase: value, parse_variable
33
using SymbolicUtils: <
44
import SymbolicUtils as SU
55

6+
@variables x
7+
@test ModelingToolkitBase.float_type_from_varmap(
8+
[x => Union{Nothing, BigFloat}[nothing]]
9+
) == BigFloat
10+
@test ModelingToolkitBase.float_type_from_varmap(
11+
[x => Union{Nothing, Float32}[nothing]]
12+
) == Float32
13+
614
@parameters α β δ
715
expr = (((1 / β - 1) + δ) / α)^(1 /- 1))
816
ref = sort([β, δ, α], lt = <ₑ)

0 commit comments

Comments
 (0)