X' allowed in JuMP model but not transpose(X)

Hi,

I have encountered a weird behaviour in JuMP. This works

JuMP.@constraint(model, sum(A[i, :] * Y_mat[i,:]’ for i in 1:m) .- sum(μ)*I .==
zeros(n,n))

while this does not

JuMP.@constraint(model, sum(A[i, :] * transpose(Y_mat[i,:]) for i in 1:m) .- sum(μ)*I .== zeros(n,n))

It throws this error
MethodError: no method matching promote_array_mul(::Type{Vector{Float64}}, ::Type{Transpose{VariableRef, Vector{VariableRef}}})

To my understanding, both should be internally the same. Is this a bug or is there a specific reason JuMP does not support transpose() here?

I am on Julia 1.9.0 and JuMP v1.19.0.

Hi @dhendryc, welcome to the forum!

I’ve opened an issue with this bug report: Missing methods for LinearAlgebra.Transpose · Issue #256 · jump-dev/MutableArithmetics.jl · GitHub

The issue stems from the fact that x' is not actually LinearAlgebra.transpose, but LinearAlgebra.adjoint. (The difference is very subtle.)

julia> x[1, :]
2-element Vector{VariableRef}:
 x[1,1]
 x[1,2]

julia> x[1, :]'
1×2 adjoint(::Vector{VariableRef}) with eltype VariableRef:
 x[1,1]  x[1,2]

julia> transpose(x[1, :])
1×2 transpose(::Vector{VariableRef}) with eltype VariableRef:
 x[1,1]  x[1,2]

julia> adjoint(x[1, :])
1×2 adjoint(::Vector{VariableRef}) with eltype VariableRef:
 x[1,1]  x[1,2]

But this is a bad MethodError, and we can fix to support transpose as well.

Hi @odow ,

thank you for the clarification!

It would be nice if JuMP also supported transpose. I find it easier to catch modelling errors, ' can be easily overlooked.

I’ve fixed this in MutableArithmetics.jl, so it just needs a new release. Likely in the next day or two :smile: