comparison liboctave/MArray.cc @ 1230:92609e161b29

[project @ 1995-04-10 01:08:57 by jwe]
author jwe
date Mon, 10 Apr 1995 01:14:34 +0000
parents 9689615b34f2
children f93b7fa5e113
comparison
equal deleted inserted replaced
1229:7d7c3eaa1d3b 1230:92609e161b29
75 for (int i = 0; i < l; i++) \ 75 for (int i = 0; i < l; i++) \
76 result[i] = -x[i]; \ 76 result[i] = -x[i]; \
77 } 77 }
78 78
79 #define DO_VS_OP2(OP) \ 79 #define DO_VS_OP2(OP) \
80 int l = length (); \ 80 int l = a.length (); \
81 if (l > 0) \ 81 if (l > 0) \
82 { \ 82 { \
83 T *tmp = fortran_vec (); \ 83 T *tmp = a.fortran_vec (); \
84 for (int i = 0; i < l; i++) \ 84 for (int i = 0; i < l; i++) \
85 tmp[i] OP s; \ 85 tmp[i] OP s; \
86 } 86 }
87 87
88 #define DO_VV_OP2(OP) \ 88 #define DO_VV_OP2(OP) \
89 do \ 89 do \
90 { \ 90 { \
91 T *tmp = fortran_vec (); \ 91 T *a_tmp = a.fortran_vec (); \
92 const T *rhs = a.data (); \ 92 const T *b_tmp = b.data (); \
93 for (int i = 0; i < l; i++) \ 93 for (int i = 0; i < l; i++) \
94 tmp[i] += rhs[i]; \ 94 a_tmp[i] += b_tmp[i]; \
95 } \ 95 } \
96 while (0) 96 while (0)
97 97
98 /* 98 /*
99 * One dimensional array with math ops. 99 * One dimensional array with math ops.
101 101
102 // Element by element MArray by scalar ops. 102 // Element by element MArray by scalar ops.
103 103
104 template <class T> 104 template <class T>
105 MArray<T>& 105 MArray<T>&
106 MArray<T>::operator += (const T& s) 106 operator += (MArray<T>& a, const T& s)
107 { 107 {
108 DO_VS_OP2 (+=) 108 DO_VS_OP2 (+=)
109 return *this; 109 return a;
110 } 110 }
111 111
112 template <class T> 112 template <class T>
113 MArray<T>& 113 MArray<T>&
114 MArray<T>::operator -= (const T& s) 114 operator -= (MArray<T>& a, const T& s)
115 { 115 {
116 DO_VS_OP2 (-=) 116 DO_VS_OP2 (-=)
117 return *this; 117 return a;
118 } 118 }
119 119
120 // Element by element MArray by MArray ops. 120 // Element by element MArray by MArray ops.
121 121
122 template <class T> 122 template <class T>
123 MArray<T>& 123 MArray<T>&
124 MArray<T>::operator += (const MArray<T>& a) 124 operator += (MArray<T>& a, const MArray<T>& b)
125 { 125 {
126 int l = length (); 126 int l = a.length ();
127 if (l > 0) 127 if (l > 0)
128 { 128 {
129 if (l != a.length ()) 129 if (l != b.length ())
130 (*current_liboctave_error_handler) \ 130 (*current_liboctave_error_handler) \
131 ("nonconformant += array operation attempted"); \ 131 ("nonconformant += array operation attempted"); \
132 else 132 else
133 DO_VV_OP2 (+=); 133 DO_VV_OP2 (+=);
134 } 134 }
135 return *this; 135 return a;
136 } 136 }
137 137
138 template <class T> 138 template <class T>
139 MArray<T>& 139 MArray<T>&
140 MArray<T>::operator -= (const MArray<T>& a) 140 operator -= (MArray<T>& a, const MArray<T>& b)
141 { 141 {
142 int l = length (); 142 int l = a.length ();
143 if (l > 0) 143 if (l > 0)
144 { 144 {
145 if (l != a.length ()) 145 if (l != b.length ())
146 (*current_liboctave_error_handler) \ 146 (*current_liboctave_error_handler) \
147 ("nonconformant -= array operation attempted"); \ 147 ("nonconformant -= array operation attempted"); \
148 else 148 else
149 DO_VV_OP2 (-=); 149 DO_VV_OP2 (-=);
150 } 150 }
151 return *this; 151 return a;
152 } 152 }
153 153
154 // Element by element MArray by scalar ops. 154 // Element by element MArray by scalar ops.
155 155
156 #define MARRAY_AS_OP(OP) \ 156 #define MARRAY_AS_OP(OP) \
232 232
233 // Element by element MArray2 by scalar ops. 233 // Element by element MArray2 by scalar ops.
234 234
235 template <class T> 235 template <class T>
236 MArray2<T>& 236 MArray2<T>&
237 MArray2<T>::operator += (const T& s) 237 operator += (MArray2<T>& a, const T& s)
238 { 238 {
239 DO_VS_OP2 (+=) 239 DO_VS_OP2 (+=)
240 return *this; 240 return a;
241 } 241 }
242 242
243 template <class T> 243 template <class T>
244 MArray2<T>& 244 MArray2<T>&
245 MArray2<T>::operator -= (const T& s) 245 operator -= (MArray2<T>& a, const T& s)
246 { 246 {
247 DO_VS_OP2 (-=) 247 DO_VS_OP2 (-=)
248 return *this; 248 return a;
249 } 249 }
250 250
251 // Element by element MArray2 by MArray2 ops. 251 // Element by element MArray2 by MArray2 ops.
252 252
253 template <class T> 253 template <class T>
254 MArray2<T>& 254 MArray2<T>&
255 MArray2<T>::operator += (const MArray2<T>& a) 255 operator += (MArray2<T>& a, const MArray2<T>& b)
256 { 256 {
257 int r = rows (); 257 int r = a.rows ();
258 int c = cols (); 258 int c = a.cols ();
259 if (r != a.rows () || c != a.cols ()) 259 if (r != b.rows () || c != b.cols ())
260 { 260 {
261 (*current_liboctave_error_handler) 261 (*current_liboctave_error_handler)
262 ("nonconformant += array operation attempted"); 262 ("nonconformant += array operation attempted");
263 } 263 }
264 else 264 else
267 { 267 {
268 int l = a.length (); 268 int l = a.length ();
269 DO_VV_OP2 (+=); 269 DO_VV_OP2 (+=);
270 } 270 }
271 } 271 }
272 return *this; 272 return a;
273 } 273 }
274 274
275 template <class T> 275 template <class T>
276 MArray2<T>& 276 MArray2<T>&
277 MArray2<T>::operator -= (const MArray2<T>& a) 277 operator -= (MArray2<T>& a, const MArray2<T>& b)
278 { 278 {
279 int r = rows (); 279 int r = a.rows ();
280 int c = cols (); 280 int c = a.cols ();
281 if (r != a.rows () || c != a.cols ()) 281 if (r != b.rows () || c != b.cols ())
282 { 282 {
283 (*current_liboctave_error_handler) 283 (*current_liboctave_error_handler)
284 ("nonconformant -= array operation attempted"); 284 ("nonconformant -= array operation attempted");
285 } 285 }
286 else 286 else
289 { 289 {
290 int l = a.length (); 290 int l = a.length ();
291 DO_VV_OP2 (-=); 291 DO_VV_OP2 (-=);
292 } 292 }
293 } 293 }
294 return *this; 294 return a;
295 } 295 }
296 296
297 // Element by element MArray2 by scalar ops. 297 // Element by element MArray2 by scalar ops.
298 298
299 #define MARRAY_A2S_OP(OP) \ 299 #define MARRAY_A2S_OP(OP) \
369 369
370 // Element by element MDiagArray by MDiagArray ops. 370 // Element by element MDiagArray by MDiagArray ops.
371 371
372 template <class T> 372 template <class T>
373 MDiagArray<T>& 373 MDiagArray<T>&
374 MDiagArray<T>::operator += (const MDiagArray<T>& a) 374 operator += (MDiagArray<T>& a, const MDiagArray<T>& b)
375 { 375 {
376 // XXX FIXME XXX 376 int r = a.rows ();
377 return *this; 377 int c = a.cols ();
378 if (r != b.rows () || c != b.cols ())
379 {
380 (*current_liboctave_error_handler)
381 ("nonconformant array " OP_STR " attempted");
382 return MArray2<T> ();
383 }
384 else
385 {
386 int l = a.length ();
387 T *a_tmp = a.fortran_vec ();
388 const T *b_tmp = b.data ();
389 for (int i = 0; i < l; i++)
390 a_tmp[i] += b_tmp[i];
391 }
392 return a;
378 } 393 }
379 394
380 template <class T> 395 template <class T>
381 MDiagArray<T>& 396 MDiagArray<T>&
382 MDiagArray<T>::operator -= (const MDiagArray<T>& a) 397 operator -= (MDiagArray<T>& a, const MDiagArray<T>& b)
383 { 398 {
384 // XXX FIXME XXX 399 int r = a.rows ();
385 return *this; 400 int c = a.cols ();
401 if (r != b.rows () || c != b.cols ())
402 {
403 (*current_liboctave_error_handler)
404 ("nonconformant array " OP_STR " attempted");
405 return MArray2<T> ();
406 }
407 else
408 {
409 int l = a.length ();
410 T *a_tmp = a.fortran_vec ();
411 const T *b_tmp = b.data ();
412 for (int i = 0; i < l; i++)
413 a_tmp[i] -= b_tmp[i];
414 }
415 return a;
386 } 416 }
387 417
388 // Element by element MDiagArray by scalar ops. 418 // Element by element MDiagArray by scalar ops.
389 419
390 #define MARRAY_DAS_OP(OP) \ 420 #define MARRAY_DAS_OP(OP) \