3
|
1 // Bounds.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef __GNUG__ |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 #include <iostream.h> |
|
29 #include "Bounds.h" |
227
|
30 #include "lo-error.h" |
3
|
31 |
|
32 // error handling |
|
33 |
|
34 void |
|
35 Bounds::error (const char* msg) |
|
36 { |
227
|
37 (*current_liboctave_error_handler) ("fatal bounds error: ", msg); |
3
|
38 } |
|
39 |
|
40 Bounds::Bounds (void) |
|
41 { |
|
42 nb = 0; |
|
43 } |
|
44 |
|
45 Bounds::Bounds (int n) |
|
46 { |
|
47 nb = n; |
|
48 lb.resize (nb); |
|
49 ub.resize (nb); |
|
50 lb.fill (0.0); |
|
51 ub.fill (0.0); |
|
52 } |
|
53 |
|
54 Bounds::Bounds (const ColumnVector l, const ColumnVector u) |
|
55 { |
|
56 if (l.capacity () != u.capacity ()) |
227
|
57 { |
|
58 error ("inconsistent sizes for lower and upper bounds"); |
|
59 return; |
|
60 } |
3
|
61 |
|
62 nb = l.capacity (); |
|
63 lb = l; |
|
64 ub = u; |
|
65 } |
|
66 |
|
67 Bounds::Bounds (const Bounds& a) |
|
68 { |
|
69 nb = a.size (); |
|
70 lb = a.lower_bounds (); |
|
71 ub = a.upper_bounds (); |
|
72 } |
|
73 |
|
74 Bounds& |
|
75 Bounds::operator = (const Bounds& a) |
|
76 { |
|
77 nb = a.size (); |
|
78 lb = a.lower_bounds (); |
|
79 ub = a.upper_bounds (); |
|
80 |
|
81 return *this; |
|
82 } |
|
83 |
|
84 Bounds& |
|
85 Bounds::resize (int n) |
|
86 { |
|
87 nb = n; |
|
88 lb.resize (nb); |
|
89 ub.resize (nb); |
|
90 |
|
91 return *this; |
|
92 } |
|
93 |
|
94 double |
|
95 Bounds::lower_bound (int index) const |
|
96 { |
|
97 return lb.elem (index); |
|
98 } |
|
99 |
|
100 double |
|
101 Bounds::upper_bound (int index) const |
|
102 { |
|
103 return ub.elem (index); |
|
104 } |
|
105 |
|
106 ColumnVector |
|
107 Bounds::lower_bounds (void) const |
|
108 { |
|
109 return lb; |
|
110 } |
|
111 |
|
112 ColumnVector |
|
113 Bounds::upper_bounds (void) const |
|
114 { |
|
115 return ub; |
|
116 } |
|
117 |
|
118 int |
|
119 Bounds::size (void) const |
|
120 { |
|
121 return nb; |
|
122 } |
|
123 |
|
124 Bounds& |
|
125 Bounds::set_bound (int index, double low, double high) |
|
126 { |
|
127 lb.elem (index) = low; |
|
128 ub.elem (index) = high; |
|
129 |
|
130 return *this; |
|
131 } |
|
132 |
|
133 Bounds& |
|
134 Bounds::set_bounds (double low, double high) |
|
135 { |
|
136 lb.fill (low); |
|
137 ub.fill (high); |
|
138 |
|
139 return *this; |
|
140 } |
|
141 |
|
142 Bounds& |
|
143 Bounds::set_bounds (const ColumnVector l, const ColumnVector u) |
|
144 { |
|
145 if (l.capacity () != u.capacity ()) |
227
|
146 { |
|
147 error ("inconsistent sizes for lower and upper bounds"); |
|
148 return *this; |
|
149 } |
3
|
150 |
|
151 nb = l.capacity (); |
|
152 lb = l; |
|
153 ub = u; |
|
154 |
|
155 return *this; |
|
156 } |
|
157 |
|
158 Bounds& |
|
159 Bounds::set_lower_bound (int index, double low) |
|
160 { |
|
161 lb.elem (index) = low; |
|
162 |
|
163 return *this; |
|
164 } |
|
165 |
|
166 Bounds& |
|
167 Bounds::set_upper_bound (int index, double high) |
|
168 { |
|
169 ub.elem (index) = high; |
|
170 |
|
171 return *this; |
|
172 } |
|
173 |
|
174 Bounds& |
|
175 Bounds::set_lower_bounds (double low) |
|
176 { |
|
177 lb.fill (low); |
|
178 |
|
179 return *this; |
|
180 } |
|
181 |
|
182 Bounds& |
|
183 Bounds::set_upper_bounds (double high) |
|
184 { |
|
185 ub.fill (high); |
|
186 |
|
187 return *this; |
|
188 } |
|
189 |
|
190 Bounds& |
|
191 Bounds::set_lower_bounds (const ColumnVector l) |
|
192 { |
|
193 if (nb != l.capacity ()) |
227
|
194 { |
|
195 error ("inconsistent size for lower bounds"); |
|
196 return *this; |
|
197 } |
3
|
198 |
|
199 lb = l; |
|
200 |
|
201 return *this; |
|
202 } |
|
203 |
|
204 Bounds& |
|
205 Bounds::set_upper_bounds (const ColumnVector u) |
|
206 { |
|
207 if (nb != u.capacity ()) |
227
|
208 { |
|
209 error ("inconsistent size for upper bounds"); |
|
210 return *this; |
|
211 } |
3
|
212 |
|
213 ub = u; |
|
214 |
|
215 return *this; |
|
216 } |
|
217 |
|
218 ostream& |
|
219 operator << (ostream& os, const Bounds& b) |
|
220 { |
|
221 for (int i = 0; i < b.size (); i++) |
|
222 os << b.lower_bound (i) << " " << b.upper_bound (i) << "\n"; |
|
223 |
|
224 return os; |
|
225 } |
|
226 |
|
227 /* |
|
228 ;;; Local Variables: *** |
|
229 ;;; mode: C++ *** |
|
230 ;;; page-delimiter: "^/\\*" *** |
|
231 ;;; End: *** |
|
232 */ |