Open arcondello opened 1 month ago
One limitation to promotion is that it won't work for all operations. So
model = Model()
x = model.list(5)
a = [0, 1, 2, 3, 4]
x * a # this will work because we're calling x's __mul__() method
a * x # this will work because first a's __mul__() will fail, so Python will try x's __mul__()
x[a] # this will work because we're calling x's __getitem__() method
a[x] # this will not work
which might be a bit mysterious for users.
Currently, in order to use a scalar/array, you need to cast it to a
Constant
symbol. E.g.with https://github.com/dwavesystems/dwave-optimization/issues/38 it should be possible to simply do
by promoting
a
to aConstant
inx
's__mul__()
.The main problem is that, in addition to #38, we would probably need some sort of caching. Consider
if each time we see
2
we create a new constant, we end up with 100 identicalConstant
symbols, each encoding the same value of2
. Whereasonly creates one.