-
Notifications
You must be signed in to change notification settings - Fork 40
/
array.py
29 lines (23 loc) · 1.1 KB
/
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
26
27
28
29
"Implements ArrayConstraint"
from .set import flatiter
from .single_equation import SingleEquationConstraint
# TODO: don't inherit from ConstraintSet, implement own .flat()
# TODO: check for numpy_bools here and here alone
class ArrayConstraint(SingleEquationConstraint, list):
"""A ConstraintSet for prettier array-constraint printing.
ArrayConstraint gets its `sub` method from ConstrainSet,
and so `left` and `right` are only used for 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):
SingleEquationConstraint.__init__(self, left, oper, right)
list.__init__(self, constraints)
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."
if self.oper != "=":
return NotImplemented
return all(bool(p) for p in flatiter(self))