From 88af5654340a50568f4938734fb26406044fdf24 Mon Sep 17 00:00:00 2001 From: Daniel VandenHeuvel <95613936+DanielVandH@users.noreply.github.com> Date: Thu, 27 Nov 2025 01:44:01 +0000 Subject: [PATCH 1/2] BroadcastStyle for Bidiagnal --- .gitignore | 1 + Project.toml | 2 +- src/LazyBandedMatrices.jl | 5 +++-- src/bidiag.jl | 3 ++- test/test_bidiag.jl | 12 +++++++++++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 339d277..8749cdb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ deps/deps.jl Manifest.toml .DS_Store +.vscode/settings.json diff --git a/Project.toml b/Project.toml index dfc6b36..58b1d66 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LazyBandedMatrices" uuid = "d7e5e226-e90b-4449-9968-0f923699bf6f" authors = ["Sheehan Olver "] -version = "0.11.7" +version = "0.11.8" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/LazyBandedMatrices.jl b/src/LazyBandedMatrices.jl index 141f89f..46f77fa 100644 --- a/src/LazyBandedMatrices.jl +++ b/src/LazyBandedMatrices.jl @@ -6,7 +6,7 @@ using BandedMatrices, BlockBandedMatrices, BlockArrays, LazyArrays, FillArrays, import Base: -, +, *, /, \, ==, AbstractMatrix, Matrix, Array, size, conj, real, imag, copy, copymutable, iszero, isone, one, zero, getindex, setindex!, copyto!, fill, fill!, promote_rule, show, print_matrix, permutedims, OneTo, oneto, require_one_based_indexing, similar, convert, axes, tail, tuple_type_tail, view, resize! -import Base.Broadcast: Broadcasted, BroadcastStyle, broadcasted, instantiate +import Base.Broadcast: Broadcasted, BroadcastStyle, broadcasted, instantiate, result_style import LinearAlgebra: transpose, adjoint, istriu, istril, isdiag, tril!, triu!, det, logabsdet, symmetric, symmetric_type, diag, issymmetric, UniformScaling, char_uplo, AbstractTriangular, AdjOrTrans, StructuredMatrixStyle, Diagonal @@ -17,7 +17,8 @@ import ArrayLayouts: MemoryLayout, bidiagonallayout, bidiagonaluplo, diagonaldat materialize!, MulAdd, MatMulVecAdd import LazyArrays: ApplyLayout, AbstractPaddedLayout, PaddedLayout, PaddedColumns, BroadcastLayout, LazyArrayStyle, LazyLayout, arguments, call, tuple_type_memorylayouts, paddeddata, _broadcast_sub_arguments, resizedata!, - _cumsum, convexunion, applylayout, AbstractLazyBandedLayout, ApplyBandedLayout, BroadcastBandedLayout, LazyBandedLayout, applied_eltype + _cumsum, convexunion, applylayout, AbstractLazyBandedLayout, ApplyBandedLayout, BroadcastBandedLayout, LazyBandedLayout, applied_eltype, + CachedArrayStyle import BandedMatrices: AbstractBandedMatrix, BandedStyle, bandwidths, isbanded import BlockBandedMatrices: AbstractBlockBandedLayout, AbstractBandedBlockBandedLayout, BlockRange1, Block1, blockbandwidths, subblockbandwidths, BlockBandedStyle, BandedBlockBandedStyle, isblockbanded, isbandedblockbanded diff --git a/src/bidiag.jl b/src/bidiag.jl index 10d588d..59a3377 100644 --- a/src/bidiag.jl +++ b/src/bidiag.jl @@ -188,7 +188,8 @@ similar(B::Bidiagonal, ::Type{T}) where {T} = Bidiagonal(similar(B.dv, T), simil # The method below is moved to SparseArrays for now # similar(B::Bidiagonal, ::Type{T}, dims::Union{Dims{1},Dims{2}}) where {T} = spzeros(T, dims...) - +# Broadcasting +BroadcastStyle(::Type{<:Bidiagonal{<:Any, DV, EV}}) where {DV, EV} = result_style(BandedStyle(), result_style(BroadcastStyle(DV), BroadcastStyle(EV))) #################### # Generic routines # diff --git a/test/test_bidiag.jl b/test/test_bidiag.jl index 685e3df..ed303c9 100644 --- a/test/test_bidiag.jl +++ b/test/test_bidiag.jl @@ -1,11 +1,14 @@ module TestBidiag # This file is based on a part of Julia LinearAlgebra/test/bidiag.jl. License is MIT: https://julialang.org/license -using Test, LazyBandedMatrices, SparseArrays, Random, FillArrays +using Test, LazyBandedMatrices, SparseArrays, Random, FillArrays, LazyArrays, BandedMatrices import LazyBandedMatrices: Bidiagonal, SymTridiagonal, Tridiagonal import LinearAlgebra import LinearAlgebra: mul!, istril, istriu, diagm, isdiag, triu, tril, triu!, tril!, diag, UpperTriangular, LowerTriangular, UnitLowerTriangular, UnitUpperTriangular, dot, Diagonal +import LazyArrays: CachedArrayStyle +import Base.Broadcast: BroadcastStyle +import BandedMatrices: BandedStyle @testset "Bidiagonal" begin n = 10 #Size of test matrix @@ -488,6 +491,13 @@ import LinearAlgebra: mul!, istril, istriu, diagm, isdiag, triu, tril, triu!, tr @test B.dv ≡ 1:5 @test B.ev ≡ Ones{Int}(4) end + + @testset "BroadcastStyle" begin + @test BroadcastStyle(typeof(Bidiagonal(1:3, 1:2, :U))) == BandedStyle() + @test BroadcastStyle(typeof(Bidiagonal(1:3, Accumulate(*, 1:2), :L))) == CachedArrayStyle{2}() + @test BroadcastStyle(typeof(Bidiagonal(Accumulate(*, 1:3), Accumulate(*, 1:2), :U))) == CachedArrayStyle{2}() + @test BroadcastStyle(typeof(Bidiagonal(Accumulate(*, 1:3), 1:2, :L))) == CachedArrayStyle{2}() + end end # testset end # module TestBidiagonal From 8d2a686f3970b6adf6ffe4a7fd7fb5ca37d145a5 Mon Sep 17 00:00:00 2001 From: Daniel VandenHeuvel <95613936+DanielVandH@users.noreply.github.com> Date: Thu, 27 Nov 2025 08:07:32 +0000 Subject: [PATCH 2/2] Minimum version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 58b1d66..67bc72e 100644 --- a/Project.toml +++ b/Project.toml @@ -28,7 +28,7 @@ BlockArrays = "1.0" BlockBandedMatrices = "0.13" FillArrays = "1.0" InfiniteArrays = "0.15" -LazyArrays = "2.8" +LazyArrays = "2.9.3" MatrixFactorizations = "3.0" StaticArrays = "1.0" julia = "1.10"