Skip to content

Commit

Permalink
Fix similar with Union{}
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHnt committed Dec 24, 2024
1 parent a543731 commit 5f40a1b
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,27 @@ struct MatMulMode{T} end
matmul_mode() = MatMulMode{:slow}()

# by-pass `similar` methods defined in array.jl
Base.similar(a::Array{T,1}) where {T<:RealOrComplexI} = zeros(T, size(a, 1))
Base.similar(a::Array{T,2}) where {T<:RealOrComplexI} = zeros(T, size(a, 1), size(a, 2))
Base.similar(a::Array{T,1}, S::Type) where {T<:RealOrComplexI} = zeros(S, size(a, 1))
Base.similar(a::Array{T,2}, S::Type) where {T<:RealOrComplexI} = zeros(S, size(a, 1), size(a, 2))
Base.similar(a::Array{T}, m::Int) where {T<:RealOrComplexI} = zeros(T, m)
Base.similar(a::Array{T}, S::Type, dims::Dims) where {T<:RealOrComplexI} = zeros(S, dims)
Base.similar(a::Array{T}, dims::Dims) where {T<:RealOrComplexI} = zeros(T, dims)
# note: written in this form to avoid by-passing the default behaviour for `Union{}`
Base.similar(a::Array{Interval{T},1}) where {T<:NumTypes} = zeros(Interval{T}, size(a, 1))
Base.similar(a::Array{Complex{Interval{T}},1}) where {T<:NumTypes} = zeros(Complex{Interval{T}}, size(a, 1))

Base.similar(a::Array{Interval{T},2}) where {T<:NumTypes} = zeros(T, size(a, 1), size(a, 2))
Base.similar(a::Array{Complex{Interval{T}},2}) where {T<:NumTypes} = zeros(T, size(a, 1), size(a, 2))

Base.similar(a::Array{Interval{T},1}, S::Type) where {T<:NumTypes} = zeros(S, size(a, 1))
Base.similar(a::Array{Complex{Interval{T}},1}, S::Type) where {T<:NumTypes} = zeros(S, size(a, 1))

Base.similar(a::Array{Interval{T},2}, S::Type) where {T<:NumTypes} = zeros(S, size(a, 1), size(a, 2))
Base.similar(a::Array{Complex{Interval{T}},2}, S::Type) where {T<:NumTypes} = zeros(S, size(a, 1), size(a, 2))

Base.similar(::Array{Interval{T}}, m::Int) where {T<:NumTypes} = zeros(T, m)
Base.similar(::Array{Complex{Interval{T}}}, m::Int) where {T<:NumTypes} = zeros(T, m)

Base.similar(::Array{Interval{T}}, S::Type, dims::Dims) where {T<:NumTypes} = zeros(S, dims)
Base.similar(::Array{Complex{Interval{T}}}, S::Type, dims::Dims) where {T<:NumTypes} = zeros(S, dims)

Base.similar(::Array{Interval{T}}, dims::Dims) where {T<:NumTypes} = zeros(T, dims)
Base.similar(::Array{Complex{Interval{T}}}, dims::Dims) where {T<:NumTypes} = zeros(T, dims)
#

function LinearAlgebra.mul!(C::AbstractVecOrMat{<:RealOrComplexI}, A::AbstractMatrix{<:RealOrComplexI}, B::AbstractVecOrMat{<:RealOrComplexI})
Expand Down

0 comments on commit 5f40a1b

Please sign in to comment.