Mercurial > hg > octave-avbm
changeset 9858:47c5af1868df
move idx_add methods to MArrayN
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 24 Nov 2009 12:30:26 +0100 |
parents | 43a7adf62534 |
children | 5919f2bd9a99 |
files | liboctave/ChangeLog liboctave/MArray.cc liboctave/MArray.h liboctave/MArrayN.cc liboctave/MArrayN.h src/ChangeLog src/data.cc |
diffstat | 7 files changed, 77 insertions(+), 75 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,9 @@ +2009-11-24 Jaroslav Hajek <highegg@gmail.com> + + * MArrayN.cc (MArrayN::idx_add): New methods. + * MArrayN.h: Declare them. + * MArray.cc, MArray.h: Remove from here. + 2009-11-19 Jaroslav Hajek <highegg@gmail.com> * dim-vector.h (dim_vector::safe_numel): New method.
--- a/liboctave/MArray.cc +++ b/liboctave/MArray.cc @@ -54,62 +54,6 @@ return 0; } -template <class T> -struct _idxadds_helper -{ - T *array; - T val; - _idxadds_helper (T *a, T v) : array (a), val (v) { } - void operator () (octave_idx_type i) - { array[i] += val; } -}; - -template <class T> -struct _idxadda_helper -{ - T *array; - const T *vals; - _idxadda_helper (T *a, const T *v) : array (a), vals (v) { } - void operator () (octave_idx_type i) - { array[i] += *vals++; } -}; - -template <class T> -void -MArray<T>::idx_add (const idx_vector& idx, T val) -{ - octave_idx_type n = this->length (); - octave_idx_type ext = idx.extent (n); - if (ext > n) - { - this->resize (ext); - n = ext; - } - - OCTAVE_QUIT; - - octave_idx_type len = idx.length (n); - idx.loop (len, _idxadds_helper<T> (this->fortran_vec (), val)); -} - -template <class T> -void -MArray<T>::idx_add (const idx_vector& idx, const MArray<T>& vals) -{ - octave_idx_type n = this->length (); - octave_idx_type ext = idx.extent (n); - if (ext > n) - { - this->resize (ext); - n = ext; - } - - OCTAVE_QUIT; - - octave_idx_type len = std::min (idx.length (n), vals.length ()); - idx.loop (len, _idxadda_helper<T> (this->fortran_vec (), vals.data ())); -} - // Element by element MArray by scalar ops. template <class T>
--- a/liboctave/MArray.h +++ b/liboctave/MArray.h @@ -104,12 +104,6 @@ map (U (&fcn) (const T&)) const { return Array<T>::template map<U> (fcn); } - // Performs indexed accumulative addition. - - void idx_add (const idx_vector& idx, T val); - - void idx_add (const idx_vector& idx, const MArray<T>& vals); - // Currently, the OPS functions don't need to be friends, but that // may change.
--- a/liboctave/MArrayN.cc +++ b/liboctave/MArrayN.cc @@ -31,6 +31,62 @@ #include "MArray-defs.h" #include "mx-inlines.cc" +template <class T> +struct _idxadds_helper +{ + T *array; + T val; + _idxadds_helper (T *a, T v) : array (a), val (v) { } + void operator () (octave_idx_type i) + { array[i] += val; } +}; + +template <class T> +struct _idxadda_helper +{ + T *array; + const T *vals; + _idxadda_helper (T *a, const T *v) : array (a), vals (v) { } + void operator () (octave_idx_type i) + { array[i] += *vals++; } +}; + +template <class T> +void +MArrayN<T>::idx_add (const idx_vector& idx, T val) +{ + octave_idx_type n = this->length (); + octave_idx_type ext = idx.extent (n); + if (ext > n) + { + this->resize (ext); + n = ext; + } + + OCTAVE_QUIT; + + octave_idx_type len = idx.length (n); + idx.loop (len, _idxadds_helper<T> (this->fortran_vec (), val)); +} + +template <class T> +void +MArrayN<T>::idx_add (const idx_vector& idx, const MArrayN<T>& vals) +{ + octave_idx_type n = this->length (); + octave_idx_type ext = idx.extent (n); + if (ext > n) + { + this->resize (ext); + n = ext; + } + + OCTAVE_QUIT; + + octave_idx_type len = std::min (idx.length (n), vals.length ()); + idx.loop (len, _idxadda_helper<T> (this->fortran_vec (), vals.data ())); +} + // N-dimensional array with math ops. template <class T> void
--- a/liboctave/MArrayN.h +++ b/liboctave/MArrayN.h @@ -104,6 +104,12 @@ return Array<T>::diag (k); } + // Performs indexed accumulative addition. + + void idx_add (const idx_vector& idx, T val); + + void idx_add (const idx_vector& idx, const MArrayN<T>& vals); + void changesign (void); };
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2009-11-24 Jaroslav Hajek <highegg@gmail.com> + + * data.cc (do_accumarray_sum): Simplify. + 2009-11-24 Jaroslav Hajek <highegg@gmail.com> * ov-struct.cc (octave_struct::save_binary): Save dimensions for
--- a/src/data.cc +++ b/src/data.cc @@ -6330,24 +6330,16 @@ else if (idx.extent (n) > n) error ("accumarray: index out of range"); - // FIXME: the class tree in liboctave is overly complicated, hence the - // following type gymnastics. - MArray<T> array; + NDT retval (dim_vector (n, 1), T()); if (vals.numel () == 1) - { - array = MArray<T> (n, T ()); - array.idx_add (idx, vals (0)); - } - else if (vals.length () == idx.length (n)) - { - array = MArray<T> (n, T ()); - array.idx_add (idx, MArray<T> (vals)); - } + retval.idx_add (idx, vals (0)); + else if (vals.numel () == idx.length (n)) + retval.idx_add (idx, vals); else error ("accumarray: dimensions mismatch"); - return NDT (MArrayN<T> (Array<T> (array))); + return retval; } DEFUN (__accumarray_sum__, args, ,