help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: switch from 1-based to 0-based indexing in NDArray::index ()


From: Jaroslav Hajek
Subject: Re: switch from 1-based to 0-based indexing in NDArray::index ()
Date: Wed, 24 Jun 2009 16:27:18 +0200

On Wed, Jun 24, 2009 at 4:07 PM, Carlo de Falco<address@hidden> wrote:
> Hi,
>
> Let pippo.cc contain the following code:
>
> -----------------------------------------------------------------
> #include <octave/oct.h>
> DEFUN_DLD(pippo, args, nargout," ")
> {
>  octave_value_list retval;
>  const NDArray coefs = args(0).array_value();
>  if (!error_state)
>    {
>      Array<idx_vector> idx2(3, idx_vector(':')); idx2(0) = 4;
>      NDArray w (coefs.index (idx2).squeeze ());
>      retval(0) = w;
>    }
>  return retval;
> }
> -----------------------------------------------------------------
>
> in version 3.0.5 I used to get:
>
> -----------------------------------------------------------------
> octave-3.0.5:4> mkoctfile pippo.cc
> octave-3.0.5:5> a = rand (4,3,3);
> octave-3.0.5:6> squeeze(a(4,:,:))
> ans =
>
>   3.7027e-01   8.2368e-02   3.2174e-01
>   4.7183e-01   2.3796e-01   2.1962e-01
>   2.2344e-01   6.8247e-05   7.6599e-01
>
> octave-3.0.5:7> pippo (a)
> ans =
>
>   3.7027e-01   8.2368e-02   3.2174e-01
>   4.7183e-01   2.3796e-01   2.1962e-01
>   2.2344e-01   6.8247e-05   7.6599e-01
>
> octave-3.0.5:8>
> -----------------------------------------------------------------
>
> while in 3.2.0 I get
>
> -----------------------------------------------------------------
> ctave-3.2.0:1> mkoctfile pippo.cc
> octave-3.2.0:2> a = rand (4,3,3);
> octave-3.2.0:3> squeeze(a(4,:,:))
> ans =
>
>   0.55451   0.70813   0.98778
>   0.88850   0.24332   0.80328
>   0.30309   0.40891   0.24563
>
> octave-3.2.0:4> pippo (a)
> error: A(I): Index exceeds matrix dimension.
> octave-3.2.0:4> a = rand (5,3,3);
> octave-3.2.0:5> squeeze(a(5,:,:))
> ans =
>
>   0.373801   0.406719   0.874288
>   0.523356   0.516201   0.096955
>   0.022904   0.643520   0.147175
>
> octave-3.2.0:6> pippo (a)
> ans =
>
>   0.373801   0.406719   0.874288
>   0.523356   0.516201   0.096955
>   0.022904   0.643520   0.147175
>
> octave-3.2.0:7>
> -----------------------------------------------------------------
>
> So should I assume there has been a switch from one-based to
> zero-based numbering in NDArray::index ?
> Was this change announced somwhere?
>
> Thanks,
> Carlo

There was a change in the idx_vector (octave_idx_type) constructor.
This was made to be consistent with the new idx_vector
(Array<octave_idx_type>) constructor, which needs to use zero-based
indexing. It wasn't announced anywhere, I think.

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]