Skip to content

Commit

Permalink
Handle singular case in _find_more_nullspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Jun 24, 2018
1 parent 6cde312 commit 993ce77
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/continuations/branching.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@ function find_more_nullspaces(Q, L, rtol, atol, max_steps)
return tJ2, cotJ
end

function _find_more_nullspaces(L2, R2, y, rtol, atol, max_steps)
function _find_more_nullspaces(L2, R2,
y :: T,
rtol, atol, max_steps,
) where {T <: AbstractVector}
if abs(det(L2)) < atol
# TODO: optimize
ker_L2 = nullspace(Array(L2))
ker_R2 = nullspace(Array(R2))
if size(ker_L2, 2) > 0 && size(ker_R2, 2) > 0
return (T(@view ker_L2[:, 1]), T(@view ker_R2[:, 1]))
end
# Otherwise, let's fallback to the manual method.
end
x0 = _similar(y, length(y))
x1 = _similar(y, length(y))

Expand All @@ -48,7 +60,7 @@ function _find_more_nullspaces(L2, R2, y, rtol, atol, max_steps)
y = _A_ldiv_B!(y, L2, x1)
y /= norm(y)
if isapprox(x0, x1; rtol=rtol, atol=atol)
return y, x1
return y::T, x1::T
end
end
error("Failed to find the cokernel.")
Expand Down

0 comments on commit 993ce77

Please sign in to comment.