octave-maintainers
[Top][All Lists]
Advanced

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

What is the expected behaviour of resize of NDArrays?


From: David Bateman
Subject: What is the expected behaviour of resize of NDArrays?
Date: Tue, 20 Apr 2004 15:43:32 +0200
User-agent: Mutt/1.4.1i

I have a problem that causes fft([1,2]',1) to crash for which a patch
is attached. However, while checking into this problem I identified a
strange difference in behaviour of resize_no_fill and resize_and_fill
in Array.cc. The code

dim_vector dv;
NDArray a;
...
a.resize (dv);

Causes the random data to be placed at the end of a considered as a 
single index if dv is larger than a.dims() is some dimension. Whilst,
if dv is smaller than a.dims() is some dimension then it cut from the
end. This means that a = [1, 3; 2, 4]; when resized to [1,2] becomes
[1, 2] !!!

This is different than the behaviour for a.resize(dv, fill_value), which
respects the dimensioning of the previous array. Thus, considering the
previous value of a and dv of [3,2] then the two different versions of 
resize give the results

a.resize(dv)         -> [1, 4; 3, 0; 2, 0]
a.resize(dv,0.0)     -> [1, 3; 2, 4; 0, 0]

However, when dv has fewer elements than in a.dims() then a.resize(dv,0.)
causes a seg-fault. Firstly, is the fact that these two versions of resize
don't have consistent behaviour a good idea? Secondly I need the behaviour
of resize_and_fill and I need the possibility than dv willl have fewer 
elements than in a.dims (). 

I propose the attached patch the address the second issue. But before 
proposing any patch for the first issue, it needs to be considered
carefully what would be the effect to changing the behaviour of
resize_no_fill. I have no ideas of all of the possible consequences
of changing resize_no_fill, so please comment...

Regards
David

-- 
David Bateman                                address@hidden
Motorola CRM                                 +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

Attachment: patch.resize
Description: Text document


reply via email to

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