@@ -25,42 +25,21 @@ A box can be created from:
2525
2626.. tabs ::
2727
28- .. group-tab :: Python
28+ .. group-tab :: Python
2929
30- .. code-block :: py
30+ .. literalinclude :: src.py
31+ :language: py
32+ :start-after: [intervalvector-class-1-beg]
33+ :end-before: [intervalvector-class-1-end]
34+ :dedent: 4
3135
32- # Default box: [-oo,oo]^n
33- x = IntervalVector(3 )
36+ .. group-tab :: C++
3437
35- # Cube [-1,3]^2
36- y = IntervalVector(2 , Interval(- 1 ,3 ))
37-
38- # From a list of bounds (each entry is [lb,ub])
39- z = IntervalVector([[3 ,4 ],[4 ,6 ]]) # [3,4]×[4,6]
40-
41- # From a list of components (Intervals and/or bounds pairs)
42- q = IntervalVector([y[1 ], z[0 ], [0 ,oo]]) # [-1,3]×[3,4]×[0,oo]
43-
44- # From a point (degenerate intervals)
45- p = Vector([0.42 ,0.42 ,0.42 ])
46- bp = IntervalVector(p) # [0.42,0.42]^3
47-
48- .. group-tab :: C++
49-
50- .. code-block :: c++
51-
52- // Default box: [-oo,oo]^n (Interval default constructor)
53- IntervalVector x(3);
54-
55- // Cube [-1,3]^2
56- IntervalVector y(2, Interval(-1,3));
57-
58- // From a list of bounds (initializer-list style)
59- IntervalVector z{{3,4},{4,6}}; // [3,4]×[4,6]
60-
61- // From a point (degenerate intervals)
62- Vector p({0.42,0.42,0.42});
63- IntervalVector bp(p); // [0.42,0.42]^3
38+ .. literalinclude :: src.cpp
39+ :language: c++
40+ :start-after: [intervalvector-class-1-beg]
41+ :end-before: [intervalvector-class-1-end]
42+ :dedent: 4
6443
6544.. note ::
6645
@@ -74,45 +53,22 @@ Components are intervals; indexing is 0-based in Python/C++ and 1-based in Matla
7453
7554.. tabs ::
7655
77- .. group-tab :: Python
78-
79- .. code-block :: py
80-
81- x = IntervalVector(2 , [- 1 ,3 ]) # [-1,3]^2
82- x[1 ] = Interval(0 ,10 ) # [-1,3]×[0,10]
83-
84- # Iterating/accessing over components
85- y = IntervalVector(2 )
86- for i, xi in enumerate (x):
87- y[i] = xi
88-
89- # Unpacking (Python convenience)
90- a,b = x
91- assert a == x[0 ] and b == x[1 ]
92-
93- # Building a new box from existing components
94- v = IntervalVector([* x, [3 ,6 ]]) # concatenation in Python
95- # v == [[-1,3]×[0,10]×[3,6]]
96-
97- # Resize: new components are default-initialized ([-oo,oo])
98- v.resize(4 ) # v == [[-1,3]×[0,10]×[3,6]×[-oo,oo]]
99- s = v.subvector(1 ,2 ) # [0,10]×[3,6]
56+ .. group-tab :: Python
10057
101- .. group-tab :: C++
58+ .. literalinclude :: src.py
59+ :language: py
60+ :start-after: [intervalvector-class-2-beg]
61+ :end-before: [intervalvector-class-2-end]
62+ :dedent: 4
10263
103- .. code-block :: c ++
64+ .. group-tab :: C ++
10465
105- IntervalVector x(2, Interval(-1,3)); // [-1,3]^2
106- x[1] = Interval(0, 10); // [-1,3]×[0,10]
66+ .. literalinclude :: src.cpp
67+ :language: c++
68+ :start-after: [intervalvector-class-2-beg]
69+ :end-before: [intervalvector-class-2-end]
70+ :dedent: 4
10771
108- // Accessing components
109- const Interval& x0 = x[0];
110-
111- // Resize: new components are default-initialized ([-oo,oo])
112- x.resize(4); // x == [-1,3]×[0,10]×[-oo,oo]×[-oo,oo]
113-
114- // Subvector / segment extraction
115- IntervalVector s = x.subvector(1,2); // [0,10]×[-oo,oo]
11672
11773Box properties
11874--------------
@@ -127,30 +83,21 @@ Typical accessors you will use in practice:
12783
12884.. tabs ::
12985
130- .. group-tab :: Python
131-
132- .. code-block :: py
133-
134- x = IntervalVector([[0 ,2 ],[- 1 ,3 ]])
86+ .. group-tab :: Python
13587
136- n = x.size() # dimension
137- # Common box information (component-wise):
138- lo = x.lb() # Vector of lower bounds
139- hi = x.ub() # Vector of upper bounds
140- m = x.mid() # Vector of midpoints
141- d = x.diam() # Vector of diameters
88+ .. literalinclude :: src.py
89+ :language: py
90+ :start-after: [intervalvector-class-3-beg]
91+ :end-before: [intervalvector-class-3-end]
92+ :dedent: 4
14293
143- .. group-tab :: C++
94+ .. group-tab :: C++
14495
145- .. code-block :: c++
146-
147- IntervalVector x{{0,2},{-1,3}};
148-
149- Index n = x.size();
150- Vector lo = x.lb();
151- Vector hi = x.ub();
152- Vector m = x.mid();
153- Vector d = x.diam();
96+ .. literalinclude :: src.cpp
97+ :language: c++
98+ :start-after: [intervalvector-class-3-beg]
99+ :end-before: [intervalvector-class-3-end]
100+ :dedent: 4
154101
155102.. note ::
156103
@@ -171,25 +118,21 @@ Common predicates include:
171118
172119.. tabs ::
173120
174- .. group-tab :: Python
175-
176- .. code-block :: py
177-
178- x = IntervalVector([[0 ,1 ],[2 ,3 ]])
179- y = IntervalVector([[0.5 ,2 ],[1 ,4 ]])
121+ .. group-tab :: Python
180122
181- assert x.intersects(y)
182- assert x.is_subset(y)
123+ .. literalinclude :: src.py
124+ :language: py
125+ :start-after: [intervalvector-class-4-beg]
126+ :end-before: [intervalvector-class-4-end]
127+ :dedent: 4
183128
184- .. group-tab :: C++
129+ .. group-tab :: C++
185130
186- .. code-block :: c++
187-
188- IntervalVector x{{0,1},{2,3}};
189- IntervalVector y{{0.5,2},{1,4}};
190-
191- assert(x.intersects(y));
192- assert(x.is_subset(y));
131+ .. literalinclude :: src.cpp
132+ :language: c++
133+ :start-after: [intervalvector-class-4-beg]
134+ :end-before: [intervalvector-class-4-end]
135+ :dedent: 4
193136
194137Advanced operations
195138-------------------
@@ -220,29 +163,23 @@ Because ``IntervalVector`` is a vector of ``Interval``, standard arithmetic is n
220163* interactions with real vectors/matrices,
221164* matrix–vector products involving :class: `~codac.IntervalMatrix `.
222165
223- .. tabs ::
224-
225- .. group-tab :: Python
226-
227- .. code-block :: py
228-
229- x = IntervalVector([[0 ,1 ],[2 ,3 ]])
230- y = IntervalVector([[1 ,2 ],[0 ,1 ]])
231-
232- z1 = x+ y
233- z2 = 2 * x
234- z3 = x- 1
166+ .. tabs ::
235167
236- .. group-tab :: C++
168+ .. group-tab :: Python
237169
238- .. code-block :: c++
170+ .. literalinclude :: src.py
171+ :language: py
172+ :start-after: [intervalvector-class-5-beg]
173+ :end-before: [intervalvector-class-5-end]
174+ :dedent: 4
239175
240- IntervalVector x{{0,1},{2,3}};
241- IntervalVector y{{1,2},{0,1}};
176+ .. group-tab :: C++
242177
243- IntervalVector z1 = x+y;
244- IntervalVector z2 = 2.*x;
245- IntervalVector z3 = x-1.;
178+ .. literalinclude :: src.cpp
179+ :language: c++
180+ :start-after: [intervalvector-class-5-beg]
181+ :end-before: [intervalvector-class-5-end]
182+ :dedent: 4
246183
247184
248185.. admonition :: Technical documentation
0 commit comments