[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
switch from 1-based to 0-based indexing in NDArray::index ()
From: |
Carlo de Falco |
Subject: |
switch from 1-based to 0-based indexing in NDArray::index () |
Date: |
Wed, 24 Jun 2009 16:07:35 +0200 |
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
- switch from 1-based to 0-based indexing in NDArray::index (),
Carlo de Falco <=