Changeset 3017
- Timestamp:
- 02/03/12 22:29:15 (4 months ago)
- Files:
-
- 1 modified
-
trunk/brian/utils/dynamicarray.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/brian/utils/dynamicarray.py
r3011 r3017 28 28 The resizing factor (see notes below). Larger values tend to lead to 29 29 more wasted memory, but more computationally efficient code. 30 ``use_numpy_resize``, ``refcheck`` 31 Normally, when you resize the array it creates a new array and copies 32 the data. Sometimes, it is possible to resize an array without a copy, 33 and if this option is set it will attempt to do this. However, this can 34 cause memory problems if you are not careful so the option is off by 35 default. You need to ensure that you do not create slices of the array 36 so that no references to the memory exist other than the main array 37 object. If you are sure you know what you're doing, you can switch this 38 reference check off. Note that resizing in this way is only done if you 39 resize in the first dimension. 30 40 31 41 The array is initialised with zeros. The data is stored in the attribute … … 105 115 minnewshapearr[resizedimensions] = newdims 106 116 newshapearr = maximum(newshapearr, minnewshapearr) 107 if self.use_numpy_resize: 117 do_resize = False 118 if self.use_numpy_resize and self._data.flags['C_CONTIGUOUS']: 119 if sum(resizedimensions)==resizedimensions[0]: 120 do_resize = True 121 if do_resize: 108 122 self.data = None 109 123 self._data.resize(tuple(newshapearr), refcheck=self.refcheck) … … 160 174 if __name__=='__main__': 161 175 if 1: 176 x = DynamicArray((2, 2), use_numpy_resize=True) 177 x[0, 0] = 0 178 x[0, 1] = 1 179 x[1, 0] = 2 180 x[1, 1] = 3 181 print x 182 x.resize((3, 2)) 183 print x 184 if 0: 162 185 import time, gc 163 186 # speed comparison between numpy resize and not numpy resize
