# Potential bug with setting variable bounds with a NamedArray

**URL:** https://discourse.julialang.org/t/potential-bug-with-setting-variable-bounds-with-a-namedarray/102359
**Category:** Optimization (Mathematical)
**Created:** [August 1, 2023, 4:07pm UTC](https://discourse.julialang.org/t/potential-bug-with-setting-variable-bounds-with-a-namedarray/102359 "2023-08-01T16:07:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mitch\_Phillipson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitch_phillipson/32/42883_2.png) [@Mitch\_Phillipson](https://discourse.julialang.org/u/Mitch_Phillipson)
#### Post date: [August 1, 2023, 4:07pm UTC](https://discourse.julialang.org/t/potential-bug-with-setting-variable-bounds-with-a-namedarray/102359/1 "2023-08-01T16:07:48Z")

</div>

Hello,

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

```julia
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

```julia
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

---

<div class="post-metadata">

### Author: ![Mitch\_Phillipson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitch_phillipson/32/42883_2.png) [@Mitch\_Phillipson](https://discourse.julialang.org/u/Mitch_Phillipson)
#### Post date: [August 1, 2023, 7:01pm UTC](https://discourse.julialang.org/t/potential-bug-with-setting-variable-bounds-with-a-namedarray/102359/2 "2023-08-01T19:01:14Z")

</div>

I’ve realized this can be expressed more simply as

```julia
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.

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [August 1, 2023, 9:53pm UTC](https://discourse.julialang.org/t/potential-bug-with-setting-variable-bounds-with-a-namedarray/102359/3 "2023-08-01T21:53:37Z")

</div>

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](https://github.com/jump-dev/JuMP.jl/pull/3413). See the much larger backstory at [[Containers] support ArrayInterface.jl traits · Issue #3214 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/issues/3214).

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

---

<div class="post-metadata">

### Author: ![Mitch\_Phillipson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitch_phillipson/32/42883_2.png) [@Mitch\_Phillipson](https://discourse.julialang.org/u/Mitch_Phillipson)
#### Post date: [August 1, 2023, 10:19pm UTC](https://discourse.julialang.org/t/potential-bug-with-setting-variable-bounds-with-a-namedarray/102359/4 "2023-08-01T22:19:58Z")

</div>

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.
