Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arbitrary radii for spheres #2

Closed
benneti opened this issue Dec 3, 2018 · 3 comments
Closed

Arbitrary radii for spheres #2

benneti opened this issue Dec 3, 2018 · 3 comments

Comments

@benneti
Copy link

benneti commented Dec 3, 2018

As discussed at DifferentialEquations.jl #389 it might be useful to change the Sphere class to include a radius

struct Sphere{T} <: Manifold where {T <: Real}
    r::T
end
Sphere() = Sphere(1)
retract!(S::Sphere, x) = (x .= x .* (S.r / norm(x)))

I think this might be a good idea as it does not add much complexity and eases the use of the library for non normalized problems.

@pkofod
Copy link
Member

pkofod commented Dec 3, 2018

I will wait to hear Antoine if he thinks it fits. Really, many of these manifolds only require 3+2 lines of code, so if we have Sphere, might might as well make it a bit general, but I won't really put my foot down.

I will say, that if you want absolute performance here, you probably don't want to do it like this. The following will allow the unit radius to be compiled completely away

struct Sphere{T} <: Manifold
    r::T
end
Sphere() = Sphere(nothing)
retract!(S::Sphere{<:Nothing}, x) = normalize!(x)
retract!(S::Sphere, x) = (x .= x .* (S.r / norm(x)))

Just a general Julia tip :) [only really matters if you do many retractions of course, but...]

@benneti
Copy link
Author

benneti commented Dec 3, 2018

Oh that is cool to know, would you say the best learning source is the official doc? Because for now I just tried stuff and read a few parts of the doc and the wiki book.

@antoine-levitt
Copy link
Collaborator

More code, more bugs, more stuff to document and change if we change an API. But sure, if you feel it's useful, can you make a PR? Don't forget project_tangent as well.

@benneti benneti closed this as completed Dec 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants