Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FillArrays"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "0.11"
version = "0.11.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
16 changes: 11 additions & 5 deletions src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import Base.Broadcast: broadcasted, DefaultArrayStyle, broadcast_shape

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

if VERSION < v"1.6-"
oneto(n) = Base.OneTo(n)
else
import Base: oneto
end

"""
AbstractFill{T, N, Axes} <: AbstractArray{T, N}

Expand Down Expand Up @@ -100,7 +106,7 @@ Fill{T,0}(x::T, ::Tuple{}) where T = Fill{T,0,Tuple{}}(x, ()) # ambiguity fix
Fill{T,N}(convert(T, x)::T, sz)

@inline Fill{T, N}(x, sz::SZ) where SZ<:Tuple{Vararg{Integer,N}} where {T, N} =
Fill{T,N}(x, Base.OneTo.(sz))
Fill{T,N}(x, oneto.(sz))
@inline Fill{T, N}(x, sz::Vararg{Integer, N}) where {T, N} = Fill{T,N}(convert(T, x)::T, sz)


Expand Down Expand Up @@ -240,7 +246,7 @@ for (Typ, funcs, func) in ((:Zeros, :zeros, :zero), (:Ones, :ones, :one))


@inline $Typ{T, 0}(sz::Tuple{}) where {T} = $Typ{T,0,Tuple{}}(sz)
@inline $Typ{T, N}(sz::Tuple{Vararg{<:Integer, N}}) where {T, N} = $Typ{T,N}(Base.OneTo.(sz))
@inline $Typ{T, N}(sz::Tuple{Vararg{<:Integer, N}}) where {T, N} = $Typ{T,N}(oneto.(sz))
@inline $Typ{T, N}(sz::Vararg{<:Integer, N}) where {T, N} = $Typ{T,N}(sz)
""" `$($Typ){T}(dims...)` construct lazy version of `$($funcs)(dims...)`"""
@inline $Typ{T}(sz::Vararg{Integer,N}) where {T, N} = $Typ{T, N}(sz)
Expand Down Expand Up @@ -304,7 +310,7 @@ struct RectDiagonal{T,V<:AbstractVector{T},Axes<:Tuple{Vararg{AbstractUnitRange,
end
end

@inline RectDiagonal{T,V}(A::V, sz::Tuple{Vararg{Integer, 2}}) where {T,V} = RectDiagonal{T,V}(A, Base.OneTo.(sz))
@inline RectDiagonal{T,V}(A::V, sz::Tuple{Vararg{Integer, 2}}) where {T,V} = RectDiagonal{T,V}(A, oneto.(sz))
@inline RectDiagonal{T,V}(A::V, axes::Vararg{Any, 2}) where {T,V} = RectDiagonal{T,V}(A, axes)
@inline RectDiagonal{T,V}(A::V, sz::Vararg{Integer, 2}) where {T,V} = RectDiagonal{T,V}(A, sz)
@inline RectDiagonal{T,V}(A::V) where {T,V} = RectDiagonal{T,V}(A, (axes(A, 1), axes(A, 1)))
Expand Down Expand Up @@ -501,8 +507,8 @@ cumsum(x::AbstractFill{<:Any,1}) = range(getindex_value(x); step=getindex_value(

cumsum(x::Zeros{<:Any,1}) = x
cumsum(x::Zeros{Bool,1}) = x
cumsum(x::Ones{II,1}) where II<:Integer = Base.OneTo{II}(length(x))
cumsum(x::Ones{Bool,1}) = Base.OneTo{Int}(length(x))
cumsum(x::Ones{II,1}) where II<:Integer = convert(AbstractVector{II}, oneto(length(x)))
cumsum(x::Ones{Bool,1}) = oneto(length(x))
cumsum(x::AbstractFill{Bool,1}) = cumsum(convert(AbstractFill{Int}, x))


Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ end
@test_throws ArgumentError mut[2, 1] = 9

D = RectDiagonal([1.,2.], (Base.OneTo(3),Base.OneTo(2)))
@test stringmime("text/plain", D) == "3×2 RectDiagonal{Float64,Array{Float64,1},Tuple{Base.OneTo{$Int},Base.OneTo{$Int}}}:\n 1.0 ⋅ \n ⋅ 2.0\n ⋅ ⋅ "
if VERSION < v"1.6-"
@test stringmime("text/plain", D) == "3×2 RectDiagonal{Float64,Array{Float64,1},Tuple{Base.OneTo{$Int},Base.OneTo{$Int}}}:\n 1.0 ⋅ \n ⋅ 2.0\n ⋅ ⋅ "
else
@test stringmime("text/plain", D) == "3×2 RectDiagonal{Float64, Vector{Float64}, Tuple{Base.OneTo{$Int}, Base.OneTo{$Int}}}:\n 1.0 ⋅ \n ⋅ 2.0\n ⋅ ⋅ "
end
end

# Check that all pair-wise combinations of + / - elements of As and Bs yield the correct
Expand Down