Mercurial > hg > octave-nkf
comparison liboctave/mx-inlines.cc @ 9612:66970dd627f6
further liboctave design improvements
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 04 Sep 2009 11:22:53 +0200 |
parents | 1be3c73ed7b5 |
children | 9ecd35a606e3 |
comparison
equal
deleted
inserted
replaced
9611:6f42ea240b3a | 9612:66970dd627f6 |
---|---|
166 DEFMXBOOLOP (mx_inline_not_and, !, &, ) | 166 DEFMXBOOLOP (mx_inline_not_and, !, &, ) |
167 DEFMXBOOLOP (mx_inline_not_or, !, |, ) | 167 DEFMXBOOLOP (mx_inline_not_or, !, |, ) |
168 DEFMXBOOLOP (mx_inline_and_not, , &, !) | 168 DEFMXBOOLOP (mx_inline_and_not, , &, !) |
169 DEFMXBOOLOP (mx_inline_or_not, , |, !) | 169 DEFMXBOOLOP (mx_inline_or_not, , |, !) |
170 | 170 |
171 #define DEFMXBOOLOPEQ(F, OP) \ | |
172 template <class X> \ | |
173 inline void F (size_t n, bool *r, const X *x) \ | |
174 { \ | |
175 for (size_t i = 0; i < n; i++) \ | |
176 r[i] OP logical_value (x[i]); \ | |
177 } \ | |
178 | |
179 DEFMXBOOLOPEQ (mx_inline_and2, &=) | |
180 DEFMXBOOLOPEQ (mx_inline_or2, |=) | |
181 | |
171 template <class T> | 182 template <class T> |
172 inline bool | 183 inline bool |
173 mx_inline_any_nan (size_t, const T*) { return false; } | 184 mx_inline_any_nan (size_t, const T*) { return false; } |
174 | 185 |
175 #define DEFMXANYNAN(T) \ | 186 #define DEFMXANYNAN(T) \ |
228 do_mx_unary_op (const XNDA& x, | 239 do_mx_unary_op (const XNDA& x, |
229 void (*op) (size_t, typename RNDA::element_type *, | 240 void (*op) (size_t, typename RNDA::element_type *, |
230 const typename XNDA::element_type *)) | 241 const typename XNDA::element_type *)) |
231 { | 242 { |
232 RNDA r (x.dims ()); | 243 RNDA r (x.dims ()); |
233 op (r.nelem (), r.fortran_vec (), x.data ()); | 244 op (r.length (), r.fortran_vec (), x.data ()); |
234 return r; | 245 return r; |
235 } | 246 } |
236 | 247 |
237 template <class RNDA> | 248 template <class RNDA> |
238 inline RNDA& | 249 inline RNDA& |
254 { | 265 { |
255 dim_vector dx = x.dims (), dy = y.dims (); | 266 dim_vector dx = x.dims (), dy = y.dims (); |
256 if (dx == dy) | 267 if (dx == dy) |
257 { | 268 { |
258 RNDA r (dx); | 269 RNDA r (dx); |
259 op (r.nelem (), r.fortran_vec (), x.data (), y.data ()); | 270 op (r.length (), r.fortran_vec (), x.data (), y.data ()); |
260 return r; | 271 return r; |
261 } | 272 } |
262 else | 273 else |
263 { | 274 { |
264 gripe_nonconformant (opname, dx, dy); | 275 gripe_nonconformant (opname, dx, dy); |
271 do_ms_binary_op (const XNDA& x, const YS& y, | 282 do_ms_binary_op (const XNDA& x, const YS& y, |
272 void (*op) (size_t, typename RNDA::element_type *, | 283 void (*op) (size_t, typename RNDA::element_type *, |
273 const typename XNDA::element_type *, YS)) | 284 const typename XNDA::element_type *, YS)) |
274 { | 285 { |
275 RNDA r (x.dims ()); | 286 RNDA r (x.dims ()); |
276 op (r.nelem (), r.fortran_vec (), x.data (), y); | 287 op (r.length (), r.fortran_vec (), x.data (), y); |
277 return r; | 288 return r; |
278 } | 289 } |
279 | 290 |
280 template <class RNDA, class XS, class YNDA> | 291 template <class RNDA, class XS, class YNDA> |
281 inline RNDA | 292 inline RNDA |
282 do_sm_binary_op (const XS& x, const YNDA& y, | 293 do_sm_binary_op (const XS& x, const YNDA& y, |
283 void (*op) (size_t, typename RNDA::element_type *, XS, | 294 void (*op) (size_t, typename RNDA::element_type *, XS, |
284 const typename YNDA::element_type *)) | 295 const typename YNDA::element_type *)) |
285 { | 296 { |
286 RNDA r (y.dims ()); | 297 RNDA r (y.dims ()); |
287 op (r.nelem (), r.fortran_vec (), x, y.data ()); | 298 op (r.length (), r.fortran_vec (), x, y.data ()); |
288 return r; | 299 return r; |
289 } | 300 } |
290 | 301 |
291 template <class RNDA, class XNDA> | 302 template <class RNDA, class XNDA> |
292 inline RNDA& | 303 inline RNDA& |
295 const typename XNDA::element_type *), | 306 const typename XNDA::element_type *), |
296 const char *opname) | 307 const char *opname) |
297 { | 308 { |
298 dim_vector dr = r.dims (), dx = x.dims (); | 309 dim_vector dr = r.dims (), dx = x.dims (); |
299 if (dr == dx) | 310 if (dr == dx) |
300 { | 311 op (r.length (), r.fortran_vec (), x.data ()); |
301 op (r.nelem (), r.fortran_vec (), x.data ()); | |
302 return r; | |
303 } | |
304 else | 312 else |
305 { | 313 gripe_nonconformant (opname, dr, dx); |
306 gripe_nonconformant (opname, dr, dx); | 314 return r; |
307 return RNDA (); | |
308 } | |
309 } | 315 } |
310 | 316 |
311 template <class RNDA, class XS> | 317 template <class RNDA, class XS> |
312 inline RNDA& | 318 inline RNDA& |
313 do_ms_inplace_op (RNDA& r, const XS& x, | 319 do_ms_inplace_op (RNDA& r, const XS& x, |
314 void (*op) (size_t, typename RNDA::element_type *, XS)) | 320 void (*op) (size_t, typename RNDA::element_type *, XS)) |
315 { | 321 { |
316 op (r.nelem (), r.fortran_vec (), x); | 322 op (r.length (), r.fortran_vec (), x); |
317 return r; | 323 return r; |
318 } | 324 } |
319 | 325 |
320 template <class T1, class T2> | 326 template <class T1, class T2> |
321 inline bool | 327 inline bool |