Skip to content

Commit

Permalink
Support converting Fills to StepRangeLen (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Aug 22, 2023
1 parent a718e2f commit 48f6157
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

2 comments on commit 48f6157

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/90099

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.6.0 -m "<description of version>" 48f615763e95f091780257d5c0018cfd045e5995
git push origin v1.6.0

Please sign in to comment.