[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Iterating over a ND-array
From: |
David Bateman |
Subject: |
Re: Iterating over a ND-array |
Date: |
Fri, 27 May 2005 10:44:35 +0200 |
User-agent: |
Mozilla Thunderbird 0.8 (X11/20040923) |
Søren Hauberg wrote:
I just calculated the total number of elements and accessed them by
using a single index, like you suggested.
Thanks,
Søren
That's the best way to do it. You might also want to be careful whether
the variable is "const" or not since different versions of the ()
operator are used whether the variable is const or not... The operator
() can't tell if the variable is on the right or left hand side of an
equation and so if the variable is not const every time you call it, it
will check if a copy of the matrix is needed. This is why you often see
the fortran_vec function used in octave even when a fortran function
isn't called, as it allows this checking to be bypassed.
So in short
NDArray foo (const NDArry &m)
{
NDArray ret (m.dims ());
double *bar = ret.fortran_vec ();
for (int i =0; i < m.nelem (); i++)
bar [i] = foobar (m(i));
return ret;
}
is good practice...
D.
--
David Bateman address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------