Skip to content

Commit 9ac4db5

Browse files
committed
Specialize setindex! with BandIndex for adj/trans
1 parent eae653a commit 9ac4db5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/adjtrans.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ IndexStyle(::Type{<:AdjOrTransAbsVec}) = IndexLinear()
357357
require_one_based_indexing(A)
358358
wrapperop(A)(A.parent[BandIndex(-b.band, b.index)])::T
359359
end
360+
@propagate_inbounds function setindex!(A::AdjOrTransAbsMat, x, b::BandIndex)
361+
require_one_based_indexing(A)
362+
setindex!(A.parent, _wrapperop(A)(x), BandIndex(-b.band, b.index))
363+
return A
364+
end
360365

361366
# conversion of underlying storage
362367
convert(::Type{Adjoint{T,S}}, A::Adjoint) where {T,S} = Adjoint{T,S}(convert(S, A.parent))::Adjoint{T,S}

test/adjtrans.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,13 +751,17 @@ end
751751

752752
@testset "band indexing" begin
753753
n = 3
754-
A = UnitUpperTriangular(reshape(1:n^2, n, n))
754+
A = UnitUpperTriangular(Matrix(reshape(1:n^2, n, n)))
755755
@testset "every index" begin
756-
Aadj = A'
756+
Aadj = Adjoint(A)
757757
for k in -(n-1):n-1
758758
di = diagind(Aadj, k, IndexStyle(Aadj))
759759
for (i,d) in enumerate(di)
760760
@test Aadj[LinearAlgebra.BandIndex(k,i)] == Aadj[d]
761+
if k < 0 # the adjoint is a unit lower triangular
762+
Aadj[LinearAlgebra.BandIndex(k,i)] = n^2 + i
763+
@test Aadj[d] == n^2 + i
764+
end
761765
end
762766
end
763767
end

0 commit comments

Comments
 (0)