designspace.count#

designspace.count(*exprs: BoolExpr) ArithExpr#

How many of exprs are true, as a number.

The way to write “at most two of these”, which is otherwise awkward: the result is arithmetic, so it can be compared.

Parameters:

*exprs (BoolExpr) – The conditions to count.

Returns:

An integer-valued expression.

Return type:

ArithExpr

Raises:

TypeError – If any argument is not a boolean expression.

Examples

>>> s = ds.space(
...     ds.param("a").bool(),
...     ds.param("b").bool(),
...     ds.param("c").bool(),
... )
>>> s = s.require(ds.count(ds.param("a"), ds.param("b"), ds.param("c")) <= 2)
>>> s.is_feasible({"a": True, "b": True, "c": False})
True
>>> s.is_feasible({"a": True, "b": True, "c": True})
False