Code Search for Developers
 
 
  

memleak_transforms.py from matplotlib at Krugle


Show memleak_transforms.py syntax highlighted

import os, sys, time, gc

from matplotlib.numerix import array, asarray, alltrue
from matplotlib.numerix.mlab import rand
from matplotlib.transforms import Point, Bbox, Value, Affine
from matplotlib.transforms import multiply_affines
from matplotlib.transforms import Func, IDENTITY, LOG10, POLAR, FuncXY
from matplotlib.transforms import SeparableTransformation
from matplotlib.transforms import identity_transform, unit_bbox
from matplotlib.transforms import get_bbox_transform
from matplotlib.transforms import transform_bbox, inverse_transform_bbox
from matplotlib.transforms import bbox_all
from matplotlib.transforms import copy_bbox_transform, blend_xy_sep_transform


def report_memory(i):
    pid = os.getpid()
    if sys.platform=='sunos5':
        command = 'ps -p %d -o rss,osz' % pid
    else:
        'ps -p %d -o rss,sz' % pid
    a2 = os.popen(command).readlines()
    print i, '  ', a2[1],
    return int(a2[1].split()[1])



# make some random bbox transforms and test inversion
def rand_point():
    xy = rand(2)
    return Point( Value(xy[0]),  Value(xy[1]) )

def rand_bbox():
    ll = rand_point()
    ur = rand_point()
    return Bbox(ll, ur)

def rand_transform():
    b1 = rand_bbox()
    b2 = rand_bbox()
    return get_bbox_transform(b1, b2)



class Line:
    def __init__(self):
        self._transform = identity_transform()

    def set_transform(self, t):
        self._transform = t

x, y = rand(2,10000)
indStart, indEnd = 30, 350
for i in range(indEnd):
    for j in range(20):
        l = Line()
        t1 = rand_transform()
        t2 = rand_transform()
        trans = blend_xy_sep_transform( t1, t2)
        l.set_transform(trans)
        xt, yt = trans.numerix_x_y(x, y)
        xytup = tuple(rand(2))
        txytup = trans.xy_tup(xytup)
        ixytup = trans.inverse_xy_tup(xytup)
        seqt = trans.seq_xy_tups(zip(x,y))
    gc.collect()
    val = report_memory(i)
    if i==indStart: start = val # wait a few cycles for memory usage to stabilize


end = val
print 'Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart))





See more files for this project here

matplotlib

Matplotlib is a pure python plotting library with the goal of making\r\npublication quality plots using a syntax familiar to matlab users. \r\nThe library uses Numeric for handling large\r\ndata sets and supports a variety of output backends

Project homepage: http://sourceforge.net/projects/matplotlib
Programming language(s): C,C++,Python
License: other

  pathologies/
    const_xy.py
    shapes.py
    single_date.py
    single_point.py
    test.py
  __init__.py
  agg_memleak.py
  auto_legend.py
  dates_unit.py
  ft2font_memleak.py
  helpers.py
  inside_poly_memleak.py
  inside_poly_profile.py
  legend_unit.py
  longs_test.py
  memleak_gui.py
  memleak_hawaii3.py
  memleak_nongui.py
  memleak_transforms.py
  override_builtins.py
  simple_plot.py
  test_wxagg.py
  transform_memleak.py
  transforms_unit.py