Skip to content

Commit 331fe53

Browse files
authored
Remove some inbounds annotations (#335)
* remove some inbounds annotations * remove some more annotations
1 parent e1bd108 commit 331fe53

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

src/banded/BandedMatrix.jl

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,11 @@ bandwidths(A::BandedMatrix) = (A.l , A.u)
354354
# ~~ getindex ~~
355355

356356
# fast method used below
357-
@inline inbands_getindex(data::AbstractMatrix, u::Integer, k::Integer, j::Integer) =
357+
@propagate_inbounds inbands_getindex(data::AbstractMatrix, u::Integer, k::Integer, j::Integer) =
358358
data[u + k - j + 1, j]
359359

360-
@inline function inbands_getindex(A::BandedMatrix, k::Integer, j::Integer)
361-
# it takes a bit of time to extract A.data, A.u since julia checks if those fields exist
362-
# the @inbounds here will suppress those checks
363-
@inbounds r = inbands_getindex(A.data, A.u, k, j)
364-
r
360+
@propagate_inbounds function inbands_getindex(A::BandedMatrix, k::Integer, j::Integer)
361+
inbands_getindex(A.data, A.u, k, j)
365362
end
366363

367364
# work around for Any matrices
@@ -475,20 +472,17 @@ data_rowrange(A::BandedMatrix{T}, i::Integer) where {T} = range((i ≤ 1+A.l ? A
475472
# ~ Special setindex methods ~
476473

477474
# fast method used below
478-
@inline @propagate_inbounds function inbands_setindex!(data::AbstractMatrix{T}, u::Integer, v, k::Integer, j::Integer) where {T}
475+
@propagate_inbounds function inbands_setindex!(data::AbstractMatrix{T}, u::Integer, v, k::Integer, j::Integer) where {T}
479476
data[u + k - j + 1, j] = convert(T, v)::T
480477
v
481478
end
482479

483480
# slow fall back method
484-
@inline @propagate_inbounds function inbands_setindex!(A::BandedMatrix, v, k::Integer, j::Integer)
485-
# it takes a bit of time to extract A.data, A.u since julia checks if those fields exist
486-
# the @inbounds here will suppress those checks
487-
@inbounds r = inbands_setindex!(A.data, A.u, v, k, j)
488-
r
481+
@propagate_inbounds function inbands_setindex!(A::BandedMatrix, v, k::Integer, j::Integer)
482+
inbands_setindex!(A.data, A.u, v, k, j)
489483
end
490484

491-
@inline @propagate_inbounds function banded_setindex!(data::AbstractMatrix, l::Integer, u::Integer, v, k::Integer, j::Integer)
485+
@propagate_inbounds function banded_setindex!(data::AbstractMatrix, l::Integer, u::Integer, v, k::Integer, j::Integer)
492486
if -l j-k u
493487
inbands_setindex!(data, u, v, k, j)
494488
elseif !iszero(v) # allow setting outside bands to zero
@@ -499,14 +493,14 @@ end
499493
end
500494

501495
# scalar - integer - integer
502-
@inline @propagate_inbounds function setindex!(A::BandedMatrix, v, k::Integer, j::Integer)
496+
@inline function setindex!(A::BandedMatrix, v, k::Integer, j::Integer)
503497
@boundscheck checkbounds(A, k, j)
504-
@inbounds r = banded_setindex!(A.data, A.l, A.u, v, k ,j)
505-
r
498+
@inbounds banded_setindex!(A.data, A.l, A.u, v, k ,j)
499+
A
506500
end
507501

508502
# matrix - colon - colon
509-
@inline @propagate_inbounds function setindex!(A::BandedMatrix{T}, v::AbstractMatrix, kr::Colon, jr::Colon) where {T}
503+
@inline function setindex!(A::BandedMatrix{T}, v::AbstractMatrix, kr::Colon, jr::Colon) where {T}
510504
@boundscheck checkdimensions(size(A), size(v))
511505
@boundscheck checkbandmatch(A, v, kr, jr)
512506

@@ -524,7 +518,7 @@ end
524518
# ~ indexing along a band
525519

526520
# vector - band - colon
527-
@inline @propagate_inbounds function setindex!(A::BandedMatrix{T}, V::AbstractVector, b::Band) where {T}
521+
@propagate_inbounds function setindex!(A::BandedMatrix{T}, V::AbstractVector, b::Band) where {T}
528522
@boundscheck checkband(A, b)
529523
@boundscheck checkdimensions(diaglength(A, b), V)
530524
row = A.u - b.i + 1
@@ -539,7 +533,7 @@ end
539533

540534
# ~ indexing along columns
541535
# vector - colon - integer -- A[:, 1] = [1, 2, 3] - not allowed
542-
@inline @propagate_inbounds function setindex!(A::BandedMatrix{T}, V::AbstractVector, kr::Colon, j::Integer) where {T}
536+
@propagate_inbounds function setindex!(A::BandedMatrix{T}, V::AbstractVector, kr::Colon, j::Integer) where {T}
543537
@boundscheck checkbounds(A, kr, j)
544538
@boundscheck checkdimensions(1:size(A,1), V)
545539
@boundscheck checkbandmatch(A,V,:,j)
@@ -553,7 +547,7 @@ end
553547
(A[colrange(A, j), j] = V) # call range method
554548

555549
# vector - range - integer -- A[1:3, 1] = [1, 2, 3]
556-
@inline @propagate_inbounds function setindex!(A::BandedMatrix, V::AbstractVector, kr::AbstractRange, j::Integer)
550+
@propagate_inbounds function setindex!(A::BandedMatrix, V::AbstractVector, kr::AbstractRange, j::Integer)
557551
@boundscheck checkbounds(A, kr, j)
558552
@boundscheck checkdimensions(kr, V)
559553
@boundscheck checkbandmatch(A, V, kr, j)
@@ -575,7 +569,7 @@ end
575569
# ~ indexing along a row
576570

577571
# vector - integer - colon -- A[1, :] = [1, 2, 3] - not allowed
578-
@inline @propagate_inbounds function setindex!(A::BandedMatrix{T}, V::AbstractVector, k::Integer, jr::Colon) where {T}
572+
@propagate_inbounds function setindex!(A::BandedMatrix{T}, V::AbstractVector, k::Integer, jr::Colon) where {T}
579573
@boundscheck if k < 1 || k > size(A,1)
580574
throw(BoundsError(A, (k, jr)))
581575
end
@@ -603,7 +597,7 @@ end
603597
(A[k, rowstart(A, k):rowstop(A, k)] = V) # call range method
604598

605599
# vector - integer - range -- A[1, 2:3] = [3, 4]
606-
@inline @propagate_inbounds function setindex!(A::BandedMatrix, V::AbstractVector, k::Integer, jr::AbstractRange)
600+
@propagate_inbounds function setindex!(A::BandedMatrix, V::AbstractVector, k::Integer, jr::AbstractRange)
607601
@boundscheck checkbounds(A, k, jr)
608602
@boundscheck checkdimensions(jr, V)
609603
@boundscheck checkbandmatch(A, V, k, jr)
@@ -624,7 +618,7 @@ end
624618
# ~ indexing over a rectangular block
625619

626620
# matrix - range - range
627-
@inline @propagate_inbounds function setindex!(A::BandedMatrix, V::AbstractMatrix, kr::AbstractRange, jr::AbstractRange)
621+
@propagate_inbounds function setindex!(A::BandedMatrix, V::AbstractMatrix, kr::AbstractRange, jr::AbstractRange)
628622
@boundscheck checkbounds(A, kr, jr)
629623
@boundscheck checkdimensions(kr, jr, V)
630624
@boundscheck checkbandmatch(A, V, kr, jr)
@@ -650,8 +644,8 @@ end
650644

651645

652646
function convert(::Type{Matrix}, A::BandedMatrix)
653-
ret=zeros(eltype(A),size(A,1),size(A,2))
654-
for j = 1:size(ret,2), k = colrange(ret,j)
647+
ret=zeros(eltype(A), size(A))
648+
for j = rowsupport(A), k = colrange(ret,j)
655649
@inbounds ret[k,j] = A[k,j]
656650
end
657651
ret
@@ -787,14 +781,12 @@ end
787781
bandwidths(S::SubArray{T,2,<:AbstractMatrix,I}) where {T,I<:Tuple{Vararg{AbstractUnitRange}}} =
788782
min.(size(S) .- 1, bandwidths(parent(S)) .+ (-1,1) .* bandshift(S))
789783

790-
@inline function inbands_getindex(S::BandedSubBandedMatrix{T}, k::Integer, j::Integer) where {T}
791-
@inbounds r = inbands_getindex(parent(S), reindex(parentindices(S), (k, j))...)
792-
r
784+
@propagate_inbounds function inbands_getindex(S::BandedSubBandedMatrix{T}, k::Integer, j::Integer) where {T}
785+
inbands_getindex(parent(S), reindex(parentindices(S), (k, j))...)
793786
end
794787

795-
@inline function inbands_setindex!(S::BandedSubBandedMatrix{T}, v, k::Integer, j::Integer) where {T}
796-
@inbounds r = inbands_setindex!(parent(S), v, reindex(parentindices(S), (k, j))...)
797-
r
788+
@propagate_inbounds function inbands_setindex!(S::BandedSubBandedMatrix{T}, v, k::Integer, j::Integer) where {T}
789+
inbands_setindex!(parent(S), v, reindex(parentindices(S), (k, j))...)
798790
end
799791

800792

0 commit comments

Comments
 (0)