Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero dimensional BlockIndex #431

Merged
merged 15 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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 .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
strategy:
fail-fast: false
matrix:
julia-version: ['1']
julia-version: ['1.11.0']
os: [ubuntu-latest]
package:
- {repo: BlockBandedMatrices.jl, group: JuliaLinearAlgebra}
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BlockArrays"
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
version = "1.1.1"
version = "1.2.0"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
7 changes: 4 additions & 3 deletions src/blockindices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@
iterate(x::Block) = (x, nothing)
iterate(x::Block, ::Any) = nothing
isempty(x::Block) = false
broadcastable(x::Block) = x
broadcastable(x::Block) = Ref(x)

Check warning on line 55 in src/blockindices.jl

View check run for this annotation

Codecov / codecov/patch

src/blockindices.jl#L55

Added line #L55 was not covered by tests
ndims(::Type{<:Block}) = 0
ndims(::Block) = 0
eltype(::Type{B}) where B<:Block = B
getindex(B::Block, ::CartesianIndex{0}) = B

# The following code is taken from CartesianIndex
@inline (+)(index::Block{N}) where {N} = Block{N}(map(+, index.n))
Expand Down Expand Up @@ -147,10 +146,12 @@
end

@inline BlockIndex(a::NTuple{N,Block{1}}, b::Tuple) where N = BlockIndex(Int.(a), b)
@inline BlockIndex(::Tuple{}, b::Tuple{}) = BlockIndex{0,Tuple{},Tuple{}}((), ())

Check warning on line 149 in src/blockindices.jl

View check run for this annotation

Codecov / codecov/patch

src/blockindices.jl#L149

Added line #L149 was not covered by tests

@inline BlockIndex(a::Integer, b::Integer) = BlockIndex((a,), (b,))
@inline BlockIndex(a::Tuple, b::Integer) = BlockIndex(a, (b,))
@inline BlockIndex(a::Integer, b::Tuple) = BlockIndex((a,), b)
@inline BlockIndex() = BlockIndex((), ())

Check warning on line 154 in src/blockindices.jl

View check run for this annotation

Codecov / codecov/patch

src/blockindices.jl#L154

Added line #L154 was not covered by tests

@inline BlockIndex(a::Block, b::Tuple) = BlockIndex(a.n, b)
@inline BlockIndex(a::Block, b::Integer) = BlockIndex(a, (b,))
Expand Down Expand Up @@ -202,7 +203,7 @@

block(R::BlockIndexRange) = R.block

getindex(::Block{0}) = Block()
getindex(::Block{0}) = BlockIndex()

Check warning on line 206 in src/blockindices.jl

View check run for this annotation

Codecov / codecov/patch

src/blockindices.jl#L206

Added line #L206 was not covered by tests
getindex(B::Block{N}, inds::Vararg{Integer,N}) where N = BlockIndex(B,inds)
getindex(B::Block{N}, inds::Vararg{AbstractUnitRange{<:Integer},N}) where N = BlockIndexRange(B,inds)
getindex(B::Block{1}, inds::Colon) = B
Expand Down
4 changes: 2 additions & 2 deletions test/test_blockarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ end
@test size(ret) == ()
@test all(iszero, ret)
@test ret[Block()] == zeros()
@test ret[Block()[]] == zeros()
@test ret[Block()[]] == 0
@test ret[] == 0
@test view(ret, Block()) == zeros()
@test Array(ret) == zeros()
Expand All @@ -360,7 +360,7 @@ end
@test all(iszero, ret)
@test ret[] == 0
@test ret[Block()] == zeros()
@test ret[Block()[]] == zeros()
@test ret[Block()[]] == 0
@test Array(ret) == zeros()
ret[] = 1
@test ret[] == 1
Expand Down
1 change: 1 addition & 0 deletions test/test_blockindices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice
end

@testset "BlockIndex" begin
@test Block()[] == BlockIndex()
@test Block(1)[1] == BlockIndex((1,),(1,))
@test Block(1)[1:2] == BlockIndexRange(Block(1),(1:2,))
@test Block(1,1)[1,1] == BlockIndex((1,1),(1,1)) == BlockIndex((1,1),(1,))
Expand Down
Loading