When creating variable or constraint containers in JuMP, one can use conditionals and a sparse array is produced, where the entries that do not met the conditions are left empty. For example:

typeof(@variable(model, [i in 1:10, j in 1:10; i != j]))
# JuMP.Containers.SparseAxisArray{VariableRef, 2, Tuple{Int64, Int64}}

Nevertheless, in base Julia:

typeof([(i, j) for i in 1:10, j in 1:10 if i != j])
# Vector{Tuple{Int64, Int64}} instead of sparse matrix

Is there a way to create sparse arrays using conditionals as above?

I do not particularly want to store the values efficiently, what I want is to create a structure that reminds entries where there shouldnâ€™t be any values. Maybe something like Matrix{Union(MyType, Nothing)} and storing nothing in those entries would be more adequate?

I wanted to create containers of variables and constraints capable of being appended rows to iteratively solve a problem increasing one by one the units of time.

I was considering

l = [s != k ? @variable(model, Bin) : nothing for s in 1:S, k in 1:S, _ in 1:T-1]
l = cat(l, [s != k ? @variable(model, Bin) : nothing for s in 1:S, k in 1:S], dims=3)