1616
1717import operator as op
1818from functools import reduce
19- from typing import List , Tuple
2019
2120import numpy as np
2221import scipy .sparse as sp
@@ -64,13 +63,13 @@ def name(self):
6463 else :
6564 pretty_args .append (a .name ())
6665 return pretty_args [0 ] + ' ' + self .OP_NAME + ' ' + pretty_args [1 ]
67-
66+
6867 def format_labeled (self ):
6968 """Format binary operation with labels where available."""
7069 # Check for own label first
7170 if self ._label is not None :
7271 return self ._label
73-
72+
7473 # Build from sub-expressions using their labels
7574 pretty_args = []
7675 for i , a in enumerate (self .args ):
@@ -90,7 +89,7 @@ def numeric(self, values):
9089 """
9190 return reduce (self .OP_FUNC , values )
9291
93- def sign_from_args (self ) -> Tuple [bool , bool ]:
92+ def sign_from_args (self ) -> tuple [bool , bool ]:
9493 """Default to rules for times.
9594 """
9695 return u .sign .mul_sign (self .args [0 ], self .args [1 ])
@@ -107,7 +106,7 @@ def is_complex(self) -> bool:
107106 return (self .args [0 ].is_complex () or self .args [1 ].is_complex ()) and \
108107 not (self .args [0 ].is_imag () and self .args [1 ].is_imag ())
109108
110- def bounds_from_args (self ) -> Tuple [np .ndarray , np .ndarray ]:
109+ def bounds_from_args (self ) -> tuple [np .ndarray , np .ndarray ]:
111110 """Returns bounds for elementwise multiplication based on argument bounds."""
112111 lb1 , ub1 = self .args [0 ].get_bounds ()
113112 lb2 , ub2 = self .args [1 ].get_bounds ()
@@ -192,7 +191,7 @@ def numeric(self, values):
192191 else :
193192 return values [0 ] @ values [1 ]
194193
195- def shape_from_args (self ) -> Tuple [int , ...]:
194+ def shape_from_args (self ) -> tuple [int , ...]:
196195 """Returns the (row, col) shape of the expression.
197196 """
198197 return u .shape .mul_shapes (self .args [0 ].shape , self .args [1 ].shape )
@@ -235,7 +234,7 @@ def is_atom_log_log_concave(self) -> bool:
235234 """
236235 return False
237236
238- def bounds_from_args (self ) -> Tuple [np .ndarray , np .ndarray ]:
237+ def bounds_from_args (self ) -> tuple [np .ndarray , np .ndarray ]:
239238 """Returns bounds for matrix multiplication based on argument bounds."""
240239 lb1 , ub1 = self .args [0 ].get_bounds ()
241240 lb2 , ub2 = self .args [1 ].get_bounds ()
@@ -312,8 +311,8 @@ def _grad(self, values):
312311 return [DX , DY ]
313312
314313 def graph_implementation (
315- self , arg_objs , shape : Tuple [int , ...], data = None
316- ) -> Tuple [lo .LinOp , List [Constraint ]]:
314+ self , arg_objs , shape : tuple [int , ...], data = None
315+ ) -> tuple [lo .LinOp , list [Constraint ]]:
317316 """Multiply the linear expressions.
318317
319318 Parameters
@@ -359,7 +358,7 @@ def is_atom_log_log_concave(self) -> bool:
359358 """Is the atom log-log concave?"""
360359 return True
361360
362- def bounds_from_args (self ) -> Tuple [np .ndarray , np .ndarray ]:
361+ def bounds_from_args (self ) -> tuple [np .ndarray , np .ndarray ]:
363362 """Returns bounds for elementwise multiplication based on argument bounds.
364363
365364 Overrides MulExpression to use elementwise multiplication bounds
@@ -397,7 +396,7 @@ def validate_arguments(self):
397396 np .empty (self .args [1 ].shape , dtype = np .dtype ([]))
398397 )
399398
400- def shape_from_args (self ) -> Tuple [int , ...]:
399+ def shape_from_args (self ) -> tuple [int , ...]:
401400 """Call np.broadcast on multiply arguments."""
402401 return np .broadcast_shapes (self .args [0 ].shape , self .args [1 ].shape )
403402
@@ -448,8 +447,8 @@ def _grad(self, values):
448447 return [DX , DY ]
449448
450449 def graph_implementation (
451- self , arg_objs , shape : Tuple [int , ...], data = None
452- ) -> Tuple [lo .LinOp , List [Constraint ]]:
450+ self , arg_objs , shape : tuple [int , ...], data = None
451+ ) -> tuple [lo .LinOp , list [Constraint ]]:
453452 """Multiply the expressions elementwise.
454453
455454 Parameters
@@ -509,7 +508,7 @@ def has_quadratic_term(self) -> bool:
509508 def is_qpwa (self ) -> bool :
510509 return self .args [0 ].is_qpwa () and self .args [1 ].is_constant ()
511510
512- def shape_from_args (self ) -> Tuple [int , ...]:
511+ def shape_from_args (self ) -> tuple [int , ...]:
513512 """Returns the (row, col) shape of the expression.
514513 """
515514 return self .args [0 ].shape
@@ -539,7 +538,7 @@ def is_atom_quasiconvex(self) -> bool:
539538 def is_atom_quasiconcave (self ) -> bool :
540539 return self .is_atom_quasiconvex ()
541540
542- def bounds_from_args (self ) -> Tuple [np .ndarray , np .ndarray ]:
541+ def bounds_from_args (self ) -> tuple [np .ndarray , np .ndarray ]:
543542 """Returns bounds for division based on argument bounds."""
544543 lb1 , ub1 = self .args [0 ].get_bounds ()
545544 lb2 , ub2 = self .args [1 ].get_bounds ()
@@ -562,8 +561,8 @@ def is_decr(self, idx) -> bool:
562561 return self .args [0 ].is_nonneg ()
563562
564563 def graph_implementation (
565- self , arg_objs , shape : Tuple [int , ...], data = None
566- ) -> Tuple [lo .LinOp , List [Constraint ]]:
564+ self , arg_objs , shape : tuple [int , ...], data = None
565+ ) -> tuple [lo .LinOp , list [Constraint ]]:
567566 """Multiply the linear expressions.
568567
569568 Parameters
@@ -646,7 +645,7 @@ def outer(x, y):
646645 y = Expression .cast_to_const (y )
647646 if y .ndim > 1 :
648647 raise ValueError ("y must be a 1-d array." )
649-
648+
650649 x = reshape (x , (x .size , 1 ), order = 'F' )
651650 y = reshape (y , (1 , y .size ), order = 'F' )
652651 return x @ y
0 commit comments