Skip to content

Commit

Permalink
Add inplace log_safe!
Browse files Browse the repository at this point in the history
  • Loading branch information
sethaxen committed Nov 15, 2020
1 parent d9bb56e commit 2ec98d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/groups/general_linear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ function _log_project_SOn_S⁺!(X, q, n = size(q, 1))
fill!(d, s)
d[n] = det(F.U) * det(F.Vt) * s
expX = F.U * Diagonal(d) * F.Vt
return copyto!(X, eltype(X) <: Real ? real(log_safe(expX)) : log_safe(expX))
return log_safe!(X, expX)
end

function log!(G::GeneralLinear{n}, X, p, q) where {n}
pinvq = inverse_translate(G, p, q, LeftAction())
if isnormal(pinvq; atol = sqrt(eps(real(eltype(pinvq)))))
copyto!(X, log_safe(pinvq))
log_safe!(X, pinvq)
else
𝔽 = number_system(G)
if 𝔽 ===
Expand Down
2 changes: 1 addition & 1 deletion src/groups/group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,6 @@ function group_exp!(G::MultiplicationGroup, q, X)
end

function group_log!(G::MultiplicationGroup, X, q)
q isa Union{Number,AbstractMatrix} && return copyto!(X, log_safe(q))
q isa Union{Number,AbstractMatrix} && return log_safe!(X, q)
return error("group_log! not implemented on $(typeof(G)) for element $(typeof(q)) and vector $(typeof(X)).")
end
10 changes: 10 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ converted to a `Matrix` before computing the log.
return SizedMatrix{s[1],s[2]}(log(Matrix(parent(x))))
end

function log_safe!(Y, X)
if eltype(Y) <: Real
# handle imprecision by coercing to real
Y .= real.(log_safe(X))
else
copyto!(Y, log_safe(X))
end
return Y
end

"""
mul!_safe(Y, A, B) -> Y
Expand Down

0 comments on commit 2ec98d3

Please sign in to comment.