Skip to content

Commit

Permalink
Fix convert_numtype
Browse files Browse the repository at this point in the history
Didn't handle NamedTuples, should not convert integers.
  • Loading branch information
oschulz committed Jul 25, 2024
1 parent 9ed9730 commit 4d1f081
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/utils/array_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

2 comments on commit 4d1f081

@oschulz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/111788

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.2.1 -m "<description of version>" 4d1f081388a90b8d658cceceb996739634460a33
git push origin v3.2.1

Please sign in to comment.