You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the introduction of the @ operator in python & numpy, it may be more natural to use standard np.array instead of np.matrix and CyLPArray to build a model.
Currently, to build CyLPExpr, we can/must use:
importnumpyasnpfromcylp.py.modeling.CyLPModelimportCyLPModel, CyLPArraymodel=CyLPModel()
T=3x=model.addVariable("x", T)
c=np.ones((T,))
A=np.ones((5, T,))
print(CyLPArray(c) <=x)
print(x<=c) # no need to convert to CyLPArray as CyLPar.__le__ has priority over np.arrayprint(x*np.matrix(c))
print(np.matrix(c) *x)
print(np.matrix(A) *x)
(I have explicitly converted np.array to np.matrix/CyLPArray when stricly needed).
It would be nice to support the following:
importnumpyasnpfromcylp.py.modeling.CyLPModelimportCyLPModel, CyLPArraymodel=CyLPModel()
T=3x=model.addVariable("x", T)
c=np.ones((T,))
A=np.ones((5, T,))
print(c<=x) # no need to wrap c into a CyLPArrayprint(x<=c)
print(x @ c) # use of @ operator for matrix multiplication instead of print(c @ x)
print(A @ x)
Supporting this requires to add the following to the CyLPExpr class
__array_ufunc__ = None
def __rmatmul__(self, other):
v = CyLPExpr(opr="*", left=other, right=self)
v.expr = v
self.expr = v
return v
def __matmul__(self, other):
v = CyLPExpr(opr="*", left=self, right=other)
v.expr = v
self.expr = v
return v
I will prepare a PR with this change
The text was updated successfully, but these errors were encountered:
With the introduction of the @ operator in python & numpy, it may be more natural to use standard np.array instead of np.matrix and CyLPArray to build a model.
Currently, to build CyLPExpr, we can/must use:
(I have explicitly converted np.array to np.matrix/CyLPArray when stricly needed).
It would be nice to support the following:
Supporting this requires to add the following to the CyLPExpr class
I will prepare a PR with this change
The text was updated successfully, but these errors were encountered: