From 240c228634d593c39fa6690bf1e0ae86e531aa1c Mon Sep 17 00:00:00 2001 From: Hajg Jasa Date: Fri, 22 Sep 2023 10:17:48 +0200 Subject: [PATCH 1/6] Fix doc typo and make functions type-proof --- src/subgradients.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/subgradients.jl b/src/subgradients.jl index 61fd718..3e0ca8a 100644 --- a/src/subgradients.jl +++ b/src/subgradients.jl @@ -1,7 +1,7 @@ @doc raw""" - subgrad_distance(M, q, p[, c = 1; atol = 0]) - subgrad_distance!(M, X, q, p[, c = 1; atol = 0]) + subgrad_distance(M, q, p[, c = 2; atol = 0]) + subgrad_distance!(M, X, q, p[, c = 2; atol = 0]) compute the subgradient of the distance (in place of `X`) @@ -21,10 +21,10 @@ for ``c\neq 1`` or ``p\neq q``. Note that for the remaining case ``c=1``, # Optional -* `c` – (`1`) the exponent of the distance, i.e. the default is the distance +* `c` – (`2`) the exponent of the distance, i.e. the default is the distance * `atol` – (`0`) the tolerance to use when evaluating the distance between `p` and `q`. """ -function subgrad_distance(M, q, p, c::Int = 2; atol = 0) +function subgrad_distance(M, q, p, c::Int = 2; atol = zero(eltype(first(p)))) if c == 2 return -log(M, p, q) elseif c == 1 && distance(M, q, p) ≤ atol @@ -33,10 +33,10 @@ function subgrad_distance(M, q, p, c::Int = 2; atol = 0) return -distance(M, p, q)^(c - 2) * log(M, p, q) end end -function subgrad_distance!(M, X, q, p, c::Int = 2; atol = 0) +function subgrad_distance!(M, X, q, p, c::Int = 2; atol = zero(eltype(first(p)))) log!(M, X, p, q) if c == 2 - X .*= -one(eltype(X)) + X .*= -one(eltype(first(X))) elseif c == 1 && distance(M, q, p) ≤ atol normal_cone_vector!(M, X, p) else @@ -46,7 +46,7 @@ function subgrad_distance!(M, X, q, p, c::Int = 2; atol = 0) end function normal_cone_vector(M, p) Y = rand(M; vector_at = p) - if norm(M, p, Y) > 1.0 + if norm(M, p, Y) > one(eltype(first(Y))) Y ./= norm(M, p, Y) Y .*= rand() end @@ -54,7 +54,7 @@ function normal_cone_vector(M, p) end function normal_cone_vector!(M, Y, p) ManifoldsBase.rand!(M, Y; vector_at = p) - if norm(M, p, Y) > 1.0 + if norm(M, p, Y) > one(eltype(first(Y))) Y ./= norm(M, p, Y) Y .*= rand() end From 9b589d828dfdd4d586b18070b86e7eaf9f4228e1 Mon Sep 17 00:00:00 2001 From: Hajg Jasa Date: Fri, 22 Sep 2023 10:20:11 +0200 Subject: [PATCH 2/6] Make statement more precise --- docs/src/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/index.md b/docs/src/index.md index 49e6cdd..5035cfe 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -8,7 +8,7 @@ Providing a derivative, differential or gradient for a given function, this pack For example * `grad_f` for a gradient ``\operatorname{grad} f`` -* `subgrad_f` for a subgradient ``\partial f`` +* `subgrad_f` for a subgradient from the subdifferential``\partial f`` * `differential_f` for ``Df`` (also called pushforward) * `differential_f_variable` if `f` has multiple variables / parameters, since a usual writing in math is ``f_x`` in this case * `adjoint_differential_f` for pullbacks From 2cee72c63df74e1bd042acb04d24c2579c76b70e Mon Sep 17 00:00:00 2001 From: Hajg Jasa Date: Fri, 22 Sep 2023 10:28:26 +0200 Subject: [PATCH 3/6] Export subgrad_distance --- src/ManifoldDiff.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ManifoldDiff.jl b/src/ManifoldDiff.jl index 44f8386..4af4134 100644 --- a/src/ManifoldDiff.jl +++ b/src/ManifoldDiff.jl @@ -241,6 +241,6 @@ include("forward_diff.jl") include("reverse_diff.jl") include("zygote.jl") -export riemannian_gradient, riemannian_gradient!, riemannian_Hessian, riemannian_Hessian! +export riemannian_gradient, riemannian_gradient!, riemannian_Hessian, riemannian_Hessian!, subgrad_distance, subgrad_distance! export set_default_differential_backend!, default_differential_backend end # module From 256de98e70982ec58734f3cbb1d03e0e38d27e81 Mon Sep 17 00:00:00 2001 From: Hajg Jasa Date: Fri, 22 Sep 2023 10:35:42 +0200 Subject: [PATCH 4/6] Run formatter --- src/ManifoldDiff.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ManifoldDiff.jl b/src/ManifoldDiff.jl index 4af4134..f5e3185 100644 --- a/src/ManifoldDiff.jl +++ b/src/ManifoldDiff.jl @@ -241,6 +241,11 @@ include("forward_diff.jl") include("reverse_diff.jl") include("zygote.jl") -export riemannian_gradient, riemannian_gradient!, riemannian_Hessian, riemannian_Hessian!, subgrad_distance, subgrad_distance! +export riemannian_gradient, + riemannian_gradient!, + riemannian_Hessian, + riemannian_Hessian!, + subgrad_distance, + subgrad_distance! export set_default_differential_backend!, default_differential_backend end # module From 8c5ec000ae082f175d55462d451cf8f2abf15c33 Mon Sep 17 00:00:00 2001 From: Hajg Jasa Date: Fri, 22 Sep 2023 10:46:24 +0200 Subject: [PATCH 5/6] Bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index b0331bf..7a8fb8f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ManifoldDiff" uuid = "af67fdf4-a580-4b9f-bbec-742ef357defd" authors = ["Seth Axen ", "Mateusz Baran ", "Ronny Bergmann "] -version = "0.3.6" +version = "0.3.7" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" From 254f2f3a280972fa0a2e4d89008a0be294f3bdc7 Mon Sep 17 00:00:00 2001 From: Hajg Jasa Date: Fri, 22 Sep 2023 10:50:37 +0200 Subject: [PATCH 6/6] Change eltype to number_eltype --- src/subgradients.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/subgradients.jl b/src/subgradients.jl index 3e0ca8a..820c952 100644 --- a/src/subgradients.jl +++ b/src/subgradients.jl @@ -24,7 +24,7 @@ for ``c\neq 1`` or ``p\neq q``. Note that for the remaining case ``c=1``, * `c` – (`2`) the exponent of the distance, i.e. the default is the distance * `atol` – (`0`) the tolerance to use when evaluating the distance between `p` and `q`. """ -function subgrad_distance(M, q, p, c::Int = 2; atol = zero(eltype(first(p)))) +function subgrad_distance(M, q, p, c::Int = 2; atol = zero(number_eltype(p))) if c == 2 return -log(M, p, q) elseif c == 1 && distance(M, q, p) ≤ atol @@ -33,10 +33,10 @@ function subgrad_distance(M, q, p, c::Int = 2; atol = zero(eltype(first(p)))) return -distance(M, p, q)^(c - 2) * log(M, p, q) end end -function subgrad_distance!(M, X, q, p, c::Int = 2; atol = zero(eltype(first(p)))) +function subgrad_distance!(M, X, q, p, c::Int = 2; atol = zero(number_eltype(p))) log!(M, X, p, q) if c == 2 - X .*= -one(eltype(first(X))) + X .*= -one(number_eltype(X)) elseif c == 1 && distance(M, q, p) ≤ atol normal_cone_vector!(M, X, p) else @@ -46,7 +46,7 @@ function subgrad_distance!(M, X, q, p, c::Int = 2; atol = zero(eltype(first(p))) end function normal_cone_vector(M, p) Y = rand(M; vector_at = p) - if norm(M, p, Y) > one(eltype(first(Y))) + if norm(M, p, Y) > one(number_eltype(Y)) Y ./= norm(M, p, Y) Y .*= rand() end @@ -54,7 +54,7 @@ function normal_cone_vector(M, p) end function normal_cone_vector!(M, Y, p) ManifoldsBase.rand!(M, Y; vector_at = p) - if norm(M, p, Y) > one(eltype(first(Y))) + if norm(M, p, Y) > one(number_eltype(Y)) Y ./= norm(M, p, Y) Y .*= rand() end