Skip to content

Commit

Permalink
Fix codecov.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Jacobsson committed Dec 18, 2024
1 parent 7079eef commit 1a2ce37
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 52 deletions.
53 changes: 24 additions & 29 deletions src/manifolds/Segre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,22 +217,23 @@ function embed!(M::Segre{𝔽,V}, q, p) where {𝔽,V}
return q = kron(p...)
end

@doc raw"""
function embed_vector(M::Segre{𝔽, V}, p, v)
Embed tangent vector ``v = (\nu, u_1, \dots, u_d)`` at ``p \doteq (\lambda, x_1, \dots, x_d)`` in ``𝔽^{n_1 \times \dots \times n_d}`` using the Krönecker product:
````math
(\nu, u_1, \dots, u_d) \mapsto \nu x_1 \otimes \dots \otimes x_d + \lambda u_1 \otimes x_2 \otimes \dots \otimes x_d + \dots + \lambda x_1 \otimes \dots \otimes x_{d - 1} \otimes u_d.
````
"""
function embed_vector!(M::Segre{𝔽,V}, u, p, v) where {𝔽,V}

# Product rule
return u = sum([
kron([i == j ? xdot : x for (j, (x, xdot)) in enumerate(zip(p, v))]...) for
(i, _) in enumerate(p)
])
end
# ManifoldsBase doesn't export embed_vector! right now
# @doc raw"""
# function embed_vector(M::Segre{𝔽, V}, p, v)

# Embed tangent vector ``v = (\nu, u_1, \dots, u_d)`` at ``p \doteq (\lambda, x_1, \dots, x_d)`` in ``𝔽^{n_1 \times \dots \times n_d}`` using the Krönecker product:
# ````math
# (\nu, u_1, \dots, u_d) \mapsto \nu x_1 \otimes \dots \otimes x_d + \lambda u_1 \otimes x_2 \otimes \dots \otimes x_d + \dots + \lambda x_1 \otimes \dots \otimes x_{d - 1} \otimes u_d.
# ````
# """
# function embed_vector!(M::Segre{𝔽,V}, u, p, v) where {𝔽,V}

# # Product rule
# return u = sum([
# kron([i == j ? xdot : x for (j, (x, xdot)) in enumerate(zip(p, v))]...) for
# (i, _) in enumerate(p)
# ])
# end

@doc raw"""
function spherical_angle_sum(M::Segre{ℝ, V}, p, q)
Expand Down Expand Up @@ -355,7 +356,7 @@ function exp!(M::Segre{ℝ,V}, q, p, v) where {V}
end
end

return 0
return q
end

@doc raw"""
Expand Down Expand Up @@ -387,21 +388,15 @@ log(M::Segre{ℝ,V}, p, q) where {V}

function log!(M::Segre{ℝ,V}, v, p, q) where {V}
closest_representative!(M, q, p)
m = spherical_angle_sum(M, p, q)

if !connected_by_geodesic(M, p, q)
v = nan.(size.(p))
else
m = spherical_angle_sum(M, p, q)

v[1][1] = q[1][1] * cos(m) - p[1][1]

for (n, xdot, x, y) in zip(V, v[2:end], p[2:end], q[2:end])
a = distance(Sphere(n - 1), x, y)
xdot .= (y - dot(x, y) * x) * (q[1][1] / p[1][1]) * sinc(m / pi) / sinc(a / pi)
end
v[1][1] = q[1][1] * cos(m) - p[1][1]
for (n, xdot, x, y) in zip(V, v[2:end], p[2:end], q[2:end])
a = distance(Sphere(n - 1), x, y)
xdot .= (y - dot(x, y) * x) * (q[1][1] / p[1][1]) * sinc(m / pi) / sinc(a / pi)
end

return 0
return v
end

@doc raw"""
Expand Down
21 changes: 7 additions & 14 deletions src/manifolds/SegreWarpedMetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function exp!(M::MetricManifold{ℝ,Segre{ℝ,V},WarpedMetric{A}}, q, p, v) wher
end
end

return 0
return q
end

@doc raw"""
Expand Down Expand Up @@ -206,22 +206,15 @@ log(M::MetricManifold{ℝ,Segre{ℝ,V},WarpedMetric{A}}, p, q) where {V,A}

function log!(M::MetricManifold{ℝ,Segre{ℝ,V},WarpedMetric{A}}, v, p, q) where {V,A}
closest_representative!(M, q, p)
m = spherical_angle_sum(M, p, q)

if !connected_by_geodesic(M, p, q)
v = nan.(size.(p))
else
m = spherical_angle_sum(M, p, q)

v[1][1] = q[1][1] * cos(A * m) - p[1][1]

for (n, xdot, x, y) in zip(V, v[2:end], p[2:end], q[2:end])
a = distance(Sphere(n - 1), x, y)
xdot .=
(y - dot(x, y) * x) * (q[1][1] / p[1][1]) * sinc(A * m / pi) / sinc(a / pi)
end
v[1][1] = q[1][1] * cos(A * m) - p[1][1]
for (n, xdot, x, y) in zip(V, v[2:end], p[2:end], q[2:end])
a = distance(Sphere(n - 1), x, y)
xdot .= (y - dot(x, y) * x) * (q[1][1] / p[1][1]) * sinc(A * m / pi) / sinc(a / pi)
end

return 0
return v
end

@doc raw"""
Expand Down
25 changes: 16 additions & 9 deletions test/manifolds/segre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1512,13 +1512,16 @@ for (M, V, p, q, v, u, dy, X) in zip(Ms, Vs, ps, qs, vs, us, dys, Xs)
@testset "is_point()" begin
@test(is_point(M, p))
@test(is_point(M, q))
@test_throws DomainError is_point(M, [[1.0, 0.0], p[2:end]...], true)
@test_throws DomainError is_point(M, [[-1.0], p[2:end]...], true)
@test_throws DomainError is_point(M, [p[1], 2 * p[2:end]...], true)
end

@testset "is_vector()" begin
@test(is_vector(M, p, v))
@test(is_vector(M, p, u))
@test_throws DomainError is_vector(M, [[1.0, 0.0], p[2:end]...], v, false, true)
@test_throws DomainError is_vector(M, p, [[1.0, 0.0], v[2:end]...], false, true)
@test_throws DomainError is_vector(M, p, p, false, true)
end

Expand Down Expand Up @@ -1658,15 +1661,9 @@ for (M, V, p, q, v, u, dy, X) in zip(Ms, Vs, ps, qs, vs, us, dys, Xs)
@test(isapprox(norm(M, p, log(M, p, q)), distance(M, p, q)))
end

@testset "riemann_tensor()" begin
# Test Riemann tensor by testing that sectional curvature is difference
# between circumference and 2 pi r for small circles. Since the sectional
# curvature contains the same information as the Riemann tensor, this
# should be fine.

sectional_curvature(M, p, u, v) =
inner(M, p, riemann_tensor(M, p, u, v, v), u) /
(inner(M, p, u, u) * inner(M, p, v, v) - inner(M, p, u, v)^2)
@testset "sectional_curvature()" begin
# Test that sectional curvature is difference between circumference
# and 2 pi r for small circles.

# Orthonormalize
u_ = u / norm(M, p, u)
Expand All @@ -1684,5 +1681,15 @@ for (M, V, p, q, v, u, dy, X) in zip(Ms, Vs, ps, qs, vs, us, dys, Xs)

@test(isapprox(K, sectional_curvature(M, p, u, v); rtol=1e-2, atol=1e-2))
end

@testset "riemann_tensor()" begin
@test(
isapprox(
sectional_curvature(M, p, u, v),
inner(M, p, riemann_tensor(M, p, u, v, v), u) /
(inner(M, p, u, u) * inner(M, p, v, v) - inner(M, p, u, v)^2),
)
)
end
end
end

0 comments on commit 1a2ce37

Please sign in to comment.