coin-or / CyLP

A Python interface to CLP, CBC, and CGL to solve LPs and MIPs.
Other
182 stars 69 forks source link

Indexing by one-dimensional tuples #89

Open anagorko opened 4 years ago

anagorko commented 4 years ago

I'm converting symbolic tensors of different shapes into CyLP variables. This works well with one exception: when the shape is one-dimensional (it is still a tuple) you cannot reference individual variables by their tuple indices.

Example:

import cylp.cy

model = cylp.cy.CyClpSimplex()

s = model.addVariable('s', (2, 2))
r = model.addVariable('r', 2)
t = model.addVariable('t', (2,  ))

# this works
print(s[(1, 1)])

# this works
print(r[1])

# this works
print(t[1])

# this doesn't work
print(t[(1,)])

The workaround is stated in the code above, but still it would be nice to be able to access elements of one-dimensional and higher-dimensional tensors in a consistent way.

tkralphs commented 4 years ago

Thanks for the report, I'll try to take a look at this.