From 705ae68d92d5e1d0070a025c46e588f4e2ae6197 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Mon, 27 Nov 2023 00:46:06 +0300 Subject: [PATCH] Provide `Base.IteratorEltype()` / `Base.eltype()` ``` julia> euclidean(a, b) ERROR: MethodError: no method matching oneunit(::Type{Any}) Closest candidates are: oneunit(::Type{Union{Missing, T}}) where T @ Base missing.jl:105 oneunit(::Type{T}) where T @ Base number.jl:370 oneunit(::T) where T @ Base number.jl:369 ... Stacktrace: [1] oneunit(#unused#::Type{Any}) @ Base ./missing.jl:106 [2] _eval_start(d::Euclidean, #unused#::Type{Any}, #unused#::Type{Any}, #unused#::Nothing) @ Distances ~/.julia/packages/Distances/PvoXa/src/metrics.jl:320 [3] _eval_start(d::Euclidean, #unused#::Type{Any}, #unused#::Type{Any}) @ Distances ~/.julia/packages/Distances/PvoXa/src/metrics.jl:318 [4] eval_start(d::Euclidean, a::VariableRef, b::VariableRef) @ Distances ~/.julia/packages/Distances/PvoXa/src/metrics.jl:317 [5] _evaluate(d::Euclidean, a::VariableRef, b::VariableRef, #unused#::Nothing) @ Distances ~/.julia/packages/Distances/PvoXa/src/metrics.jl:236 [6] (::Euclidean)(a::VariableRef, b::VariableRef) @ Distances ~/.julia/packages/Distances/PvoXa/src/metrics.jl:328 [7] top-level scope @ REPL[10]:1 ``` --- src/JuMP.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/JuMP.jl b/src/JuMP.jl index 9bc01c96cad..659709c6b41 100644 --- a/src/JuMP.jl +++ b/src/JuMP.jl @@ -1049,6 +1049,9 @@ function owner_model end Base.ndims(::Type{<:AbstractJuMPScalar}) = 0 Base.ndims(::AbstractJuMPScalar) = 0 +Base.IteratorEltype(::Type{<:AbstractJuMPScalar}) = Base.HasEltype() +Base.eltype(::Type{T}) where {T<:AbstractJuMPScalar} = T + # These are required to create symmetric containers of AbstractJuMPScalars. LinearAlgebra.symmetric_type(::Type{T}) where {T<:AbstractJuMPScalar} = T LinearAlgebra.hermitian_type(::Type{T}) where {T<:AbstractJuMPScalar} = T