Added \ and * operators
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
module thinQR
|
||||
|
||||
import Base: size, show, getproperty, getfield, propertynames, *
|
||||
using LinearAlgebra: norm, I, triu, diagm
|
||||
import Base: size, show, getproperty, getfield, propertynames, \, *
|
||||
using LinearAlgebra: norm, I, triu, diagm, ldiv!
|
||||
|
||||
export QRthin, qrhous!, qyhous
|
||||
export QRthin, qrhous!, qyhous, qyhoust
|
||||
|
||||
mutable struct QRthin{T <: Real}
|
||||
A::AbstractVecOrMat{T}
|
||||
@ -43,6 +43,15 @@ function qyhous(A::QRthin{T}, y::AbstractArray{T}) where T
|
||||
return z
|
||||
end
|
||||
|
||||
function qyhoust(A::QRthin{T}, y::AbstractArray{T}) where T
|
||||
m, n = size(A.A)
|
||||
z = deepcopy(y)
|
||||
for j ∈ 1:n
|
||||
z[j:m] = z[j:m] - A.A[j:m, j] * (A.A[j:m, j]' * z[j:m])
|
||||
end
|
||||
return z
|
||||
end
|
||||
|
||||
function calculateQ(A::QRthin{T}) where T
|
||||
if A.AQ != nothing
|
||||
return A.AQ
|
||||
@ -61,7 +70,7 @@ function calculateR(A::QRthin{T}) where T
|
||||
return A.AR
|
||||
end
|
||||
m, n = size(A.A)
|
||||
A.AR = triu(A.A[1:n, :], 1) + diagm(A.d)
|
||||
A.AR = vcat(triu(A.A[1:n, :], 1) + diagm(A.d), zeros(m-n, n))
|
||||
return A.AR
|
||||
end
|
||||
|
||||
@ -87,8 +96,18 @@ Base.propertynames(A::QRthin, private::Bool=false) = (:R, :Q, (private ? fieldna
|
||||
|
||||
Base.size(A::QRthin) = size(getfield(A, :A))
|
||||
|
||||
function *(A::QRthin{T}, b::AbstractVector{T}) where {T}
|
||||
return qyhous(A, b)
|
||||
function (\)(A::QRthin{T}, b::AbstractVector{T}) where T
|
||||
n, m = size(A)
|
||||
v = qyhoust(A, b)
|
||||
x = zeros(m)
|
||||
for j ∈ m:-1:1
|
||||
x[j] = (v[j] - x[j+1:m]' * A.A[j, j+1:m]) * A.d[j]^-1
|
||||
end
|
||||
return x
|
||||
end
|
||||
|
||||
function (*)(A::QRthin{T}, x::AbstractVecOrMat{T}) where T
|
||||
return qyhous(A, (A.R * x))
|
||||
end
|
||||
|
||||
end # module
|
||||
Reference in New Issue
Block a user