From ca9270503f17c177bedcffe6a56174215a643c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Tue, 15 Aug 2023 14:37:43 +0200 Subject: [PATCH] [POC] Allow array in nonlinear expressions --- src/nlp_expr.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/nlp_expr.jl b/src/nlp_expr.jl index 6fe42fcb5ee..26596fb2ced 100644 --- a/src/nlp_expr.jl +++ b/src/nlp_expr.jl @@ -336,6 +336,10 @@ for f in MOI.Nonlinear.DEFAULT_UNIVARIATE_OPERATORS end end +function LinearAlgebra.det(A::LinearAlgebra.Symmetric{<:AbstractJuMPScalar}) + return GenericNonlinearExpr{variable_ref_type(eltype(A))}(:det, A) +end + # Multivariate operators # The multivariate operators in MOI are +, -, *, ^, /, ifelse, atan @@ -506,6 +510,8 @@ function moi_function(f::GenericNonlinearExpr{V}) where {V} for i in length(f.args):-1:1 if f.args[i] isa GenericNonlinearExpr{V} push!(stack, (ret, i, f.args[i])) + elseif arg.args[i] isa AbstractArray + child.args[i] = moi_function.(arg.args[i]) else ret.args[i] = moi_function(f.args[i]) end @@ -517,6 +523,8 @@ function moi_function(f::GenericNonlinearExpr{V}) where {V} for j in length(arg.args):-1:1 if arg.args[j] isa GenericNonlinearExpr{V} push!(stack, (child, j, arg.args[j])) + elseif arg.args[j] isa AbstractArray + child.args[j] = moi_function.(arg.args[j]) else child.args[j] = moi_function(arg.args[j]) end @@ -542,6 +550,8 @@ function jump_function(model::GenericModel, f::MOI.ScalarNonlinearFunction) end elseif arg isa Number push!(parent.args, arg) + elseif arg isa AbstractArray + push!(parent.args, jump_function.(model, arg)) else push!(parent.args, jump_function(model, arg)) end