Potential bug with setting variable bounds with a NamedArray

Hello,

I think I’ve found a small bug in JuMP (or NamedArrays) when setting bounds using a NamedArray

using JuMP
using NamedArrays

S = [:a,:b]
X = NamedArray([1, 2],S)
m = Model()
@variable(m,Y[S])

set_upper_bound.(Y,X)

This throws DimensionMismatch: arrays could not be broadcast to a common size; got a dimension with lengths 2 and 2

Both of the following commands work as expected

set_upper_bound.(Y,X.array)

set_upper_bound.(Y.data,X)

I’m not sure if the issue is with JuMP or NamedArrays.

Thanks,

Mitch

I’ve realized this can be expressed more simply as

using JuMP
using NamedArrays

L = NamedArray([1,2,3],[:a,:b,:c])
X = JuMP.Containers.DenseAxisArray([1,2,3],[:a,:b,:c])

X .≈ L

This produces the same error for the same reasons.

This is a problem with the way that Julia packages compose. In this case, there are no methods to coordinate JuMP’s DenseAxisArray with NamedArray.

One approach might be a package extension, like we recently merged for DimensionalData: Add DimensionalData extension by odow · Pull Request #3413 · jump-dev/JuMP.jl · GitHub. See the much larger backstory at [Containers] support ArrayInterface.jl traits · Issue #3214 · jump-dev/JuMP.jl · GitHub.

Why use NamedArray in the first place? Why not just something like X = Containers.DenseAxisArray([1, 2], S).

That makes sense. And I’ve wanted to experiment with package extensions.

One reason for named arrays vs dense axis arrays is, at least to my knowledge, you can’t mask a dense axis arrays. In your example I don’t believe X[X>1] works.

I’m on a phone so apologies if things format poorly or that example does actually work.