-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copied from linalg/lu.jl | ||
function ipiv2perm{T}(v::AbstractVector{T}, maxi::Integer) | ||
p = T[1:maxi] | ||
@inbounds for i in 1:length(v) | ||
p[i], p[v[i]] = p[v[i]], p[i] | ||
end | ||
return p | ||
end | ||
|
||
function ipiv2perm{T}(v::AbstractVector{T}) | ||
ipiv2perm(v,length(v)) | ||
end | ||
|
||
|
||
# A naive algorithm, maybe there exists a faster one. | ||
# Build the pivot while permuting 1:n. Make | ||
# inverse perm at the same time, so we know where to | ||
# find p[i] | ||
function perm2ipiv{T}(p::AbstractVector{T}) | ||
n = length(p) | ||
m = [1:n] | ||
v = similar(m) | ||
x = copy(m) | ||
@inbounds for i in 1:n | ||
j = x[p[i]] | ||
mi = m[i] | ||
mj = m[j] | ||
m[i],m[j] = mj,mi | ||
v[i] = j | ||
x[mj] = i | ||
x[mi] = j | ||
end | ||
return v | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters