Skip to content

Commit

Permalink
Support converting Fills to StepRangeLen
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Aug 22, 2023
1 parent a718e2f commit 9e98677
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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 = "1.5.0"
version = "1.6.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
3 changes: 3 additions & 0 deletions src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,9 @@ function convert(::Type{T}, A::AbstractFillMatrix) where T<:Diagonal
isdiag(A) ? T(A) : throw(InexactError(:convert, T, A))
end

Base.StepRangeLen(F::AbstractFillVector{T}) where T = StepRangeLen(getindex_value(F), zero(T), length(F))
convert(::Type{SL}, F::AbstractFillVector) where SL<:AbstractRange = convert(SL, StepRangeLen(F))

#################
# Structured matrix types
#################
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ end
@test A[1,:,1] A[1,1:6,1] Fill(2.0,6)
@test A[:,:,:] A[1:5,1:6,1:7] A[1:5,:,1:7] A[:,1:6,1:7] A
end

@testset "StepRangeLen convert" begin
for (z,s) in ((Zeros{Int}(5), StepRangeLen(0, 0, 5)), (Ones{Int}(5), StepRangeLen(1, 0, 5)), (Fill(2,5), StepRangeLen(2, 0, 5)))
@test s == z
@test StepRangeLen(z) convert(StepRangeLen, z) convert(StepRangeLen{Int}, z) convert(typeof(s), z) convert(AbstractRange, z) s
end
end
end

@testset "RectDiagonal" begin
Expand Down

0 comments on commit 9e98677

Please sign in to comment.