Skip to content

Instantly share code, notes, and snippets.

@kersulis
Created February 12, 2018 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kersulis/b7c800ff476c5223bdd5a4aa4e09de89 to your computer and use it in GitHub Desktop.
Save kersulis/b7c800ff476c5223bdd5a4aa4e09de89 to your computer and use it in GitHub Desktop.
using Optim
import Optim.retract!
import Optim.project_tangent!
struct SphereSubspaceComplementIntersection <: Manifold
U::Matrix
proj::Matrix
end
function SphereSubspaceComplementIntersection(U)
Q = qr(U)[1]
SphereSubspaceComplementIntersection(U, eye(size(U, 1)) - Q*(Q'))
end
function retract!(S::SphereSubspaceComplementIntersection, X)
X[:] = S.proj*X
normalize!(X)
end
function project_tangent!(S::SphereSubspaceComplementIntersection, G, X)
G .= S.proj*(G .- real(vecdot(X,G)).*X)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment