-
Notifications
You must be signed in to change notification settings - Fork 40
/
array.py
25 lines (19 loc) · 931 Bytes
/
array.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"Implements ArrayConstraint"
from .single_equation import SingleEquationConstraint
class ArrayConstraint(SingleEquationConstraint, list):
"""A ConstraintSet for prettier array-constraint printing.
When created by NomialArray `left` and `right` are likely to be
be either NomialArrays or Varkeys of VectorVariables.
"""
def __init__(self, constraints, left, oper, right):
self.constraints = constraints
list.__init__(self, constraints)
SingleEquationConstraint.__init__(self, left, oper, right)
def __iter__(self):
yield from self.constraints.flat
def lines_without(self, excluded):
"Returns lines for indentation in hierarchical printing."
return self.str_without(excluded).split("\n")
def __bool__(self):
"Allows the use of '=' NomialArrays as truth elements."
return False if self.oper != "=" else bool(self.constraints.all())