diff --git a/src/plans/vectorial_plan.jl b/src/plans/vectorial_plan.jl index ac3731c7c0..e43a81a1b3 100644 --- a/src/plans/vectorial_plan.jl +++ b/src/plans/vectorial_plan.jl @@ -788,7 +788,7 @@ function get_jacobian!( FT,VGF<:AbstractVectorGradientFunction{<:InplaceEvaluation,FT,<:CoordinateVectorialType} } vgf.jacobian!!(M, JF, p) - _change_basis!(JF, vgf.jacobian_type.basis, basis) + _change_basis!(M, p, JF, vgf.jacobian_type.basis, basis) return JF end @@ -1119,7 +1119,7 @@ This function can perform the evalutation inplace of `V`. get_value(M::AbstractManifold, vgf::AbstractVectorFunction, p, i) function get_value( M::AbstractManifold, vgf::AbstractVectorFunction{E,<:FunctionVectorialType}, p, i=: -) where {E<:AbstractEvaluationType} +) where {E<:AllocatingEvaluation} c = vgf.value!!(M, p) if isa(c, Number) return c @@ -1140,9 +1140,25 @@ function get_value( ) where {E<:AbstractEvaluationType} return [f(M, p) for f in vgf.value!![i]] end +function get_value( + M::AbstractManifold, + vgf::AbstractVectorFunction{E,<:FunctionVectorialType}, + p, + i=:; + value_cache=zeros(vgf.range_dimension), +) where {E<:InplaceEvaluation} + vgf.value!!(M, value_cache, p) + return value_cache[i] +end +# A ComponentVectorialType Inplace does that make sense, since those would be real - valued functions + function get_value!( - M::AbstractManifold, V, vgf::AbstractVectorFunction{E,<:FunctionVectorialType}, p, i=: -) where {E<:AbstractEvaluationType} + M::AbstractManifold, + V, + vgf::AbstractVectorFunction{AllocatingEvaluation,<:FunctionVectorialType}, + p, + i=:, +) c = vgf.value!!(M, p) if isa(c, Number) V .= c @@ -1151,6 +1167,20 @@ function get_value!( end return V end + +function get_value!( + M::AbstractManifold, + V, + vgf::AbstractVectorFunction{InplaceEvaluation,<:FunctionVectorialType}, + p, + i=:; + value_cache=zeros(vgf.range_dimension), +) + vgf.value!!(M, value_cache, p) + V .= value_cache[i] + return V +end + @doc raw""" get_value_function(vgf::VectorGradientFunction, recursive=false) diff --git a/test/plans/test_constrained_plan.jl b/test/plans/test_constrained_plan.jl index a0fd3842b9..7ebc1362f6 100644 --- a/test/plans/test_constrained_plan.jl +++ b/test/plans/test_constrained_plan.jl @@ -12,6 +12,7 @@ include("../utils/dummy_types.jl") hess_f!(M, Y, p, X) = (Y .= [2.0, 2.0, 2.0]) # Inequality constraints g(M, p) = [p[1] - 1, -p[2] - 1] + g!(M, V, p) = (V .= [p[1] - 1, -p[2] - 1]) # # Function grad_g(M, p) = [[1.0, 0.0, 0.0], [0.0, -1.0, 0.0]] grad_gA(M, p) = [1.0 0.0; 0.0 -1.0; 0.0 0.0] @@ -41,6 +42,7 @@ include("../utils/dummy_types.jl") ) == 2 # Equality Constraints h(M, p) = [2 * p[3] - 1] + h!(M, V, p) = (V .= [2 * p[3] - 1]) h1(M, p) = 2 * p[3] - 1 grad_h(M, p) = [[0.0, 0.0, 2.0]] grad_hA(M, p) = [[0.0, 0.0, 2.0];;] @@ -83,9 +85,9 @@ include("../utils/dummy_types.jl") cofm = ConstrainedManifoldObjective( f, grad_f!, - g, + g!, grad_g!, - h, + h!, grad_h!; evaluation=InplaceEvaluation(), inequality_constraints=2, @@ -149,9 +151,9 @@ include("../utils/dummy_types.jl") cofhm = ConstrainedManifoldObjective( f, grad_f!, - g, + g!, grad_g!, - h, + h!, grad_h!; hess_f=hess_f!, hess_g=hess_g!, diff --git a/test/plans/test_vectorial_plan.jl b/test/plans/test_vectorial_plan.jl index da8daf3668..0f3b25a1ef 100644 --- a/test/plans/test_vectorial_plan.jl +++ b/test/plans/test_vectorial_plan.jl @@ -3,6 +3,7 @@ using Manopt: get_value, get_value_function, get_gradient_function @testset "VectorialGradientCost" begin M = ManifoldsBase.DefaultManifold(3) g(M, p) = [p[1] - 1, -p[2] - 1] + g!(M, V, p) = (V .= [p[1] - 1, -p[2] - 1]) # # Function grad_g(M, p) = [[1.0, 0.0, 0.0], [0.0, -1.0, 0.0]] hess_g(M, p, X) = [copy(X), -copy(X)] @@ -37,7 +38,7 @@ using Manopt: get_value, get_value_function, get_gradient_function function_type=ComponentVectorialType(), jacobian_type=ComponentVectorialType(), ) - vgf_fi = VectorGradientFunction(g, grad_g!, 2; evaluation=InplaceEvaluation()) + vgf_fi = VectorGradientFunction(g!, grad_g!, 2; evaluation=InplaceEvaluation()) vgf_vi = VectorGradientFunction( [g1, g2], [grad_g1!, grad_g2!], @@ -50,7 +51,7 @@ using Manopt: get_value, get_value_function, get_gradient_function g, jac_g, 2; jacobian_type=CoordinateVectorialType(DefaultOrthonormalBasis()) ) vgf_ji = VectorGradientFunction( - g, + g!, jac_g!, 2; jacobian_type=CoordinateVectorialType(DefaultOrthonormalBasis()), @@ -71,7 +72,7 @@ using Manopt: get_value, get_value_function, get_gradient_function jacobian_type=ComponentVectorialType(), hessian_type=ComponentVectorialType(), ) - vhf_fi = VectorHessianFunction(g, grad_g!, hess_g!, 2; evaluation=InplaceEvaluation()) + vhf_fi = VectorHessianFunction(g!, grad_g!, hess_g!, 2; evaluation=InplaceEvaluation()) vhf_vi = VectorHessianFunction( [g1, g2], [grad_g1!, grad_g2!],