I’m trying to optimize over a 3d array. It seems like it doesn’t want to handle a 3d array, but I’m not sure why. Is there a solution for this?
using Optimization, Optim, OptimizationOptimJL, Zygote, DifferentiationInterface
let k = 5
f(Ψ, _) = sum((@view Ψ[:,:,i]) * (@view Ψ[:,:,i]) for i in 1:k)
@assert all(isfinite, f(rand(5,5,k), nothing))
optfunc = OptimizationFunction(f, Optimization.AutoZygote())
problem = OptimizationProblem(optfunc, rand(5,5,k))
solve(problem, BFGS())
end
ERROR: adjoint not defined for Array{Float64, 3}. Consider using `permutedims` for higher-dimensional arrays.
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] adjoint(a::Array{Float64, 3})
@ LinearAlgebra /nix/store/x044gz5qmcy25gm3cjil3kg0mv5jnf5p-julia-bin-1.10.3/share/julia/stdlib/v1.10/LinearAlgebra/src/transpose.jl:3
[3] alloc_H(x::Array{Float64, 3}, F::Float64)
@ NLSolversBase ~/.julia/packages/NLSolversBase/kavn7/src/objective_types/abstract.jl:25
[4] __solve(cache::OptimizationCache{…})
@ OptimizationOptimJL ~/.julia/packages/OptimizationOptimJL/hDX5k/src/OptimizationOptimJL.jl:206
[5] solve!(cache::OptimizationCache{…})
@ SciMLBase ~/.julia/packages/SciMLBase/tEuIM/src/solve.jl:186
[6] solve(::OptimizationProblem{…}, ::BFGS{…}; kwargs::@Kwargs{})
@ SciMLBase ~/.julia/packages/SciMLBase/tEuIM/src/solve.jl:94
[7] solve(::OptimizationProblem{…}, ::BFGS{…})
@ SciMLBase ~/.julia/packages/SciMLBase/tEuIM/src/solve.jl:91
[8] top-level scope