cf.bounds_combination_mode

cf.bounds_combination_mode(*arg)[source]

Determine how to deal with cell bounds in binary operations.

The flag returned by cf.bounds_combination_mode() is used to influence whether or not the result of a binary operation “op(x, y)”, such as x + y, x -= y, x << y, etc., will contain bounds, and if so how those bounds are calculated.

The result of op(x, y) may only contain bounds if

  • x is a construct that may contain bounds, or

  • x does not support the operation and y is a construct that may contain bounds, e.g. 2 + y.

and so the flag only has an effect in these specific cases. Only dimension coordinate, auxiliary coordinate and domain ancillary constructs support bounds.

The behaviour for the different flag values is described by the following truth tables, for which it assumed that it is possible for the result of the operation to contain bounds:

  • If the flag is 'AND' (the default) then

    x

    y

    op(x, y)

    Resulting bounds

    has bounds

    has bounds

    has bounds

    Yes

    Yes

    Yes

    op(x.bounds, y.bounds)

    Yes

    No

    No

    No

    Yes

    No

    No

    No

    No

  • If the flag is 'OR' then

    x

    y

    op(x, y)

    Resulting bounds

    has bounds

    has bounds

    has bounds

    Yes

    Yes

    Yes

    op(x.bounds, y.bounds)

    Yes

    No

    Yes

    op(x.bounds, y)

    No

    Yes

    Yes

    op(x, y.bounds)

    No

    No

    No

  • If the flag is 'XOR' then

    x

    y

    op(x, y)

    Resulting bounds

    has bounds

    has bounds

    has bounds

    Yes

    Yes

    No

    Yes

    No

    Yes

    op(x.bounds, y)

    No

    Yes

    Yes

    op(x, y.bounds)

    No

    No

    No

  • If the flag is 'NONE' then

    x

    y

    op(x, y)

    Resulting bounds

    has bounds

    has bounds

    has bounds

    Yes

    Yes

    No

    Yes

    No

    No

    No

    Yes

    No

    No

    No

    No

New in version 3.8.0.

See also

configuration

Parameters
arg: str or Constant, optional

Provide a new flag value that will apply to all subsequent binary operations.

Returns
str

The value prior to the change, or the current value if no new value was specified.

Examples

>>> old = cf.bounds_combination_mode()
>>> print(old)
AND
>>> print(cf.bounds_combination_mode('OR'))
AND
>>> print(cf.bounds_combination_mode())
OR
>>> print(cf.bounds_combination_mode(old))
OR
>>> print(cf.bounds_combination_mode())
AND

Use as a context manager:

>>> print(cf.bounds_combination_mode())
AND
>>> with cf.bounds_combination_mode('XOR'):
...     print(cf.bounds_combination_mode())
...
XOR
>>> print(cf.bounds_combination_mode())
AND