|
52 | 52 |
|
53 | 53 | if VERSION < v"1.7"
|
54 | 54 | #=
|
55 |
| - This method for `logabsdet(F::UmfpackLU)` is required to calculate the (log)determinants |
56 |
| - of sparse matrices, but was not defined prior to Julia v1.7. In order fo the rrules |
57 |
| - for the determinants of sparse matrices below to work, they need to be able to |
58 |
| - compute the primals as well, so this import from the future is included. For more |
59 |
| - recent versions of Julia, this definition lives in: |
| 55 | + The method below for `logabsdet(F::UmfpackLU)` is required to calculate the (log) |
| 56 | + determinants of sparse matrices, but was not defined prior to Julia v1.7. In order |
| 57 | + for the rrules for the determinants of sparse matrices below to work, they need to be |
| 58 | + able to compute the primals as well, so this import from the future is included. For |
| 59 | + more recent versions of Julia, this definition lives in: |
60 | 60 | julia/stdlib/SuiteSparse/src/umfpack.jl
|
61 | 61 | =#
|
62 |
| - using SuiteSparse.UMFPACK: _signperm, UmfpackLU |
| 62 | + using SuiteSparse.UMFPACK: UmfpackLU |
63 | 63 |
|
| 64 | + # compute the sign/parity of a permutation |
| 65 | + function _signperm(p) |
| 66 | + n = length(p) |
| 67 | + result = 0 |
| 68 | + todo = trues(n) |
| 69 | + while any(todo) |
| 70 | + k = findfirst(todo) |
| 71 | + todo[k] = false |
| 72 | + result += 1 # increment element count |
| 73 | + j = p[k] |
| 74 | + while j != k |
| 75 | + result += 1 # increment element count |
| 76 | + todo[j] = false |
| 77 | + j = p[j] |
| 78 | + end |
| 79 | + result += 1 # increment cycle count |
| 80 | + end |
| 81 | + return ifelse(isodd(result), -1, 1) |
| 82 | + end |
| 83 | + |
64 | 84 | for itype in (:Int32, :Int64)
|
65 | 85 | @eval begin
|
66 | 86 | function LinearAlgebra.logabsdet(F::UmfpackLU{T, $itype}) where {T<:Union{Float64,ComplexF64}}
|
|
0 commit comments