-
Notifications
You must be signed in to change notification settings - Fork 152
inv, size, and \ for QR objects #1300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,3 +61,39 @@ end | |
function _first_zero_on_diagonal(A::StaticULT) | ||
_first_zero_on_diagonal(A.data) | ||
end | ||
|
||
|
||
inv(R::UpperTriangular{T, <:StaticMatrix}) where T = | ||
(@inline; UpperTriangular(_inv_upper_triangular(R.data))) | ||
|
||
_inv_upper_triangular(R::StaticMatrix{n, m}) where {n, m} = | ||
checksquare(R) | ||
|
||
@generated function _inv_upper_triangular(R::StaticMatrix{n, n, T}) where {n, T} | ||
ex = quote | ||
R_inv = MMatrix{n,n,T}(undef) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should either use |
||
end | ||
for i in n:-1:1 | ||
append!(ex.args, (quote | ||
r = 1 / R[$i, $i] | ||
for j in 1:$((i)-1) | ||
R_inv[$i, j] = 0 | ||
end | ||
R_inv[$i, $i] = r | ||
end).args) | ||
|
||
for j in (i+1):n | ||
s = :(0r) | ||
for k in (i+1):j | ||
s = :( $s + R[$i, $k] * R_inv[$k, $j] ) | ||
end | ||
push!(ex.args, :( | ||
R_inv[$i, $j] = -r * $s | ||
)) | ||
end | ||
end | ||
push!(ex.args, :( | ||
return SMatrix(R_inv) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
)) | ||
ex | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,10 +74,12 @@ TrivialView(a::AbstractArray{T,N}) where {T,N} = TrivialView{typeof(a),T,N}(a) | |
@inline drop_sdims(a::StaticArrayLike) = TrivialView(a) | ||
@inline drop_sdims(a) = a | ||
|
||
Base.@propagate_inbounds function invperm(p::StaticVector) | ||
# in difference to base, this does not check if p is a permutation (every value unique) | ||
ip = similar(p) | ||
ip[p] = 1:length(p) | ||
similar_type(p)(ip) | ||
@inline function invperm(p::StaticVector{N,T}) where {N,T<:Integer} | ||
ip = zeros(MVector{N,T}) | ||
@inbounds for i in SOneTo(N) | ||
j = p[i] | ||
1 <= j <= N && iszero(ip[j]) || throw(ArgumentError("argument is not a permutation")) | ||
ip[j] = i | ||
end | ||
SVector(ip) | ||
Comment on lines
-77
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quite likely someone relied on this being faster thanks to not performing the checks so I'm not sure about this change. |
||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.