Mercurial > hg > octave-lojdl
changeset 9027:9a46ba093db4
generalize dim_vector::numel
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 26 Mar 2009 13:20:05 +0100 |
parents | 6890d411a0b8 |
children | e67dc11ed6e8 |
files | liboctave/ChangeLog liboctave/dim-vector.h |
diffstat | 2 files changed, 7 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2009-03-26 Jaroslav Hajek <highegg@gmail.com> + + * dim-vector.h (dim_vector::numel): Add optional argument, simplify. + 2009-03-26 Jaroslav Hajek <highegg@gmail.com> * Array.h (Array<T>::dims): Return a const reference.
--- a/liboctave/dim-vector.h +++ b/liboctave/dim-vector.h @@ -310,13 +310,13 @@ // vector would have, NOT the number of dimensions (elements in the // dimension vector). - octave_idx_type numel (void) const + octave_idx_type numel (int n = 0) const { int n_dims = length (); - octave_idx_type retval = n_dims > 0 ? elem (0) : 0; + octave_idx_type retval = 1; - for (int i = 1; i < n_dims; i++) + for (int i = n; i < n_dims; i++) retval *= elem (i); return retval;