comparison liboctave/CMatrix.cc @ 8736:53b4fdeacc2e

improve reduction functions
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 13 Feb 2009 21:04:50 +0100
parents a1ae2aae903e
children 1bd918cfb6e2
comparison
equal deleted inserted replaced
8735:afbfd7f4fd93 8736:53b4fdeacc2e
3262 } 3262 }
3263 3263
3264 ComplexMatrix 3264 ComplexMatrix
3265 ComplexMatrix::cumprod (int dim) const 3265 ComplexMatrix::cumprod (int dim) const
3266 { 3266 {
3267 MX_CUMULATIVE_OP (ComplexMatrix, Complex, *=); 3267 return do_mx_cum_op<ComplexMatrix> (*this, dim, mx_inline_cumprod);
3268 } 3268 }
3269 3269
3270 ComplexMatrix 3270 ComplexMatrix
3271 ComplexMatrix::cumsum (int dim) const 3271 ComplexMatrix::cumsum (int dim) const
3272 { 3272 {
3273 MX_CUMULATIVE_OP (ComplexMatrix, Complex, +=); 3273 return do_mx_cum_op<ComplexMatrix> (*this, dim, mx_inline_cumsum);
3274 } 3274 }
3275 3275
3276 ComplexMatrix 3276 ComplexMatrix
3277 ComplexMatrix::prod (int dim) const 3277 ComplexMatrix::prod (int dim) const
3278 { 3278 {
3279 MX_REDUCTION_OP (ComplexMatrix, *=, 1.0, 1.0); 3279 return do_mx_red_op<ComplexMatrix> (*this, dim, mx_inline_prod);
3280 } 3280 }
3281 3281
3282 ComplexMatrix 3282 ComplexMatrix
3283 ComplexMatrix::sum (int dim) const 3283 ComplexMatrix::sum (int dim) const
3284 { 3284 {
3285 MX_REDUCTION_OP (ComplexMatrix, +=, 0.0, 0.0); 3285 return do_mx_red_op<ComplexMatrix> (*this, dim, mx_inline_sum);
3286 } 3286 }
3287 3287
3288 ComplexMatrix 3288 ComplexMatrix
3289 ComplexMatrix::sumsq (int dim) const 3289 ComplexMatrix::sumsq (int dim) const
3290 { 3290 {
3291 #define ROW_EXPR \ 3291 return do_mx_red_op<Matrix> (*this, dim, mx_inline_sumsq);
3292 Complex d = elem (i, j); \
3293 retval.elem (i, 0) += d * conj (d)
3294
3295 #define COL_EXPR \
3296 Complex d = elem (i, j); \
3297 retval.elem (0, j) += d * conj (d)
3298
3299 MX_BASE_REDUCTION_OP (ComplexMatrix, ROW_EXPR, COL_EXPR, 0.0, 0.0);
3300
3301 #undef ROW_EXPR
3302 #undef COL_EXPR
3303 } 3292 }
3304 3293
3305 Matrix ComplexMatrix::abs (void) const 3294 Matrix ComplexMatrix::abs (void) const
3306 { 3295 {
3307 return Matrix (mx_inline_cabs_dup (data (), length ()), 3296 return Matrix (mx_inline_cabs_dup (data (), length ()),