Skip to content

Commit fb59bec

Browse files
authored
Add rdiv!, ldiv! methods and tests (#19)
* Non-working version with rdiv!, ldiv! * Change tests * Change from character to symbol in comparison. * Test transposed rdiv! and ldiv!, pass 'C' for cong. tr.
1 parent 44a59b9 commit fb59bec

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/lapack.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ for (f, elty) in (
206206
chkstride1(B)
207207
m, n = size(B, 1), size(B, 2)
208208
k, l = transr == 'N' ? size(A) : reverse(size(A))
209-
if k - (2l k) != m
209+
if k - (2l k) != (side == 'L' ? m : n)
210210
throw(
211211
DimensionMismatch(
212212
"First dimension of B must equal $(k - (2l k)), got $m",

src/triangular.jl

+19-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ LinearAlgebra.inv!(A::TriangularRFP) =
5656
TriangularRFP(LAPACK_RFP.tftri!(A.transr, A.uplo, 'N', A.data), A.transr, A.uplo)
5757
LinearAlgebra.inv(A::TriangularRFP) = LinearAlgebra.inv!(copy(A))
5858

59-
ldiv!(A::TriangularRFP{T}, B::StridedVecOrMat{T}) where {T} =
59+
LinearAlgebra.ldiv!(A::TriangularRFP{T}, B::StridedVecOrMat{T}) where {T} =
6060
LAPACK_RFP.tfsm!(A.transr, 'L', A.uplo, 'N', 'N', one(T), A.data, B)
61+
function LinearAlgebra.ldiv!(
62+
A::Adjoint{T, TriangularRFP{T}},
63+
B::StridedVecOrMat{T}) where {T}
64+
Ap = A.parent
65+
tr = T <: Complex ? 'C' : 'T'
66+
return LAPACK_RFP.tfsm!(Ap.transr, 'L', Ap.uplo, tr, 'N', one(T), Ap.data, B)
67+
end
68+
69+
LinearAlgebra.rdiv!(A::StridedVecOrMat{T}, B::TriangularRFP{T}) where {T} =
70+
LAPACK_RFP.tfsm!(B.transr, 'R', B.uplo, 'N', 'N', one(T), B.data, A)
71+
function LinearAlgebra.rdiv!(
72+
A::StridedVecOrMat{T},
73+
B::Adjoint{T, TriangularRFP{T}}) where {T}
74+
Bp = B.parent
75+
tr = T <: Complex ? 'C' : 'T'
76+
return LAPACK_RFP.tfsm!(Bp.transr, 'R', Bp.uplo, tr, 'N', one(T), Bp.data, A)
77+
end
78+
6179
(\)(A::TriangularRFP, B::StridedVecOrMat) = ldiv!(A, copy(B))

test/runtests.jl

+7-2
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,24 @@ import RectangularFullPacked: Ac_mul_A_RFP, TriangularRFP
8484
Complex{Float32},
8585
Complex{Float64},
8686
),
87-
n in (6, 7),
87+
n in (6,7),
8888
uplo in (:L, :U),
8989
transr in (:N, elty <: Complex ? :C : :T)
9090

9191
A = lu(rand(elty, n, n)).U
9292
A = uplo == :U ? A : copy(A')
9393
A_RFP = TriangularRFP(A, uplo; transr)
94+
Atri = uplo == :U ? UpperTriangular(copy(A)) : LowerTriangular(A)
9495
o = ones(elty, n)
9596

9697
@test A A_RFP
9798
@test A Array(A_RFP)
9899
@test A \ o A_RFP \ o
99-
@test inv(A) Array(inv(A_RFP))
100+
@test Array(inv(A)) Array(inv(A_RFP))
101+
@test ldiv!(Atri, copy(o)) ldiv!(A_RFP, copy(o))
102+
@test ldiv!(Atri', copy(o)) ldiv!(A_RFP', copy(o))
103+
@test rdiv!(collect(o'), Atri) rdiv!(collect(o'), A_RFP)
104+
@test rdiv!(collect(o'), Atri') rdiv!(collect(o'), A_RFP')
100105
end
101106

102107
@testset "In-place scalar multiplication" begin

0 commit comments

Comments
 (0)