Coverage for gpkit/constraints/array.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-07 22:56 -0500

1"Implements ArrayConstraint" 

2from .single_equation import SingleEquationConstraint 

3 

4 

5class ArrayConstraint(SingleEquationConstraint, list): 

6 """A ConstraintSet for prettier array-constraint printing. 

7 

8 When created by NomialArray `left` and `right` are likely to be 

9 be either NomialArrays or Varkeys of VectorVariables. 

10 """ 

11 def __init__(self, constraints, left, oper, right): 

12 self.constraints = constraints 

13 list.__init__(self, constraints) 

14 SingleEquationConstraint.__init__(self, left, oper, right) 

15 

16 def __iter__(self): 

17 yield from self.constraints.flat 

18 

19 def lines_without(self, excluded): 

20 "Returns lines for indentation in hierarchical printing." 

21 return self.str_without(excluded).split("\n") 

22 

23 def __bool__(self): 

24 "Allows the use of '=' NomialArrays as truth elements." 

25 return False if self.oper != "=" else bool(self.constraints.all())