# HG changeset patch # User Jaroslav Hajek # Date 1234788791 -3600 # Node ID c32a08dccae68ea92b19d70d5523a2d45add7ced # Parent 83c9d60c3c47a0d2f13251c7ece404be5247db6d remove unused macros from mx-inlines.cc diff -r 83c9d60c3c47 -r c32a08dccae6 liboctave/ChangeLog --- a/liboctave/ChangeLog Mon Feb 16 13:53:09 2009 +0100 +++ b/liboctave/ChangeLog Mon Feb 16 13:53:11 2009 +0100 @@ -2,6 +2,11 @@ * mx-inlines.cc (OP_ROW_SHORT_CIRCUIT): New macro. (mx_inline_any, mx_inline_all): Override row-reduction case. + (MX_CUMULATIVE_OP, MX_BASE_REDUCTION_OP, MX_REDUCTION_OP, + MX_ANY_OP, MX_ALL_OP, MX_ND_ANY_ALL, MX_ND_REDUCTION, + MX_ND_COMPLEX_OP_REDUCTION, MX_ND_CUMULATIVE_OP, + MX_ND_ANY_EVAL, MX_ND_ALL_EVAL, MX_ND_REAL_OP_REDUCTION): + Remove unused macros. 2009-02-16 Jaroslav Hajek diff -r 83c9d60c3c47 -r c32a08dccae6 liboctave/mx-inlines.cc --- a/liboctave/mx-inlines.cc Mon Feb 16 13:53:09 2009 +0100 +++ b/liboctave/mx-inlines.cc Mon Feb 16 13:53:11 2009 +0100 @@ -769,369 +769,6 @@ return ret; } -// Avoid some code duplication. Maybe we should use templates. - -#define MX_CUMULATIVE_OP(RET_TYPE, ELT_TYPE, OP) \ - \ - octave_idx_type nr = rows (); \ - octave_idx_type nc = cols (); \ - \ - RET_TYPE retval (nr, nc); \ - \ - if (nr > 0 && nc > 0) \ - { \ - if ((nr == 1 && dim == -1) || dim == 1) \ - { \ - for (octave_idx_type i = 0; i < nr; i++) \ - { \ - ELT_TYPE t = elem (i, 0); \ - for (octave_idx_type j = 0; j < nc; j++) \ - { \ - retval.elem (i, j) = t; \ - if (j < nc - 1) \ - t OP elem (i, j+1); \ - } \ - } \ - } \ - else \ - { \ - for (octave_idx_type j = 0; j < nc; j++) \ - { \ - ELT_TYPE t = elem (0, j); \ - for (octave_idx_type i = 0; i < nr; i++) \ - { \ - retval.elem (i, j) = t; \ - if (i < nr - 1) \ - t OP elem (i+1, j); \ - } \ - } \ - } \ - } \ - \ - return retval - -#define MX_BASE_REDUCTION_OP(RET_TYPE, ROW_EXPR, COL_EXPR, INIT_VAL, \ - MT_RESULT) \ - \ - octave_idx_type nr = rows (); \ - octave_idx_type nc = cols (); \ - \ - RET_TYPE retval; \ - \ - if (nr > 0 && nc > 0) \ - { \ - if ((nr == 1 && dim == -1) || dim == 1) \ - { \ - retval.resize (nr, 1); \ - for (octave_idx_type i = 0; i < nr; i++) \ - { \ - retval.elem (i, 0) = INIT_VAL; \ - for (octave_idx_type j = 0; j < nc; j++) \ - { \ - ROW_EXPR; \ - } \ - } \ - } \ - else \ - { \ - retval.resize (1, nc); \ - for (octave_idx_type j = 0; j < nc; j++) \ - { \ - retval.elem (0, j) = INIT_VAL; \ - for (octave_idx_type i = 0; i < nr; i++) \ - { \ - COL_EXPR; \ - } \ - } \ - } \ - } \ - else if (nc == 0 && (nr == 0 || (nr == 1 && dim == -1))) \ - retval.resize (1, 1, MT_RESULT); \ - else if (nr == 0 && (dim == 0 || dim == -1)) \ - retval.resize (1, nc, MT_RESULT); \ - else if (nc == 0 && dim == 1) \ - retval.resize (nr, 1, MT_RESULT); \ - else \ - retval.resize (nr > 0, nc > 0); \ - \ - return retval - -#define MX_REDUCTION_OP_ROW_EXPR(OP) \ - retval.elem (i, 0) OP elem (i, j) - -#define MX_REDUCTION_OP_COL_EXPR(OP) \ - retval.elem (0, j) OP elem (i, j) - -#define MX_REDUCTION_OP(RET_TYPE, OP, INIT_VAL, MT_RESULT) \ - MX_BASE_REDUCTION_OP (RET_TYPE, \ - MX_REDUCTION_OP_ROW_EXPR (OP), \ - MX_REDUCTION_OP_COL_EXPR (OP), \ - INIT_VAL, MT_RESULT) - -#define MX_ANY_ALL_OP_ROW_CODE(TEST_OP, TEST_TRUE_VAL) \ - if (elem (i, j) TEST_OP 0.0) \ - { \ - retval.elem (i, 0) = TEST_TRUE_VAL; \ - break; \ - } - -#define MX_ANY_ALL_OP_COL_CODE(TEST_OP, TEST_TRUE_VAL) \ - if (elem (i, j) TEST_OP 0.0) \ - { \ - retval.elem (0, j) = TEST_TRUE_VAL; \ - break; \ - } - -#define MX_ANY_ALL_OP(DIM, INIT_VAL, TEST_OP, TEST_TRUE_VAL) \ - MX_BASE_REDUCTION_OP (boolMatrix, \ - MX_ANY_ALL_OP_ROW_CODE (TEST_OP, TEST_TRUE_VAL), \ - MX_ANY_ALL_OP_COL_CODE (TEST_OP, TEST_TRUE_VAL), \ - INIT_VAL, INIT_VAL) - -#define MX_ALL_OP(DIM) MX_ANY_ALL_OP (DIM, true, ==, false) - -#define MX_ANY_OP(DIM) MX_ANY_ALL_OP (DIM, false, !=, true) - -#define MX_ND_ALL_EXPR elem (iter_idx) == 0 - -#define MX_ND_ANY_EXPR elem (iter_idx) != 0 - -#define MX_ND_ALL_EVAL(TEST_EXPR) \ - if (retval(result_idx) && (TEST_EXPR)) \ - retval(result_idx) = 0; - -#define MX_ND_ANY_EVAL(TEST_EXPR) \ - if (retval(result_idx) || (TEST_EXPR)) \ - retval(result_idx) = 1; - -#define MX_ND_REDUCTION(EVAL_EXPR, INIT_VAL, RET_TYPE) \ - \ - RET_TYPE retval; \ - \ - dim_vector dv = this->dims (); \ - int nd = this->ndims (); \ - \ - int empty = false; \ - \ - for (int i = 0; i < nd; i++) \ - { \ - if (dv(i) == 0) \ - { \ - empty = true; \ - break; \ - } \ - } \ - \ - if (nd == 2 && dv(0) == 0 && dv(1) == 0) \ - { \ - retval.resize (dim_vector (1, 1), INIT_VAL); \ - return retval; \ - } \ - \ - /* We need to find first non-singleton dim. */ \ - \ - if (dim == -1) \ - { \ - dim = 0; \ - \ - for (int i = 0; i < nd; i++) \ - { \ - if (dv(i) != 1) \ - { \ - dim = i; \ - break; \ - } \ - } \ - } \ - else if (dim >= nd) \ - { \ - dim = nd++; \ - dv.resize (nd, 1); \ - } \ - \ - /* R = op (A, DIM) \ - \ - The strategy here is to access the elements of A along the \ - dimension specified by DIM. This means that we loop over each \ - element of R and adjust the index into A as needed. Store the \ - cummulative product of all dimensions of A in CP_SZ. The last \ - element of CP_SZ is the total number of elements of A. */ \ - \ - Array cp_sz (nd+1, 1); \ - for (int i = 1; i <= nd; i++) \ - cp_sz(i) = cp_sz(i-1)*dv(i-1); \ - \ - octave_idx_type reset_at = cp_sz(dim); \ - octave_idx_type base_incr = cp_sz(dim+1); \ - octave_idx_type incr = cp_sz(dim); \ - octave_idx_type base = 0; \ - octave_idx_type next_base = base + base_incr; \ - octave_idx_type iter_idx = base; \ - octave_idx_type n_elts = dv(dim); \ - \ - dv(dim) = 1; \ - \ - retval.resize (dv, INIT_VAL); \ - \ - if (! empty) \ - { \ - octave_idx_type nel = dv.numel (); \ - \ - octave_idx_type k = 1; \ - \ - for (octave_idx_type result_idx = 0; result_idx < nel; result_idx++) \ - { \ - OCTAVE_QUIT; \ - \ - for (octave_idx_type j = 0; j < n_elts; j++) \ - { \ - OCTAVE_QUIT; \ - \ - EVAL_EXPR; \ - \ - iter_idx += incr; \ - } \ - \ - if (k == reset_at) \ - { \ - base = next_base; \ - next_base += base_incr; \ - iter_idx = base; \ - k = 1; \ - } \ - else \ - { \ - base++; \ - iter_idx = base; \ - k++; \ - } \ - } \ - } \ - \ - retval.chop_trailing_singletons (); \ - \ - return retval - -#define MX_ND_REAL_OP_REDUCTION(ASN_EXPR, INIT_VAL) \ - MX_ND_REDUCTION (retval(result_idx) ASN_EXPR, INIT_VAL, NDArray) - -#define MX_ND_COMPLEX_OP_REDUCTION(ASN_EXPR, INIT_VAL) \ - MX_ND_REDUCTION (retval(result_idx) ASN_EXPR, INIT_VAL, ComplexNDArray) - -#define MX_ND_ANY_ALL_REDUCTION(EVAL_EXPR, VAL) \ - MX_ND_REDUCTION (EVAL_EXPR, VAL, boolNDArray) - -#define MX_ND_CUMULATIVE_OP(RET_TYPE, ACC_TYPE, INIT_VAL, OP) \ - \ - RET_TYPE retval; \ - \ - dim_vector dv = this->dims (); \ - int nd = this->ndims (); \ - \ - bool empty = false; \ - \ - for (int i = 0; i < nd; i++) \ - { \ - if (dv(i) == 0) \ - { \ - empty = true; \ - break; \ - } \ - } \ - \ - /* We need to find first non-singleton dim. */ \ - \ - if (dim == -1) \ - { \ - dim = 0; \ - \ - for (int i = 0; i < nd; i++) \ - { \ - if (dv(i) != 1) \ - { \ - dim = i; \ - break; \ - } \ - } \ - } \ - else if (dim >= nd) \ - { \ - dim = nd++; \ - dv.resize (nd, 1); \ - } \ - \ - /* R = op (A, DIM) \ - \ - The strategy here is to access the elements of A along the \ - dimension specified by DIM. This means that we loop over each \ - element of R and adjust the index into A as needed. Store the \ - cummulative product of all dimensions of A in CP_SZ. The last \ - element of CP_SZ is the total number of elements of A. */ \ - \ - Array cp_sz (nd+1, 1); \ - for (int i = 1; i <= nd; i++) \ - cp_sz(i) = cp_sz(i-1)*dv(i-1); \ - \ - octave_idx_type reset_at = cp_sz(dim); \ - octave_idx_type base_incr = cp_sz(dim+1); \ - octave_idx_type incr = cp_sz(dim); \ - octave_idx_type base = 0; \ - octave_idx_type next_base = base + base_incr; \ - octave_idx_type iter_idx = base; \ - octave_idx_type n_elts = dv(dim); \ - \ - retval.resize (dv, INIT_VAL); \ - \ - if (! empty) \ - { \ - octave_idx_type nel = dv.numel () / n_elts; \ - \ - octave_idx_type k = 1; \ - \ - for (octave_idx_type i = 0; i < nel; i++) \ - { \ - OCTAVE_QUIT; \ - \ - ACC_TYPE prev_val = INIT_VAL; \ - \ - for (octave_idx_type j = 0; j < n_elts; j++) \ - { \ - OCTAVE_QUIT; \ - \ - if (j == 0) \ - { \ - retval(iter_idx) = elem (iter_idx); \ - prev_val = retval(iter_idx); \ - } \ - else \ - { \ - prev_val = prev_val OP elem (iter_idx); \ - retval(iter_idx) = prev_val; \ - } \ - \ - iter_idx += incr; \ - } \ - \ - if (k == reset_at) \ - { \ - base = next_base; \ - next_base += base_incr; \ - iter_idx = base; \ - k = 1; \ - } \ - else \ - { \ - base++; \ - iter_idx = base; \ - k++; \ - } \ - } \ - } \ - \ - retval.chop_trailing_singletons (); \ - \ - return retval - #endif /*