diff --git a/Project.toml b/Project.toml index 79dc748..c3c6ffd 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "InfiniteArrays" uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c" -version = "0.15.10" +version = "0.15.11" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" @@ -33,7 +33,7 @@ BlockBandedMatrices = "0.13" DSP = "0.7, 0.8" FillArrays = "1.0" Infinities = "0.1.1" -LazyArrays = "2.2.3" +LazyArrays = "2.9.3" LinearAlgebra = "1.6" SparseArrays = "1.0" Statistics = "1.0" diff --git a/ext/InfiniteArraysBandedMatricesExt.jl b/ext/InfiniteArraysBandedMatricesExt.jl index bc008a0..9c67792 100644 --- a/ext/InfiniteArraysBandedMatricesExt.jl +++ b/ext/InfiniteArraysBandedMatricesExt.jl @@ -3,10 +3,10 @@ using InfiniteArrays, BandedMatrices, LinearAlgebra using InfiniteArrays.LazyArrays, InfiniteArrays.ArrayLayouts, InfiniteArrays.FillArrays import Base: BroadcastStyle, size, getindex, similar, copy, *, +, -, /, \, materialize!, copyto!, OneTo -import Base.Broadcast: Broadcasted +import Base.Broadcast: Broadcasted, result_style import InfiniteArrays: InfIndexRanges, Infinity, PosInfinity, OneToInf, InfAxes, AbstractInfUnitRange, InfRanges, InfBaseToeplitzLayouts, ConstRowMatrix, PertConstRowMatrix, SymTriPertToeplitz, TriPertToeplitz, ConstRows, PertConstRows, PertTridiagonalToeplitzLayout import ArrayLayouts: sub_materialize, MemoryLayout, sublayout, mulreduce, triangularlayout, MatLdivVec, subdiagonaldata, diagonaldata, supdiagonaldata, OnesLayout, _copy_oftype -import LazyArrays: applybroadcaststyle, applylayout, islazy, islazy_layout, simplifiable, AbstractLazyLayout, PaddedColumns, LazyArrayStyle, ApplyLayout, AbstractLazyBandedLayout, ApplyBandedLayout, BroadcastBandedLayout +import LazyArrays: applybroadcaststyle, applylayout, islazy, islazy_layout, simplifiable, AbstractLazyLayout, PaddedColumns, LazyArrayStyle, ApplyLayout, AbstractLazyBandedLayout, ApplyBandedLayout, BroadcastBandedLayout, CachedArrayStyle, AbstractLazyArrayStyle import BandedMatrices: _BandedMatrix, AbstractBandedMatrix, banded_similar, BandedMatrix, bandedcolumns, BandedColumns, bandeddata, _default_banded_broadcast import FillArrays: AbstractFillMatrix, AbstractFill, getindex_value @@ -26,9 +26,11 @@ InfBandCartesianIndices(b::Band) = InfBandCartesianIndices(b.i) size(::InfBandCartesianIndices) = (∞,) getindex(B::InfBandCartesianIndices, k::Int) = B.b ≥ 0 ? CartesianIndex(k, k+B.b) : CartesianIndex(k-B.b, k) + Base.checkindex(::Type{Bool}, ::NTuple{2,OneToInf{Int}}, ::InfBandCartesianIndices) = true BandedMatrices.band_to_indices(_, ::NTuple{2,OneToInf{Int}}, b) = (InfBandCartesianIndices(b),) -BroadcastStyle(::Type{<:SubArray{<:Any,1,<:Any,Tuple{InfBandCartesianIndices}}}) = LazyArrayStyle{1}() +_lower_style_dim(::Sty) where {Sty} = Sty(Val(1)) +BroadcastStyle(::Type{<:SubArray{<:Any,1,P,Tuple{InfBandCartesianIndices}}}) where {P} = _lower_style_dim(result_style(LazyArrayStyle{1}(), BroadcastStyle(P))) _inf_banded_sub_materialize(_, V) = V function _inf_banded_sub_materialize(::BandedColumns, V) @@ -296,6 +298,7 @@ for Typ in (:ConstRows, :PertConstRows) @eval begin sublayout(::$Typ, ::Type{<:Tuple{Any,AbstractInfUnitRange{Int}}}) = $Typ() # no way to lose const rows applybroadcaststyle(::Type{<:AbstractMatrix}, ::$Typ) = LazyArrayStyle{2}() + applybroadcaststyle(::Type{<:ApplyMatrix{<:Any, <:Any, Args}}, ::$Typ) where {Args<:Tuple} = LazyArrayStyle{2}() # ambiguity applylayout(::Type, ::$Typ, _...) = LazyLayout() end end diff --git a/test/test_infbanded.jl b/test/test_infbanded.jl index a632a3a..331e263 100644 --- a/test/test_infbanded.jl +++ b/test/test_infbanded.jl @@ -4,7 +4,8 @@ import InfiniteArrays: TridiagonalToeplitzLayout, BidiagonalToeplitzLayout, TriP TriToeplitz, ConstRows, SymTriPertToeplitz, AdjTriPertToeplitz, subdiagonalconstant, diagonalconstant, supdiagonalconstant, PertTridiagonalToeplitzLayout using Base: oneto -using LazyArrays: simplifiable, ApplyLayout, BroadcastBandedLayout, islazy +using LazyArrays: simplifiable, ApplyLayout, CachedArrayStyle, LazyArrayStyle, BroadcastBandedLayout, islazy +import Base.Broadcast: BroadcastStyle const InfiniteArraysBandedMatricesExt = Base.get_extension(InfiniteArrays, :InfiniteArraysBandedMatricesExt) const InfToeplitz = InfiniteArraysBandedMatricesExt.InfToeplitz @@ -40,6 +41,7 @@ const InfBandCartesianIndices = InfiniteArraysBandedMatricesExt.InfBandCartesian @test (B*A*x)[1:10] == [0; 10; 14; 12; zeros(6)] @test _BandedMatrix((1:∞)', ∞, -1, 1) isa BandedMatrix + end @testset "∞-Toeplitz" begin @@ -380,4 +382,13 @@ const InfBandCartesianIndices = InfiniteArraysBandedMatricesExt.InfBandCartesian A = BandedMatrix(1 => Fill(2im,∞), 2 => Fill(-1,∞), 3 => Fill(2,∞), -2 => Fill(-4,∞), -3 => Fill(-2im,∞)) @test copy(Base.broadcasted(BandedMatrices.BandedStyle(), exp,A))[1:10,1:10] == exp.(A[1:10,1:10]) end + + @testset "BroadcastStyle with InfBandCartesianIndices" begin + A = BandedMatrix(1 => Fill(2im,∞), 2 => Fill(-1,∞), 3 => Fill(2,∞), -2 => Fill(-4,∞), -3 => Fill(-2im,∞)) + B = view(A, band(0)) + @test BroadcastStyle(typeof(B)) == LazyArrayStyle{1}() + A = BandedMatrix(1 => Fill(2im,∞), 2 => cache(Fill(-1,∞)), 3 => Fill(2,∞), -2 => Fill(-4,∞), -3 => Fill(-2im,∞)) + B = view(A, band(0)) + @test BroadcastStyle(typeof(B)) == CachedArrayStyle{1}() + end end