Skip to content

Manopt does not work with Float32 data #582

@rsnumerics

Description

@rsnumerics

Manopt does not work with Float32 data. This has to do with default function arguments all specified as Float64 in the code. The default argument should be converted to the correct data type, say R(1.0), where R is the type parameter. Machine learning models tend to use Float32...

Explicitly specifying default function arguments is not a workaround, because this still causes problems internally.

For example the modified trust regions test fails straight away (this is what I am mainly interested in)

julia> include("test_trust_regions.jl")
Riemannian Trust-Region: Test Failed at ???/Tests/test_trust_regions.jl:15
  Expression: trust_regions(M, f, rgrad, rhess, p; max_trust_region_radius = -0.1f0)
    Expected: ErrorException
      Thrown: MethodError
      MethodError: no method matching var"#trust_regions!#1049"(::ExponentialRetraction, ::StopWhenAny{Tuple{StopAfterIteration, StopWhenGradientNormLess{typeof(norm), Float64, Missing}}}, ::Float32, ::Float32, ::Bool, ::typeof(copyto!), ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::@NamedTuple{}, ::TrustRegionModelObjective{AllocatingEvaluation, ManifoldHessianObjective{AllocatingEvaluation, typeof(f), typeof(rgrad), typeof(rhess), Manopt.var"#trust_regions##6#trust_regions##7"}}, ::DefaultManoptProblem{Fiber{ℝ, ManifoldsBase.TangentSpaceType, PowerManifold{ℝ, Grassmann{ℝ, ManifoldsBase.TypeParameter{Tuple{3, 2}}}, Tuple{Int64}, ArrayPowerRepresentation}, Array{Float32, 3}}, TrustRegionModelObjective{AllocatingEvaluation, ManifoldHessianObjective{AllocatingEvaluation, typeof(f), typeof(rgrad), typeof(rhess), Manopt.var"#trust_regions##6#trust_regions##7"}}}, ::StopWhenAny{Tuple{StopAfterIteration, StopWhenResidualIsReducedByFactorOrPower{Float64}, StopWhenTrustRegionIsExceeded{Float64}, StopWhenCurvatureIsNegative{Float64}, StopWhenModelIncreased{Float64}}}, ::TruncatedConjugateGradientState{Array{Float32, 3}, Float32, StopWhenAny{Tuple{StopAfterIteration, StopWhenResidualIsReducedByFactorOrPower{Float64}, StopWhenTrustRegionIsExceeded{Float64}, StopWhenCurvatureIsNegative{Float64}, StopWhenModelIncreased{Float64}}}, typeof(copyto!)}, ::Base.Pairs{Symbol, AllocatingEvaluation, Nothing, @NamedTuple{evaluation::AllocatingEvaluation}}, ::typeof(trust_regions!), ::PowerManifold{ℝ, Grassmann{ℝ, ManifoldsBase.TypeParameter{Tuple{3, 2}}}, Tuple{Int64}, ArrayPowerRepresentation}, ::ManifoldHessianObjective{AllocatingEvaluation, typeof(f), typeof(rgrad), typeof(rhess), Manopt.var"#trust_regions##6#trust_regions##7"}, ::Array{Float32, 3})
      The function `#trust_regions!#1049` exists, but no method is defined for this combination of argument types.
      
      Closest candidates are:
        var"#trust_regions!#1049"(::AbstractRetractionMethod, ::StoppingCriterion, ::R, ::R, ::Bool, ::Proj, ::R, ::R, ::Any, ::R, ::R, ::Any, ::R, ::R, ::R, ::R, ::Any, ::Any, ::Any, ::StoppingCriterion, ::AbstractManoptSolverState, ::Base.Pairs{Symbol, V, Nothing, NT} where {V, NT<:NamedTuple}, ::typeof(trust_regions!), ::AbstractManifold, ::O, ::Any) where {Proj, O<:Union{AbstractDecoratedManifoldObjective, ManifoldHessianObjective}, R}
         @ Manopt ~/.julia/packages/Manopt/vVYNl/src/solvers/trust_regions.jl:432
      
      Stacktrace:
       [1] trust_regions(M::PowerManifold{ℝ, Grassmann{ℝ, ManifoldsBase.TypeParameter{Tuple{3, 2}}}, Tuple{Int64}, ArrayPowerRepresentation}, mho::ManifoldHessianObjective{AllocatingEvaluation, typeof(f), typeof(rgrad), typeof(rhess), Manopt.var"#trust_regions##6#trust_regions##7"}, p::Array{Float32, 3}; kwargs::@Kwargs{evaluation::AllocatingEvaluation, max_trust_region_radius::Float32})
         @ Manopt ~/.julia/packages/Manopt/vVYNl/src/solvers/trust_regions.jl:382
       [2] trust_regions(M::PowerManifold{ℝ, Grassmann{ℝ, ManifoldsBase.TypeParameter{Tuple{3, 2}}}, Tuple{Int64}, ArrayPowerRepresentation}, f::Function, grad_f::Function, Hess_f::typeof(rhess), p::Array{Float32, 3}; evaluation::AllocatingEvaluation, preconditioner::Function, kwargs::@Kwargs{max_trust_region_radius::Float32})
         @ Manopt ~/.julia/packages/Manopt/vVYNl/src/solvers/trust_regions.jl:345
       [3] top-level scope
         @ ~/Documents/Tests/test_trust_regions.jl:6
       [4] macro expansion
         @ ~/.julia/juliaup/julia-1.12.5+0.x64.linux.gnu/share/julia/stdlib/v1.12/Test/src/Test.jl:1776 [inlined]
       [5] macro expansion
         @ ~/Documents/Tests/test_trust_regions.jl:15 [inlined]
       [6] macro expansion
         @ ~/.julia/juliaup/julia-1.12.5+0.x64.linux.gnu/share/julia/stdlib/v1.12/Test/src/Test.jl:774 [inlined]
       [7] macro expansion
         @ ~/Documents/Tests/test_trust_regions.jl:15 [inlined]

All code is here: Archive.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions