Skip to content

Commit 1179e7d

Browse files
authored
Add more Fill convert methods (#120)
1 parent 24d79d3 commit 1179e7d

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FillArrays"
22
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
3-
version = "0.9.6"
3+
version = "0.9.7"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/FillArrays.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ struct Fill{T, N, Axes} <: AbstractFill{T, N, Axes}
8989
Fill{T,0,Tuple{}}(x::T, sz::Tuple{}) where T = new{T,0,Tuple{}}(x,sz)
9090
end
9191

92+
Fill{T,N,Axes}(x, sz::Axes) where Axes<:Tuple{Vararg{AbstractUnitRange,N}} where {T, N} =
93+
Fill{T,N,Axes}(convert(T, x)::T, sz)
94+
9295
Fill{T,0}(x::T, ::Tuple{}) where T = Fill{T,0,Tuple{}}(x, ()) # ambiguity fix
9396

9497
@inline Fill{T, N}(x::T, sz::Axes) where Axes<:Tuple{Vararg{AbstractUnitRange,N}} where {T, N} =
@@ -147,6 +150,8 @@ end
147150
unique_value(f::AbstractFill) = getindex_value(f)
148151
convert(::Type{Fill}, arr::AbstractArray{T}) where T = Fill{T}(unique_value(arr), axes(arr))
149152
convert(::Type{Fill{T}}, arr::AbstractArray) where T = Fill{T}(unique_value(arr), axes(arr))
153+
convert(::Type{Fill{T,N}}, arr::AbstractArray{<:Any,N}) where {T,N} = Fill{T,N}(unique_value(arr), axes(arr))
154+
convert(::Type{Fill{T,N,Axes}}, arr::AbstractArray{<:Any,N}) where {T,N,Axes} = Fill{T,N,Axes}(unique_value(arr), axes(arr))
150155
convert(::Type{T}, F::T) where T<:Fill = F # ambiguity fix
151156

152157

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import FillArrays: AbstractFill, RectDiagonal, SquareEye
4242
@test convert(Fill, Float64[1,1,1]) Fill(1.0, 3)
4343
@test convert(Fill{Float64}, Fill(1.0,2)) Fill(1.0, 2) # was ambiguous
4444
@test convert(Fill{Int}, Ones(20)) Fill(1, 20)
45+
@test convert(Fill{Int,1}, Ones(20)) Fill(1, 20)
46+
@test convert(Fill{Int,1,Tuple{Base.OneTo{Int}}}, Ones(20)) Fill(1, 20)
4547

4648
@test $Typ{T,2}(2ones(T,5,5)) $Typ{T}(5,5)
4749
@test $Typ{T}(2ones(T,5,5)) $Typ{T}(5,5)

0 commit comments

Comments
 (0)