@@ -447,8 +447,18 @@ function dataview(V::BandedMatrixBand)
447447 view (A. data, A. u - b + 1 , max (b,0 )+ 1 : min (n,m+ b))
448448end
449449
450+ @propagate_inbounds function Base. getindex (B:: BandedMatrixBand , i:: Int )
451+ A = parent (parent (B))
452+ b = band (B)
453+ if - A. l ≤ band (B) ≤ A. u
454+ dataview (B)[i]
455+ else
456+ zero (eltype (B))
457+ end
458+ end
459+
450460# B[band(i)]
451- function copyto! (v:: AbstractVector , B:: BandedMatrixBand )
461+ @inline function copyto! (v:: AbstractVector , B:: BandedMatrixBand )
452462 A = parent (parent (B))
453463 if - A. l ≤ band (B) ≤ A. u
454464 copyto! (v, dataview (B))
@@ -460,7 +470,7 @@ function copyto!(v::AbstractVector, B::BandedMatrixBand)
460470end
461471
462472# B[band(i)] .= x::Number
463- function fill! (Bv:: BandedMatrixBand , x)
473+ @inline function fill! (Bv:: BandedMatrixBand , x)
464474 b = band (Bv)
465475 A = parent (parent (Bv))
466476 l, u = bandwidths (A)
@@ -472,29 +482,23 @@ function fill!(Bv::BandedMatrixBand, x)
472482 Bv
473483end
474484
475- # B[band(i)] .= V::AbstractVector
476- function _copyto! (Bv:: BandedMatrixBand , V:: AbstractVector )
477- isempty (V) && return Bv
478- A = parent (parent (Bv))
479- if - A. l ≤ band (Bv) ≤ A. u
480- copyto! (dataview (Bv), V)
485+ @noinline throwdm (destaxes, srcaxes) =
486+ throw (DimensionMismatch (" destination axes $destaxes do not match source axes $srcaxes " ))
487+
488+ # more complicated broadcating
489+ # e.g. B[band(i)] .= a .* x .+ v
490+ @inline function copyto! (dest:: BandedMatrixBand , bc:: Broadcasted{Nothing} )
491+ axes (dest) == axes (bc) || throwdm (axes (dest), axes (src))
492+
493+ A = parent (parent (dest))
494+ if - A. l ≤ band (dest) ≤ A. u
495+ copyto! (dataview (dest), bc)
481496 else
482- # bounds-checking to work around axis offset of V
483- destinds, srcinds = LinearIndices (Bv), LinearIndices (V)
484- idf, isf = first (destinds), first (srcinds)
485- Δi = idf - isf
486- (checkbounds (Bool, destinds, isf+ Δi) &
487- checkbounds (Bool, destinds, last (srcinds)+ Δi)) ||
488- throw (BoundsError (dest, srcinds))
489-
490- all (iszero, V) || throw (BandError (A, band (Bv)))
497+ all (iszero, bc) || throw (BandError (A, band (dest)))
491498 end
492- return Bv
499+ return dest
493500end
494501
495- copyto! (Bv:: BandedMatrixBand , V:: AbstractVector ) = _copyto! (Bv, V)
496- copyto! (Bv:: BandedMatrixBand , V:: BandedMatrixBand ) = _copyto! (Bv, V)
497-
498502# ~ indexing along a row
499503
500504
0 commit comments