[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Array slicing in Octave
From: |
Hamid 2C |
Subject: |
Re: Array slicing in Octave |
Date: |
Sat, 14 May 2011 17:40:51 +0430 |
Hi,
I followed your suggestion to run octave in gdb. I put breakpoints at
every index function in Array.cc(703, 767, 822, ...). However, these
breakpoints are only triggered before the prompt of the octave
interpreter appears on the screen, after that, slice operations that
is performed by the interpreter does not trigger any breakpoint. Why
is that? Doesn't the interpreter call functions you mentioned? Am I
missing something?
I got the whole idea of slicing to some extent. If I got it correctly,
those index functions make a shallow copy of the array if the slice
refers to a contiguous block of memory and copy the elements to a new
array otherwise. Is it right?
I am interested in knowing what does happen when someone tries to
modify parts of an array through slicing. For example, consider the
following example:
octave:13> b=reshape(1:10, 2, 5)
b =
1 3 5 7 9
2 4 6 8 10
octave:14> b(:, 1:2:5) = [-1 -2 -3; -4 -5 -6]
b =
-1 3 -2 7 -3
-4 4 -5 8 -6
where the original array (b) is changed through the slicing.
Is the slice copied back to the original array?
A for loop is generated that does the job?
Thanks,
Hamid
2011/5/11 Jordi Gutiérrez Hermoso <address@hidden>:
> On 6 May 2011 03:20, Hamid 2C <address@hidden> wrote:
>> I would like to know how array slicing is implemented in Octave.
>> Any comment/suggestion on the direction where I should look at would
>> be really appreciated.
>
> The answer isn't simple. The general type in liboctave/ is idx_vector
> that is actually a polymorphic type for representing single indices,
> range slices, and full colons. So for example for the base Array class
> in liboctave/Array.h, the index(...) family of functions are in charge
> of this work. You can see the definition for them near
> liboctave/Array.cc:703 and near liboctave/Array.cc:1037 (hg changeset
> 6b2f14af2360).
>
> Note that sparse matrices must naturally have their own indexing and
> slicing rules, so its own index(...) functions are implemented near
> liboctave/Sparse.cc:1340.
>
> That should be enough to get you started. I think the best way to
> really learn this is to run Octave in a debugger and put breakpoints
> inside the functions I hinted to above; that way you can really see
> what's going on.
>
> HTH,
> - Jordi G. H.
>
- Array slicing in Octave, Hamid 2C, 2011/05/06
- Re: Array slicing in Octave, David Bruce, 2011/05/10
- Re: Array slicing in Octave, Jordi Gutiérrez Hermoso, 2011/05/11
- Re: Array slicing in Octave, Hamid 2C, 2011/05/12
- Re: Array slicing in Octave,
Hamid 2C <=
- Re: Array slicing in Octave, John W. Eaton, 2011/05/14
- Re: Array slicing in Octave, Hamid 2C, 2011/05/15
- Re: Array slicing in Octave, Jordi Gutiérrez Hermoso, 2011/05/15
- Message not available
- Array slicing in Octave, Hamid 2C, 2011/05/16
- Re: Array slicing in Octave, Jordi Gutiérrez Hermoso, 2011/05/16
- Re: Array slicing in Octave, Hamid 2C, 2011/05/16