Skip to content

Finite sections of JacobiTriangle Jacobi matrices are ApplyArrays instead of BandedBlockBandedMatrices #216

Open

Description

@MikaelSlevinsky

I don't think this used to be the case.

julia> jacobimatrix(Val(1), RectPolynomial(ChebyshevT(), ChebyshevT()))[Block.(1:5), Block.(1:5)]
5×5-blocked 15×15 BandedBlockBandedMatrix{Float64} with block-bandwidths (1, 1) and sub-block-bandwidths block-bandwidths (0, 0) with data 3×5-blocked 3×15 BlockedMatrix{Float64}:
 0.0  │  0.5   ⋅   │   ⋅    ⋅    ⋅   │   ⋅    ⋅    ⋅    ⋅   │   ⋅    ⋅    ⋅    ⋅    ⋅ 
 ─────┼────────────┼─────────────────┼──────────────────────┼─────────────────────────
 1.0  │  0.0   ⋅   │  0.5   ⋅    ⋅   │   ⋅    ⋅    ⋅    ⋅   │   ⋅    ⋅    ⋅    ⋅    ⋅ 
  ⋅   │   ⋅   0.0  │   ⋅   0.5   ⋅   │   ⋅    ⋅    ⋅    ⋅   │   ⋅    ⋅    ⋅    ⋅    ⋅ 
 ─────┼────────────┼─────────────────┼──────────────────────┼─────────────────────────
  ⋅   │  0.5   ⋅   │  0.0   ⋅    ⋅   │  0.5   ⋅    ⋅    ⋅   │   ⋅    ⋅    ⋅    ⋅    ⋅ 
  ⋅   │   ⋅   1.0  │   ⋅   0.0   ⋅   │   ⋅   0.5   ⋅    ⋅   │   ⋅    ⋅    ⋅    ⋅    ⋅ 
  ⋅   │   ⋅    ⋅   │   ⋅    ⋅   0.0  │   ⋅    ⋅   0.5   ⋅   │   ⋅    ⋅    ⋅    ⋅    ⋅ 
 ─────┼────────────┼─────────────────┼──────────────────────┼─────────────────────────
  ⋅   │   ⋅    ⋅   │  0.5   ⋅    ⋅   │  0.0   ⋅    ⋅    ⋅   │  0.5   ⋅    ⋅    ⋅    ⋅ 
  ⋅   │   ⋅    ⋅   │   ⋅   0.5   ⋅   │   ⋅   0.0   ⋅    ⋅   │   ⋅   0.5   ⋅    ⋅    ⋅ 
  ⋅   │   ⋅    ⋅   │   ⋅    ⋅   1.0  │   ⋅    ⋅   0.0   ⋅   │   ⋅    ⋅   0.5   ⋅    ⋅ 
  ⋅   │   ⋅    ⋅   │   ⋅    ⋅    ⋅   │   ⋅    ⋅    ⋅   0.0  │   ⋅    ⋅    ⋅   0.5   ⋅ 
 ─────┼────────────┼─────────────────┼──────────────────────┼─────────────────────────
  ⋅   │   ⋅    ⋅   │   ⋅    ⋅    ⋅   │  0.5   ⋅    ⋅    ⋅   │  0.0   ⋅    ⋅    ⋅    ⋅ 
  ⋅   │   ⋅    ⋅   │   ⋅    ⋅    ⋅   │   ⋅   0.5   ⋅    ⋅   │   ⋅   0.0   ⋅    ⋅    ⋅ 
  ⋅   │   ⋅    ⋅   │   ⋅    ⋅    ⋅   │   ⋅    ⋅   0.5   ⋅   │   ⋅    ⋅   0.0   ⋅    ⋅ 
  ⋅   │   ⋅    ⋅   │   ⋅    ⋅    ⋅   │   ⋅    ⋅    ⋅   1.0  │   ⋅    ⋅    ⋅   0.0   ⋅ 
  ⋅   │   ⋅    ⋅   │   ⋅    ⋅    ⋅   │   ⋅    ⋅    ⋅    ⋅   │   ⋅    ⋅    ⋅    ⋅   0.0

julia> typeof(ans)
BlockBandedMatrices.BandedBlockBandedMatrix{Float64, BlockedMatrix{Float64, Matrix{Float64}, Tuple{BlockedOneTo{Int64, StepRangeLen{Int64, Int64, Int64, Int64}}, BlockedOneTo{Int64, Vector{Int64}}}}, BlockedOneTo{Int64, Vector{Int64}}}

julia> jacobimatrix(Val(1), JacobiTriangle())[Block.(1:5), Block.(1:5)]
(5×5-blocked 15×15 BandedBlockBandedMatrix{Float64} with block-bandwidths (1, 0) and sub-block-bandwidths block-bandwidths (0, 0) with data 2×5-blocked 2×15 BlockVcat{Float64}) * (5×5-blocked 15×15 BandedBlockBandedMatrix{Float64} with block-bandwidths (0, 1) and sub-block-bandwidths block-bandwidths (0, 0) with data 2×5-blocked 2×15 BlockVcat{Float64}) with indices BlockedOneTo([1, 3, 6, 10, 15])×BlockedOneTo([1, 3, 6, 10, 15]):
 0.333333  │  0.166667   ⋅   │   ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅          ⋅       
 ──────────┼─────────────────┼────────────────────────────────┼──────────────────────────────────────────┼────────────────────────────────────────────────────
 0.333333  │  0.466667   ⋅   │  0.2        ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅          ⋅       
  ⋅        │   ⋅        0.2  │   ⋅        0.133333   ⋅        │   ⋅         ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅          ⋅       
 ──────────┼─────────────────┼────────────────────────────────┼──────────────────────────────────────────┼────────────────────────────────────────────────────
  ⋅        │  0.3        ⋅   │  0.485714   ⋅         ⋅        │  0.214286   ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅          ⋅       
  ⋅        │   ⋅        0.2  │   ⋅        0.371429   ⋅        │   ⋅        0.178571   ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅          ⋅       
  ⋅        │   ⋅         ⋅   │   ⋅         ⋅        0.142857  │   ⋅         ⋅        0.107143   ⋅        │   ⋅         ⋅         ⋅         ⋅          ⋅       
 ──────────┼─────────────────┼────────────────────────────────┼──────────────────────────────────────────┼────────────────────────────────────────────────────
  ⋅        │   ⋅         ⋅   │  0.285714   ⋅         ⋅        │  0.492063   ⋅         ⋅         ⋅        │  0.222222   ⋅         ⋅         ⋅          ⋅       
  ⋅        │   ⋅         ⋅   │   ⋅        0.238095   ⋅        │   ⋅        0.428571   ⋅         ⋅        │   ⋅        0.2        ⋅         ⋅          ⋅       
  ⋅        │   ⋅         ⋅   │   ⋅         ⋅        0.142857  │   ⋅         ⋅        0.301587   ⋅        │   ⋅         ⋅        0.155556   ⋅          ⋅       
  ⋅        │   ⋅         ⋅   │   ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅        0.111111  │   ⋅         ⋅         ⋅        0.0888889   ⋅       
 ──────────┼─────────────────┼────────────────────────────────┼──────────────────────────────────────────┼────────────────────────────────────────────────────
  ⋅        │   ⋅         ⋅   │   ⋅         ⋅         ⋅        │  0.277778   ⋅         ⋅         ⋅        │  0.494949   ⋅         ⋅         ⋅          ⋅       
  ⋅        │   ⋅         ⋅   │   ⋅         ⋅         ⋅        │   ⋅        0.25       ⋅         ⋅        │   ⋅        0.454545   ⋅         ⋅          ⋅       
  ⋅        │   ⋅         ⋅   │   ⋅         ⋅         ⋅        │   ⋅         ⋅        0.194444   ⋅        │   ⋅         ⋅        0.373737   ⋅          ⋅       
  ⋅        │   ⋅         ⋅   │   ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅        0.111111  │   ⋅         ⋅         ⋅        0.252525    ⋅       
  ⋅        │   ⋅         ⋅   │   ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅         0.0909091

julia> typeof(ans)
LazyArrays.ApplyArray{Float64, 2, typeof(*), Tuple{BlockBandedMatrices.BandedBlockBandedMatrix{Float64, LazyBandedMatrices.BlockVcat{Float64, 2, Tuple{Adjoint{Float64, BlockVector{Float64, Vector{Vector{Float64}}, Tuple{BlockedOneTo{Int64, Vector{Int64}}}}}, Adjoint{Float64, BlockVector{Float64, Vector{Vector{Float64}}, Tuple{BlockedOneTo{Int64, Vector{Int64}}}}}}, Tuple{BlockedOneTo{Int64, StaticArraysCore.SVector{2, Int64}}, BlockedOneTo{Int64, Vector{Int64}}}}, BlockedOneTo{Int64, Vector{Int64}}}, BlockBandedMatrices.BandedBlockBandedMatrix{Float64, LazyBandedMatrices.BlockVcat{Float64, 2, Tuple{Adjoint{Float64, BlockVector{Float64, Vector{Vector{Float64}}, Tuple{BlockedOneTo{Int64, Vector{Int64}}}}}, Adjoint{Float64, BlockVector{Float64, Vector{Vector{Float64}}, Tuple{BlockedOneTo{Int64, Vector{Int64}}}}}}, Tuple{BlockedOneTo{Int64, StaticArraysCore.SVector{2, Int64}}, BlockedOneTo{Int64, Vector{Int64}}}}, BlockedOneTo{Int64, Vector{Int64}}}}}

Activity

  1. dlfivefifty commented on Mar 26, 2026

    @dlfivefifty
    Member

    Does this matter in practice? You can always convert explicitly:

    julia> @time BandedBlockBandedMatrix(jacobimatrix(Val(1), JacobiTriangle())[Block.(1:5), Block.(1:5)])
      0.000032 seconds (425 allocations: 23.297 KiB)
    5×5-blocked 15×15 BandedBlockBandedMatrix{Float64} with block-bandwidths (1, 1) and sub-block-bandwidths block-bandwidths (0, 0) with data 3×5-blocked 3×15 BlockedMatrix{Float64}:
     0.333333  │  0.166667   ⋅   │   ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅          ⋅       
     ──────────┼─────────────────┼────────────────────────────────┼──────────────────────────────────────────┼────────────────────────────────────────────────────
     0.333333  │  0.466667   ⋅   │  0.2        ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅          ⋅       
      ⋅        │   ⋅        0.2  │   ⋅        0.133333   ⋅        │   ⋅         ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅          ⋅       
     ──────────┼─────────────────┼────────────────────────────────┼──────────────────────────────────────────┼────────────────────────────────────────────────────
      ⋅        │  0.3        ⋅   │  0.485714   ⋅         ⋅        │  0.214286   ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅          ⋅       
      ⋅        │   ⋅        0.2  │   ⋅        0.371429   ⋅        │   ⋅        0.178571   ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅          ⋅       
      ⋅        │   ⋅         ⋅   │   ⋅         ⋅        0.142857  │   ⋅         ⋅        0.107143   ⋅        │   ⋅         ⋅         ⋅         ⋅          ⋅       
     ──────────┼─────────────────┼────────────────────────────────┼──────────────────────────────────────────┼────────────────────────────────────────────────────
      ⋅        │   ⋅         ⋅   │  0.285714   ⋅         ⋅        │  0.492063   ⋅         ⋅         ⋅        │  0.222222   ⋅         ⋅         ⋅          ⋅       
      ⋅        │   ⋅         ⋅   │   ⋅        0.238095   ⋅        │   ⋅        0.428571   ⋅         ⋅        │   ⋅        0.2        ⋅         ⋅          ⋅       
      ⋅        │   ⋅         ⋅   │   ⋅         ⋅        0.142857  │   ⋅         ⋅        0.301587   ⋅        │   ⋅         ⋅        0.155556   ⋅          ⋅       
      ⋅        │   ⋅         ⋅   │   ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅        0.111111  │   ⋅         ⋅         ⋅        0.0888889   ⋅       
     ──────────┼─────────────────┼────────────────────────────────┼──────────────────────────────────────────┼────────────────────────────────────────────────────
      ⋅        │   ⋅         ⋅   │   ⋅         ⋅         ⋅        │  0.277778   ⋅         ⋅         ⋅        │  0.494949   ⋅         ⋅         ⋅          ⋅       
      ⋅        │   ⋅         ⋅   │   ⋅         ⋅         ⋅        │   ⋅        0.25       ⋅         ⋅        │   ⋅        0.454545   ⋅         ⋅          ⋅       
      ⋅        │   ⋅         ⋅   │   ⋅         ⋅         ⋅        │   ⋅         ⋅        0.194444   ⋅        │   ⋅         ⋅        0.373737   ⋅          ⋅       
      ⋅        │   ⋅         ⋅   │   ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅        0.111111  │   ⋅         ⋅         ⋅        0.252525    ⋅       
      ⋅        │   ⋅         ⋅   │   ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅        │   ⋅         ⋅         ⋅         ⋅         0.0909091
    
  2. dlfivefifty commented on Mar 26, 2026

    @dlfivefifty
    Member

    There is a fundamental question that there's ambiguity about when something should be left lazy versus materialised. The change probably came about to support something infinite dimensional, and as no tests failed it was merged.

    Without a firm guideline on what the right choice is I'm inclined to not worry about this, unless there's a very argument why it matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions