Mercurial > hg > octave-nkf
diff liboctave/Sparse.h @ 15212:4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
* lo-utils.h (any_all_test): New function.
* lo-utils.h, lo-utils.cc (xtoo_large_for_float (const Complex&)):
New function.
* Array.h (Array<T>::test): Call any_all_test.
* Sparse.h (Sparse<T>::test, Sparse<T>::test_any, Sparse<T>::test_all,
Sparse<T>::test_any, Sparse<T>::test_any, Sparse<T>::test_all,
Sparse<T>::test_all): New functions.
* CMatrix.cc (ComplexMatrix::too_large_for_float): Simplify with
test_any and xtoo_large_for_float.
* CNDArray.cc (ComplexNDArray::too_large_for_float): Likewise.
* CSparse.cc (SparseComplexMatrix::too_large_for_float): Likewise.
* dSparse.cc (SparseMatrix::too_large_for_float): Likewise.
* dMatrix.cc (Matrix::too_large_for_float): Use test_any, not test_all.
* dNDArray.cc (NDArray::too_large_for_float): Likewise.
* fCMatrix.cc (FloatComplexMatrix::too_large_for_float):
Unconditionlly return false.
* fCNDArray.cc (FloatComplexNDArray::too_large_for_float): Likewise.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 22 Aug 2012 16:16:31 -0400 |
parents | 560317fd5977 |
children |
line wrap: on
line diff
--- a/liboctave/Sparse.h +++ b/liboctave/Sparse.h @@ -584,6 +584,35 @@ Array<T> array_value (void) const; + // Generic any/all test functionality with arbitrary predicate. + template <class F, bool zero> + bool test (F fcn) const + { + return any_all_test<F, T, zero> (fcn, data (), nnz ()); + } + + // Simpler calls. + template <class F> + bool test_any (F fcn) const + { return test<F, false> (fcn); } + + template <class F> + bool test_all (F fcn) const + { return test<F, true> (fcn); } + + // Overloads for function references. + bool test_any (bool (&fcn) (T)) const + { return test<bool (&) (T), false> (fcn); } + + bool test_any (bool (&fcn) (const T&)) const + { return test<bool (&) (const T&), false> (fcn); } + + bool test_all (bool (&fcn) (T)) const + { return test<bool (&) (T), true> (fcn); } + + bool test_all (bool (&fcn) (const T&)) const + { return test<bool (&) (const T&), true> (fcn); } + template <class U, class F> Sparse<U> map (F fcn) const