Mercurial > hg > octave-nkf
changeset 14590:6250e1232c9c stable
Implement proper op() indexing for diagonal matrices (bug #36368)
* DiagArray2.h (DiagArray2<T>::check_idx): New function.
(DiagArray2<T>::checkelem): Deleted. (DiagArray2<T>::operator()): New
non-const version, returns references. Conditionally call check_idx.
* DiagArray2.cc (DiagArray2<T>::check_idx): Contents copied over from
checkelem.
(DiagArray2<T>::checkelem): Deleted.
* ov-base-diag.cc (octave_base_diag<DMT, MT>::do_index_op): Replace
call to now-inaccessible checkelem() with elem().
* ov-cx-diag.cc: Add a test for this bug.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Wed, 02 May 2012 17:29:40 -0400 |
parents | 89504d0a5c5b |
children | f4acb362b513 ad1d7a53b1ca |
files | liboctave/DiagArray2.cc liboctave/DiagArray2.h src/ov-base-diag.cc src/ov-cx-diag.cc |
diffstat | 4 files changed, 21 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/DiagArray2.cc +++ b/liboctave/DiagArray2.cc @@ -82,16 +82,14 @@ // A two-dimensional array with diagonal elements only. -template <class T> -T -DiagArray2<T>::checkelem (octave_idx_type r, octave_idx_type c) const +template <typename T> +void +DiagArray2<T>::check_idx (octave_idx_type r, octave_idx_type c) const { if (r < 0 || r >= dim1 ()) gripe_index_out_of_range (2, 1, r+1, dim1 ()); if (c < 0 || c >= dim2 ()) gripe_index_out_of_range (2, 2, c+1, dim2 ()); - - return elem (r, c); } template <class T>
--- a/liboctave/DiagArray2.h +++ b/liboctave/DiagArray2.h @@ -119,15 +119,22 @@ T& dgelem (octave_idx_type i) { return Array<T>::elem (i); } - T checkelem (octave_idx_type r, octave_idx_type c) const; + void check_idx (octave_idx_type r, octave_idx_type c) const; T operator () (octave_idx_type r, octave_idx_type c) const { #if defined (BOUNDS_CHECKING) - return checkelem (r, c); -#else + check_idx (r, c); +#endif return elem (r, c); + } + + T& operator () (octave_idx_type r, octave_idx_type c) + { +#if defined (BOUNDS_CHECKING) + check_idx (r, c); #endif + return elem (r, c); } // No checking.