7.1. IntervalArithmetic
¶
This module implements interval arithmetic.
-
class
IntervalArithmetic.
Interval
(*args, **kwargs)[source]¶ Bases:
object
Interval [inf, sup] in the float domain.
An interval can be constructed using a couple (inf, sup) or an object that support the
__getitem__()
interface:Interval(inf, sup) Interval((inf, sup)) Interval(iterable) Interval(interval)
To get the interval boundaries, use the
inf
andsup
attribute.An empty interval is defined with inf and sup set to
None
.To compute the union of two intervals use:
i3 = i1 | i2 i1 |= i2
To compute the intersection of two intervals use:
i3 = i1 & i2 i1 &= i2
It returns an empty interval if the intersection is null.
-
center
¶ Return the interval’s center.
-
is_left_open
¶
-
is_right_open
¶
-
length
¶ Return
sup - inf
.
-
map_x_in
(x, clamp=False)[source]¶ Return
x - inf
. If clamp parameter is set True then the value is clamped in the interval.
-
radius
¶ Return length / 2.
-
-
class
IntervalArithmetic.
IntervalInt
(*args, **kwargs)[source]¶ Bases:
IntervalArithmetic.Interval
Interval [inf, sup] in the integer domain.
-
is_left_open
¶
-
is_right_open
¶
-
length
¶ Return
sup - inf +1
.
-
length_float
¶ Return
sup - inf
.
-
slice
¶ Return a slice instance.
-
-
class
IntervalArithmetic.
IntervalIntSupOpen
(*args)[source]¶ Bases:
IntervalArithmetic.IntervalInt
Interval [inf, sup[ in the integer domain.
-
exclude
(i1, i2)[source]¶ Compute the subset intervals of i1 given an exclusion interval i2.
It returns
None
if the intervals don’t intersect or i1 is included in i2. Else it returns a list of couples (interval, excluded_flag) where interval is a subset of the interval i1 and excluded_flag indicated if the subset is excluded.
-
-
class
IntervalArithmetic.
Interval2D
(x, y)[source]¶ Bases:
object
Interval [inf, sup]*[inf, sup] in the float domain.
The components can be accessed using the
x
andy
attribute, or using an index interface where the index 0 maps to x and 1 to y, respectively.-
area
¶ Return the area.
-
bounding_box
¶ Return the corresponding bounding box
(x.inf, y.inf, x.sup, y.sup)
.
-
center
¶ Return the interval’s center.
-
diagonal
¶ Return the diagonal’s length.
-
radius
¶ Return the horizontal and vertical radius.
-
size
¶ Return the horizontal and vertical length.
-
-
class
IntervalArithmetic.
IntervalInt2D
(x, y)[source]¶ Bases:
IntervalArithmetic.Interval2D
Interval [inf, sup]*[inf, sup] in the integer domain.