3
|
1 // Bounds.cc -*- C++ -*- |
|
2 /* |
|
3 |
1011
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
3
|
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 |
238
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
3
|
26 #endif |
|
27 |
|
28 #include <iostream.h> |
238
|
29 |
3
|
30 #include "Bounds.h" |
227
|
31 #include "lo-error.h" |
3
|
32 |
|
33 // error handling |
|
34 |
|
35 void |
|
36 Bounds::error (const char* msg) |
|
37 { |
227
|
38 (*current_liboctave_error_handler) ("fatal bounds error: ", msg); |
3
|
39 } |
|
40 |
|
41 Bounds::Bounds (void) |
|
42 { |
|
43 nb = 0; |
|
44 } |
|
45 |
|
46 Bounds::Bounds (int n) |
|
47 { |
|
48 nb = n; |
|
49 lb.resize (nb); |
|
50 ub.resize (nb); |
|
51 lb.fill (0.0); |
|
52 ub.fill (0.0); |
|
53 } |
|
54 |
|
55 Bounds::Bounds (const ColumnVector l, const ColumnVector u) |
|
56 { |
|
57 if (l.capacity () != u.capacity ()) |
227
|
58 { |
|
59 error ("inconsistent sizes for lower and upper bounds"); |
|
60 return; |
|
61 } |
3
|
62 |
|
63 nb = l.capacity (); |
|
64 lb = l; |
|
65 ub = u; |
|
66 } |
|
67 |
|
68 Bounds::Bounds (const Bounds& a) |
|
69 { |
|
70 nb = a.size (); |
|
71 lb = a.lower_bounds (); |
|
72 ub = a.upper_bounds (); |
|
73 } |
|
74 |
|
75 Bounds& |
|
76 Bounds::operator = (const Bounds& a) |
|
77 { |
|
78 nb = a.size (); |
|
79 lb = a.lower_bounds (); |
|
80 ub = a.upper_bounds (); |
|
81 |
|
82 return *this; |
|
83 } |
|
84 |
|
85 Bounds& |
|
86 Bounds::resize (int n) |
|
87 { |
|
88 nb = n; |
|
89 lb.resize (nb); |
|
90 ub.resize (nb); |
|
91 |
|
92 return *this; |
|
93 } |
|
94 |
|
95 double |
|
96 Bounds::lower_bound (int index) const |
|
97 { |
|
98 return lb.elem (index); |
|
99 } |
|
100 |
|
101 double |
|
102 Bounds::upper_bound (int index) const |
|
103 { |
|
104 return ub.elem (index); |
|
105 } |
|
106 |
|
107 ColumnVector |
|
108 Bounds::lower_bounds (void) const |
|
109 { |
|
110 return lb; |
|
111 } |
|
112 |
|
113 ColumnVector |
|
114 Bounds::upper_bounds (void) const |
|
115 { |
|
116 return ub; |
|
117 } |
|
118 |
|
119 int |
|
120 Bounds::size (void) const |
|
121 { |
|
122 return nb; |
|
123 } |
|
124 |
|
125 Bounds& |
|
126 Bounds::set_bound (int index, double low, double high) |
|
127 { |
|
128 lb.elem (index) = low; |
|
129 ub.elem (index) = high; |
|
130 |
|
131 return *this; |
|
132 } |
|
133 |
|
134 Bounds& |
|
135 Bounds::set_bounds (double low, double high) |
|
136 { |
|
137 lb.fill (low); |
|
138 ub.fill (high); |
|
139 |
|
140 return *this; |
|
141 } |
|
142 |
|
143 Bounds& |
|
144 Bounds::set_bounds (const ColumnVector l, const ColumnVector u) |
|
145 { |
|
146 if (l.capacity () != u.capacity ()) |
227
|
147 { |
|
148 error ("inconsistent sizes for lower and upper bounds"); |
|
149 return *this; |
|
150 } |
3
|
151 |
|
152 nb = l.capacity (); |
|
153 lb = l; |
|
154 ub = u; |
|
155 |
|
156 return *this; |
|
157 } |
|
158 |
|
159 Bounds& |
|
160 Bounds::set_lower_bound (int index, double low) |
|
161 { |
|
162 lb.elem (index) = low; |
|
163 |
|
164 return *this; |
|
165 } |
|
166 |
|
167 Bounds& |
|
168 Bounds::set_upper_bound (int index, double high) |
|
169 { |
|
170 ub.elem (index) = high; |
|
171 |
|
172 return *this; |
|
173 } |
|
174 |
|
175 Bounds& |
|
176 Bounds::set_lower_bounds (double low) |
|
177 { |
|
178 lb.fill (low); |
|
179 |
|
180 return *this; |
|
181 } |
|
182 |
|
183 Bounds& |
|
184 Bounds::set_upper_bounds (double high) |
|
185 { |
|
186 ub.fill (high); |
|
187 |
|
188 return *this; |
|
189 } |
|
190 |
|
191 Bounds& |
|
192 Bounds::set_lower_bounds (const ColumnVector l) |
|
193 { |
|
194 if (nb != l.capacity ()) |
227
|
195 { |
|
196 error ("inconsistent size for lower bounds"); |
|
197 return *this; |
|
198 } |
3
|
199 |
|
200 lb = l; |
|
201 |
|
202 return *this; |
|
203 } |
|
204 |
|
205 Bounds& |
|
206 Bounds::set_upper_bounds (const ColumnVector u) |
|
207 { |
|
208 if (nb != u.capacity ()) |
227
|
209 { |
|
210 error ("inconsistent size for upper bounds"); |
|
211 return *this; |
|
212 } |
3
|
213 |
|
214 ub = u; |
|
215 |
|
216 return *this; |
|
217 } |
|
218 |
|
219 ostream& |
|
220 operator << (ostream& os, const Bounds& b) |
|
221 { |
|
222 for (int i = 0; i < b.size (); i++) |
|
223 os << b.lower_bound (i) << " " << b.upper_bound (i) << "\n"; |
|
224 |
|
225 return os; |
|
226 } |
|
227 |
|
228 /* |
|
229 ;;; Local Variables: *** |
|
230 ;;; mode: C++ *** |
|
231 ;;; page-delimiter: "^/\\*" *** |
|
232 ;;; End: *** |
|
233 */ |