Skip to content

Commit

Permalink
[POC] Allow array in nonlinear expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Aug 31, 2023
1 parent a573de2 commit ca92705
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/nlp_expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ca92705

Please sign in to comment.