DenseAxisArray not working as expected with single dimensional

I’m trying to set some values on slices of a DenseAxisArray and am getting an error when setting on a single dimensional DenseAxisArray.

The following code works exactly as expected:

using JuMP.Containers

D = DenseAxisArray(zeros((3,2)),[:a,:b,:c],[:d,:e])
E = DenseAxisArray(ones((3)),[:a,:b,:c])
I = [:a,:b]

D[I,:d] = E[I]

The D array is equal to 1 on the indices corresponding to I and :d. Notice D is two dimensional.

However, when D is a single dimension:

D = DenseAxisArray(zeros((3)),[:a,:b,:c])
E = DenseAxisArray(ones((3)),[:a,:b,:c])
I = [:a,:b]

D[I] = E[I]

I get the following error

MethodError: no method matching Int64(::Symbol)
Closest candidates are:
  (::Type{T})(!Matched::AbstractChar) where T<:Union{Int32, Int64} at char.jl:51
  (::Type{T})(!Matched::AbstractChar) where T<:Union{AbstractChar, Number} at char.jl:50
  (::Type{T})(!Matched::BigInt) where T<:Union{Int128, Int16, Int32, Int64, Int8} at gmp.jl:359

Yes, I can use an explicit for loop to set the values, but I don’t want to. I’ll be doing this many times and a for loop is less clear with more clutter.

I don’t know if this is a bug in the implementation of DenseAxisArray or if I am doing something wrong.


Nice catch, and thanks for the reproducible example.

This looks like a bug: DenseAxisArray with Symbol key does not support setting · Issue #3151 · jump-dev/JuMP.jl · GitHub

1 Like

Thanks for the reply!

I was hoping it was me doing something wrong, but I’ll do a for loop until a fix comes out.

Thanks again

1 Like