From: <md...@us...> - 2007-11-27 17:40:47
|
Revision: 4469 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4469&view=rev Author: mdboom Date: 2007-11-27 09:40:45 -0800 (Tue, 27 Nov 2007) Log Message: ----------- Fix memory leak and increase performance in quadmesh drawing (Agg) Modified Paths: -------------- branches/transforms/lib/matplotlib/collections.py branches/transforms/src/_backend_agg.cpp Modified: branches/transforms/lib/matplotlib/collections.py =================================================================== --- branches/transforms/lib/matplotlib/collections.py 2007-11-27 17:34:20 UTC (rev 4468) +++ branches/transforms/lib/matplotlib/collections.py 2007-11-27 17:40:45 UTC (rev 4469) @@ -163,10 +163,8 @@ xs = self.convert_xunits(self._offsets[:0]) ys = self.convert_yunits(self._offsets[:1]) offsets = zip(xs, ys) - if len(offsets) == 0: - offsets = npy.array([], npy.float_) - else: - offsets = npy.asarray(offsets, npy.float_) + + offsets = npy.asarray(offsets, npy.float_) self.update_scalarmappable() @@ -389,10 +387,12 @@ self._bbox = transforms.Bbox.unit() self._bbox.update_from_data_xy(coordinates.reshape( ((meshWidth + 1) * (meshHeight + 1), 2))) + + # By converting to floats now, we can avoid that on every draw. + self._coordinates = self._coordinates.reshape((meshHeight + 1, meshWidth + 1, 2)) + self._coordinates = npy.array(self._coordinates, npy.float_) def get_paths(self, dataTrans=None): - import pdb - pdb.set_trace() if self._paths is None: self._paths = self.convert_mesh_to_paths( self._meshWidth, self._meshHeight, self._coordinates) @@ -402,7 +402,7 @@ def convert_mesh_to_paths(meshWidth, meshHeight, coordinates): Path = mpath.Path - c = coordinates.reshape((meshHeight + 1, meshWidth + 1, 2)) + c = coordinates # We could let the Path constructor generate the codes for us, # but this is faster, since we know they'll always be the same codes = npy.array( @@ -436,10 +436,7 @@ ys = self.convert_yunits(self._offsets[:1]) offsets = zip(xs, ys) - if len(offsets) == 0: - offsets = npy.array([], npy.float_) - else: - offsets = npy.asarray(offsets, npy.float_) + offsets = npy.asarray(offsets, npy.float_) if self.check_update('array'): self.update_scalarmappable() Modified: branches/transforms/src/_backend_agg.cpp =================================================================== --- branches/transforms/src/_backend_agg.cpp 2007-11-27 17:34:20 UTC (rev 4468) +++ branches/transforms/src/_backend_agg.cpp 2007-11-27 17:40:45 UTC (rev 4469) @@ -1113,8 +1113,9 @@ inline unsigned vertex(unsigned idx, double* x, double* y) { size_t m = m_m + offsets[idx][0]; size_t n = m_n + offsets[idx][1]; - *x = *(double*)PyArray_GETPTR3(m_coordinates, m, n, 0); - *y = *(double*)PyArray_GETPTR3(m_coordinates, m, n, 1); + double* pair = (double*)PyArray_GETPTR2(m_coordinates, m, n); + *x = *pair++; + *y = *pair; return (idx == 0) ? agg::path_cmd_move_to : agg::path_cmd_line_to; } @@ -1130,10 +1131,6 @@ inline unsigned total_vertices() { return 5; } - - inline bool has_curves() { - return false; - } }; public: @@ -1146,11 +1143,7 @@ throw Py::ValueError("Invalid coordinates array."); } - PyArray_Dims shape; - npy_intp dims[] = { meshHeight + 1, meshWidth + 1, 2 }; - shape.ptr = dims; - shape.len = 3; - m_coordinates = (PyArrayObject*)PyArray_Newshape(coordinates_array, &shape, PyArray_CORDER); + m_coordinates = coordinates_array; } inline ~QuadMeshGenerator() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |