Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
putianyi889 committed Dec 23, 2024
1 parent 64146df commit 7415215
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import LinearAlgebra: rank, svdvals!, tril, triu, tril!, triu!, diag, transpose,


import Base.Broadcast: broadcasted, DefaultArrayStyle, broadcast_shape, BroadcastStyle, Broadcasted
import EltypeExtensions: convert_eltype
import EltypeExtensions: convert_eltype, _to_eltype

export Zeros, Ones, Fill, Eye, Trues, Falses, OneElement

Expand Down Expand Up @@ -138,6 +138,8 @@ Fill{T,0}(x, ::Tuple{}) where T = Fill{T,0,Tuple{}}(convert(T, x)::T, ()) # ambi
""" `Fill(x, dims)` construct lazy version of `fill(x, dims)` """
@inline Fill(x::T, sz::Tuple{Vararg{Any,N}}) where {T, N} = Fill{T, N}(x, sz)

_to_eltype(::Type{T}, ::Type{Fill{V,N,Axes}}) where {T,V,N,Axes} = Fill{T,N,Axes}

# We restrict to when T is specified to avoid ambiguity with a Fill of a Fill
@inline Fill{T}(F::Fill{T}) where T = F
@inline Fill{T,N}(F::Fill{T,N}) where {T,N} = F
Expand Down Expand Up @@ -341,6 +343,7 @@ for (AbsTyp, Typ, funcs, func) in ((:AbstractZeros, :Zeros, :zeros, :zero), (:Ab
getindex(F::$AbsTyp{T,0}) where T = getindex_value(F)

promote_rule(::Type{$Typ{T, N, Axes}}, ::Type{$Typ{V, N, Axes}}) where {T,V,N,Axes} = $Typ{promote_type(T,V),N,Axes}
_to_eltype(::Type{T}, ::Type{$Typ{V,N,Axes}}) where {T,V,N,Axes} = $Typ{T,N,Axes}

Check warning on line 346 in src/FillArrays.jl

View check run for this annotation

Codecov / codecov/patch

src/FillArrays.jl#L346

Added line #L346 was not covered by tests
function convert(::Type{Typ}, A::$AbsTyp{V,N,Axes}) where {T,V,N,Axes,Typ<:$AbsTyp{T,N,Axes}}
convert(T, getindex_value(A)) # checks that the types are convertible
Typ(axes(A))
Expand Down
4 changes: 3 additions & 1 deletion src/fillalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ end
for TYPE in (:Array, :AbstractFill, :AbstractRange, :Diagonal)
@eval function +(a::$TYPE{T}, b::AbstractZeros{V}) where {T, V}
promote_shape(a,b)
return convert_eltype(promote_op(+,T,V),a)
ret = convert_eltype(promote_op(+,T,V), a)
ret a ? copy(ret) : ret # must return a copy
# (_to_eltype(promote_op(+,T,V), typeof(a)))(a) doesn't work for types not supporting such constructors. E.g. https://github.com/JuliaLang/LinearAlgebra.jl/pull/1158
end
@eval +(a::AbstractZeros, b::$TYPE) = b + a
end
Expand Down

0 comments on commit 7415215

Please sign in to comment.