From bf6f80b2ae012a387f278cfd4481c96807cf9db7 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Fri, 22 Nov 2024 11:59:49 -0500 Subject: [PATCH 1/8] Zero dimensional `BlockIndex` (#431) * Zero dimensional `BlockIndex` --------- Co-authored-by: Sheehan Olver --- Project.toml | 2 +- src/blockindices.jl | 7 ++++--- test/test_blockarrays.jl | 4 ++-- test/test_blockindices.jl | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 48f106a1..acbb824d 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/blockindices.jl b/src/blockindices.jl index f00f54a0..a5b5119e 100644 --- a/src/blockindices.jl +++ b/src/blockindices.jl @@ -52,11 +52,10 @@ last(b::Block) = b iterate(x::Block) = (x, nothing) iterate(x::Block, ::Any) = nothing isempty(x::Block) = false -broadcastable(x::Block) = x +broadcastable(x::Block) = Ref(x) 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)) @@ -147,10 +146,12 @@ struct BlockIndex{N,TI<:Tuple{Vararg{Integer,N}},Tα<:Tuple{Vararg{Integer,N}}} 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{}}((), ()) @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((), ()) @inline BlockIndex(a::Block, b::Tuple) = BlockIndex(a.n, b) @inline BlockIndex(a::Block, b::Integer) = BlockIndex(a, (b,)) @@ -202,7 +203,7 @@ BlockIndexRange(block::Block{N}, inds::Vararg{AbstractUnitRange{<:Integer},N}) w block(R::BlockIndexRange) = R.block -getindex(::Block{0}) = Block() +getindex(::Block{0}) = BlockIndex() 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 diff --git a/test/test_blockarrays.jl b/test/test_blockarrays.jl index f6ff21a4..d24fb52e 100644 --- a/test/test_blockarrays.jl +++ b/test/test_blockarrays.jl @@ -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() @@ -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 diff --git a/test/test_blockindices.jl b/test/test_blockindices.jl index d14ce4d2..d6e4b67b 100644 --- a/test/test_blockindices.jl +++ b/test/test_blockindices.jl @@ -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,)) From 5e08961a54f69aee962cccc967d8ce4a45a3a31b Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Wed, 27 Nov 2024 12:28:37 +0530 Subject: [PATCH 2/8] `file` -> `files` in CI codecov step (#434) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0cea964f..f7d6d998 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,4 +66,4 @@ jobs: - uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} - file: lcov.info + files: lcov.info From a62bd8e6518a45c81b0e715add60d5be9f8f0d98 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Mon, 2 Dec 2024 17:23:49 +0530 Subject: [PATCH 3/8] Limit julia compat to v1.10 --- Project.toml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index acbb824d..2cf42475 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BlockArrays" uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" -version = "1.2.0" +version = "1.3.0" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" @@ -21,13 +21,13 @@ BandedMatrices = "1.0" Documenter = "1.0" FillArrays = "1.11" Images = "0.26" -LinearAlgebra = "1.6" +LinearAlgebra = "1" OffsetArrays = "1.0" -Random = "1.6" -SparseArrays = "1.6" -StaticArrays = "1.6" -Test = "1.6" -julia = "1.6" +Random = "1" +SparseArrays = "1" +StaticArrays = "1" +Test = "1" +julia = "1.10" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" From 44ce47205a4ae2e22142a03625095e2cd9d3387f Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 3 Dec 2024 13:12:39 +0530 Subject: [PATCH 4/8] Pass a command line flag to downstream tests (#435) The command line flag `--downstream_integration_test` that is passed to the downstream test will allow us to selectively skip tests that might not be necessary. In particular, the Aqua test for stale dependencies is unnecessary in downstream tests if we want to test package extensions. We also reinstate the test against `InfiniteLinearAlgebra` in this PR, which was commented out. --- .github/workflows/downstream.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/downstream.yml b/.github/workflows/downstream.yml index fb9bb7e5..a0a1cbe1 100644 --- a/.github/workflows/downstream.yml +++ b/.github/workflows/downstream.yml @@ -38,7 +38,7 @@ jobs: - {repo: ApproxFunBase.jl, group: JuliaApproximation} - {repo: LazyArrays.jl, group: JuliaArrays} - {repo: LazyBandedMatrices.jl, group: JuliaLinearAlgebra} - # - {repo: InfiniteLinearAlgebra.jl, group: JuliaLinearAlgebra} + - {repo: InfiniteLinearAlgebra.jl, group: JuliaLinearAlgebra} steps: - uses: actions/checkout@v4 @@ -60,7 +60,7 @@ jobs: # force it to use this PR's version of the package Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps Pkg.update() - Pkg.test() # resolver may fail with test time deps + Pkg.test(test_args=["--downstream_integration_test"]) # resolver may fail with test time deps catch err err isa Pkg.Resolve.ResolverError || rethrow() # If we can't resolve that means this is incompatible by SemVer and this is fine From 642f90915a34dfeec1c53511ef0165c62ab1024c Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 3 Dec 2024 13:33:11 +0530 Subject: [PATCH 5/8] Skip Aqua stale deps check in downstream tests (#436) --- test/runtests.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index f6ce9823..8a87e547 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,10 @@ using BlockArrays, LinearAlgebra, Test using Aqua +downstream_test = "--downstream_integration_test" in ARGS @testset "Project quality" begin - Aqua.test_all(BlockArrays, ambiguities=false) + Aqua.test_all(BlockArrays, ambiguities=false, + stale_deps=!downstream_test) end using Documenter From def5e59644a2812fdd985483f76a1263af398730 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 3 Dec 2024 14:36:08 +0530 Subject: [PATCH 6/8] Inline blocksizes for better type-inference (#429) --- src/blocks.jl | 2 +- test/test_blocks.jl | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/blocks.jl b/src/blocks.jl index 711a182a..b87550ca 100644 --- a/src/blocks.jl +++ b/src/blocks.jl @@ -125,7 +125,7 @@ julia> blocksizes(A,2) ``` """ blocksizes(A::AbstractArray) = BlockSizes(A) -blocksizes(A::AbstractArray, d::Integer) = blocklengths(axes(A, d)) +@inline blocksizes(A::AbstractArray, d::Integer) = blocklengths(axes(A, d)) struct BlockSizes{T,N,A<:AbstractArray{<:Any,N}} <: AbstractArray{T,N} array::A diff --git a/test/test_blocks.jl b/test/test_blocks.jl index 9a636bf9..3ad25e64 100644 --- a/test/test_blocks.jl +++ b/test/test_blocks.jl @@ -127,6 +127,14 @@ end @test blocksizes(A, 1) == [2, 3] @test blocksizes(A, 2) == [3, 1] end + + @testset "Inference: issue #425" begin + x = BlockedArray(rand(4, 4), [2, 2], [2, 2]) + bs1 = @inferred (x -> blocksizes(x, 1))(x) + @test bs1 == [2,2] + bs4 = @inferred (x -> blocksizes(x, 4))(x) + @test bs4 == 1:1 + end end end # module From 1f84243fe68a85bfb322621ba0a7bbbb889bec8a Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 3 Dec 2024 16:22:48 +0530 Subject: [PATCH 7/8] Remove extension loading code for older julia versions (#437) --- src/BlockArrays.jl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/BlockArrays.jl b/src/BlockArrays.jl index 58fa689b..15341192 100644 --- a/src/BlockArrays.jl +++ b/src/BlockArrays.jl @@ -78,8 +78,4 @@ include("blockbanded.jl") @deprecate getblock!(X, A::AbstractBlockArray{T,N}, I::Vararg{Integer, N}) where {T,N} copyto!(X, view(A, Block(I))) @deprecate setblock!(A::AbstractBlockArray{T,N}, v, I::Vararg{Integer, N}) where {T,N} (A[Block(I...)] = v) -if !isdefined(Base, :get_extension) - include("../ext/BlockArraysBandedMatricesExt.jl") -end - end # module From cc46573ff980b2b843053ffe397940853b591d8d Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 3 Dec 2024 16:28:56 +0530 Subject: [PATCH 8/8] Don't specify arch in ci matrix (#438) --- .github/workflows/ci.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7d6d998..0f711b3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: test: needs: pre_job if: needs.pre_job.outputs.should_skip != 'true' - name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ github.event_name }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -42,14 +42,11 @@ jobs: - ubuntu-latest - macOS-latest - windows-latest - arch: - - x64 steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.version }} - arch: ${{ matrix.arch }} - uses: actions/cache@v4 env: cache-name: cache-artifacts