8000 applied Erics contour memleak fixes · matplotlib/matplotlib@77a9d55 · GitHub
[go: up one dir, main page]

Skip to content

Commit 77a9d55

Browse files
committed
applied Erics contour memleak fixes
svn path=/trunk/matplotlib/; revision=1295
1 parent 3e9d6ee commit 77a9d55

File tree

7 files changed

+1724
-1494
lines changed

7 files changed

+1724
-1494
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
New entries should be added at the top
22

3+
2005-05-10 Applied Eric's contour mem leak fixes - JDH
4+
35
2005-05-10 Extended python agg wrapper and started implementing backend_agg2,
46
an agg renderer based on the python wrapper. This will be
57
more flexible and easier to extend than the current

lib/matplotlib/_contour.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
if numerix.which[0] == "numarray":
44
try:
5-
from matplotlib._na_contour import *
5+
from matplotlib._na_cntr import *
66
except ImportError:
77
numerix._import_fail_message("_contour", "_na")
88
raise
99
else:
1010
try:
11-
from matplotlib._nc_contour import *
11+
from matplotlib._nc_cntr import *
1212
except ImportError:
1313
numerix._import_fail_message("_contour", "_nc")
1414
raise

lib/matplotlib/contour.py

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -553,45 +553,6 @@ def _contour_args(self, filled, origin, extent, *args):
553553
self.ax.set_ylim((ma.minimum(y), ma.maximum(y)))
554554
return (x, y, z, lev)
555555

556-
557-
def _initialize_reg_tri(self, z):
558-
'''
559-
Initialize two arrays used by the low-level contour
560-
algorithm. This is temporary code; most of the reg
561-
initialization should be done in c.
562-
563-
For each masked point, we need to mark as missing
564-
the four regions with that point as a corner.
565-
'''
566-
imax, jmax = shape(z)
567-
nreg = jmax*(imax+1)+1
568-
reg = ones((1, nreg), typecode = 'i')
569-
reg[0,:jmax+1]=0
570-
reg[0,-jmax:]=0
571-
for j in range(0, nreg, jmax):
572-
reg[0,j]=0
573-
badmask = z.mask()
574-
if badmask is not None:
575-
for i in range(imax):
576-
for j in range(jmax):
577-
if badmask[i,j]:
578-
ii = i*jmax+j
579-
if ii < nreg:
580-
reg[0,ii] = 0
581-
ii += 1
582-
if ii < nreg:
583-
reg[0,ii] = 0
584-
ii += jmax
585-
if ii < nreg:
586-
reg[0,ii] = 0
587-
ii -= 1
588-
if ii < nreg:
589-
reg[0,ii] = 0
590-
591-
triangle = zeros((imax,jmax), typecode='s')
592-
593-
return reg, triangle
594-
595556
def _process_colors(self, z, colors, alpha, lev, cmap):
596557
"""
597558
Color argument processing for contouring.
@@ -728,8 +689,6 @@ def contour(self, *args, **kwargs):
728689
Ncolors = Nlev
729690

730691

731-
reg, triangle = self._initialize_reg_tri(z)
732-
733692
tcolors, mappable, collections = self._process_colors(
734693
z, colors, alpha, lev, cmap)
735694

@@ -743,13 +702,9 @@ def contour(self, *args, **kwargs):
743702
tlinewidths = [(w,) for w in linewidths]
744703

745704
region = 0
705+
C = _contour.Cntr(x, y, z.filled(), z.mask())
746706
for level, color, width in zip(lev, tcolors, tlinewidths):
747-
ntotal, nparts = _contour.GcInit1(x, y, reg, triangle,
748-
region, z.filled(), level)
749-
np = zeros((nparts,), typecode='l')
750-
xp = zeros((ntotal, ), Float64)
751-
yp = zeros((ntotal,), Float64)
752-
nlist = _contour.GcTrace(np, xp, yp)
707+
nlist = C.trace(level, points = 1)
753708
col = LineCollection(nlist)
754709
col.set_color(color)
755710
col.set_linewidth(width)
@@ -852,24 +807,16 @@ def contourf(self, *args, **kwargs):
852807

853808
Nlev = len(lev)
854809

855-
856-
reg, triangle = self._initialize_reg_tri(z)
857-
858810
tcolors, mappable, collections = self._process_colors(z, colors,
859811
alpha,
860812
lev, cmap)
861813

862814
region = 0
863815
lev_upper = list(lev[1:])
864816
lev_upper.append(1e38)
817+
C = _contour.Cntr(x, y, z.filled(), z.mask())
865818
for level, level_upper, color in zip(lev, lev_upper, tcolors):
866-
levs = (level, level_upper)
867-
ntotal, nparts = _contour.GcInit2(x, y, reg, triangle,
868-
region, z.filled(), levs, 30)
869-
np = zeros((nparts,), typecode='l')
870-
xp = zeros((ntotal, ), Float64)
871-
yp = zeros((ntotal,), Float64)
872-
nlist = _contour.GcTrace(np, xp, yp)
819+
nlist = C.trace(level, level_upper, points = 1)
873820
col = PolyCollection(nlist,
874821
linewidths=(1,))
875822
# linewidths = 1 is necessary to avoid artifacts

setupext.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -554,26 +554,22 @@ def build_contour(ext_modules, packages, numerix):
554554
if BUILT_CONTOUR: return # only build it if you you haven't already
555555

556556
if numerix in ["numarray","both"]: # Build for numarray
557-
temp_copy('src/_contour.c', 'src/_na_contour.c')
558-
#deps = ['src/_na_contour.c', 'src/gcntr.c', libraries = ['stdc++']]
557+
temp_copy('src/cntr.c', 'src/_na_cntr.c')
559558
module = Extension(
560-
'matplotlib._na_contour',
561-
[ 'src/_na_contour.c',
562-
'src/gcntr.c'],
563-
libraries = ['stdc++'],
564-
)
559+
'matplotlib._na_cntr',
560+
[ 'src/_na_cntr.c',],
561+
#libraries = ['stdc++'],
562+
)
565563
module.extra_compile_args.append('-DNUMARRAY=1')
566564
add_base_flags(module)
567565
ext_modules.append(module)
568566

569567
86D9 if numerix in ["Numeric","both"]: # Build for Numeric
570-
temp_copy('src/_contour.c', 'src/_nc_contour.c')
571-
#deps = ['src/_nc_contour.c', 'src/gcntr.c']
568+
temp_copy('src/cntr.c', 'src/_nc_cntr.c')
572569
module = Extension(
573-
'matplotlib._nc_contour',
574-
[ 'src/_nc_contour.c',
575-
'src/gcntr.c'],
576-
libraries = ['stdc++'],
570+
'matplotlib._nc_cntr',
571+
[ 'src/_nc_cntr.c'],
572+
#libraries = ['stdc++'],
577573
)
578574
module.extra_compile_args.append('-DNUMERIC=1')
579575
add_base_flags(module)

0 commit comments

Comments
 (0)
0