[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Array slicing in Octave
From: |
John W. Eaton |
Subject: |
Re: Array slicing in Octave |
Date: |
Sat, 14 May 2011 11:11:12 -0400 |
On 14-May-2011, Hamid 2C wrote:
| 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?
The rules are different for indexing and indexed assignment. If you
want to understand what happens with indexed assignment, set
breakpoints in the functions
Array<T>::assign (const idx_vector& i, const Array<T>& rhs, const T& rfv)
Array<T>::assign (const idx_vector& i, const idx_vector& j,
const Array<T>& rhs, const T& rfv)
Array<T>::assign (const Array<idx_vector>& ia,
const Array<T>& rhs, const T& rfv)
and step through them to see what they do. The first is a special
case for a single index, the second for two indices, and the third is
the general case of 3 or more indices.
jwe
- 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, 2011/05/14
- Re: Array slicing in Octave,
John W. Eaton <=
- 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