Mercurial > hg > octave-nkf
diff liboctave/array/dMatrix.cc @ 19511:3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
* liboctave/array/CMatrix.cc, liboctave/array/CMatrix.h,
liboctave/array/dMatrix.cc, liboctave/array/dMatrix.h,
liboctave/array/fCMatrix.cc, liboctave/array/fCMatrix.h,
liboctave/array/fMatrix.cc, liboctave/array/fMatrix.h: remove a lot of
duplicate code from Matrix type classes now that these classes inherit from
their NDArrays counterpart. These mostly include operator ! and =,
any_element_is_nan, any_element_is_inf_or_nan, all_elements_are_real,
all_integers, too_large_for_float, all, any, cumprod, cumsum, prod, sum,
sumsq, and abs. In some cases these need to still appear on the Matrix
definition to avoid slicing.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Fri, 07 Nov 2014 10:41:18 +0000 |
parents | d0c73e23a505 |
children | 385499581a5e |
line wrap: on
line diff
--- a/liboctave/array/dMatrix.cc +++ b/liboctave/array/dMatrix.cc @@ -2632,15 +2632,6 @@ // unary operations -boolMatrix -Matrix::operator ! (void) const -{ - if (any_element_is_nan ()) - gripe_nan_to_logical_conversion (); - - return do_mx_unary_op<bool, double> (*this, mx_inline_not); -} - // column vector by row vector -> matrix operations Matrix @@ -2670,131 +2661,54 @@ // other operations. -bool -Matrix::any_element_is_negative (bool neg_zero) const -{ - return (neg_zero ? test_all (xnegative_sign) - : do_mx_check<double> (*this, mx_inline_any_negative)); -} - -bool -Matrix::any_element_is_positive (bool neg_zero) const -{ - return (neg_zero ? test_all (xpositive_sign) - : do_mx_check<double> (*this, mx_inline_any_positive)); -} - -bool -Matrix::any_element_is_nan (void) const -{ - return do_mx_check<double> (*this, mx_inline_any_nan); -} - -bool -Matrix::any_element_is_inf_or_nan (void) const -{ - return ! do_mx_check<double> (*this, mx_inline_all_finite); -} - -bool -Matrix::any_element_not_one_or_zero (void) const -{ - return ! test_all (xis_one_or_zero); -} - -bool -Matrix::all_elements_are_int_or_inf_or_nan (void) const -{ - return test_all (xis_int_or_inf_or_nan); -} - -// Return nonzero if any element of M is not an integer. Also extract -// the largest and smallest values and return them in MAX_VAL and MIN_VAL. - -bool -Matrix::all_integers (double& max_val, double& min_val) const -{ - octave_idx_type nel = nelem (); - - if (nel > 0) - { - max_val = elem (0); - min_val = elem (0); - } - else - return false; - - for (octave_idx_type i = 0; i < nel; i++) - { - double val = elem (i); - - if (val > max_val) - max_val = val; - - if (val < min_val) - min_val = val; - - if (! xisinteger (val)) - return false; - } - - return true; -} - -bool -Matrix::too_large_for_float (void) const -{ - return test_any (xtoo_large_for_float); -} - // FIXME: Do these really belong here? Maybe they should be in a base class? boolMatrix Matrix::all (int dim) const { - return do_mx_red_op<bool, double> (*this, dim, mx_inline_all); + return NDArray::all (dim); } boolMatrix Matrix::any (int dim) const { - return do_mx_red_op<bool, double> (*this, dim, mx_inline_any); + return NDArray::any (dim); } Matrix Matrix::cumprod (int dim) const { - return do_mx_cum_op<double, double> (*this, dim, mx_inline_cumprod); + return NDArray::cumprod (dim); } Matrix Matrix::cumsum (int dim) const { - return do_mx_cum_op<double, double> (*this, dim, mx_inline_cumsum); + return NDArray::cumsum (dim); } Matrix Matrix::prod (int dim) const { - return do_mx_red_op<double, double> (*this, dim, mx_inline_prod); + return NDArray::prod (dim); } Matrix Matrix::sum (int dim) const { - return do_mx_red_op<double, double> (*this, dim, mx_inline_sum); + return NDArray::sum (dim); } Matrix Matrix::sumsq (int dim) const { - return do_mx_red_op<double, double> (*this, dim, mx_inline_sumsq); + return NDArray::sumsq (dim); } Matrix Matrix::abs (void) const { - return do_mx_unary_map<double, double, std::abs> (*this); + return NDArray::abs (); } Matrix