From 4d1f081388a90b8d658cceceb996739634460a33 Mon Sep 17 00:00:00 2001 From: Oliver Schulz Date: Thu, 25 Jul 2024 11:51:12 +0200 Subject: [PATCH] Fix convert_numtype Didn't handle NamedTuples, should not convert integers. --- src/utils/array_utils.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/array_utils.jl b/src/utils/array_utils.jl index 082e7524f..c70f661a9 100644 --- a/src/utils/array_utils.jl +++ b/src/utils/array_utils.jl @@ -45,10 +45,14 @@ const SingleArrayIndex = Union{Integer, CartesianIndex} convert_numtype(::Type{T}, x::T) where {T<:Real} = x convert_numtype(::Type{T}, x::Real) where {T<:Real} = convert(T, x) +convert_numtype(::Type{T}, x::Integer) where {T<:AbstractFloat} = x convert_numtype(::Type{T}, x::AbstractArray{T}) where {T<:Real} = x convert_numtype(::Type{T}, x::AbstractArray{<:Real}) where {T<:Real} = convert.(T, x) +convert_numtype(::Type{T}, x::Tuple) where {T<:Real} = map(Base.Fix1(convert_numtype, T), x) +convert_numtype(::Type{T}, x::NamedTuple{names}) where {T<:Real, names} = NamedTuple{names}(convert_numtype(T, values(x))) + convert_numtype(::Type{T}, x::ArrayOfSimilarArrays{T}) where {T<:Real} = x convert_numtype(::Type{T}, x::ArrayOfSimilarArrays{<:Real,M,N}) where {T<:Real,M,N} = ArrayOfSimilarArrays{T,M,N}(convert_numtype(T, flatview(x)))