Changeset 745 for trunk/delaunay

Show
Ignore:
Timestamp:
01/17/08 12:21:48 (10 months ago)
Author:
rkern
Message:

* BUG: fix a leak.
* Add some tests for the duplicate point handling contributed by "pv".

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/delaunay/scikits/delaunay/_delaunay.cpp

    r547 r745  
    127127    vdg.getNumbers(length, numtri); 
    128128 
     129    // Count the actual number of edges 
     130    i = 0; 
     131    vdg.resetEdgeListIter(); 
     132    while (vdg.getNextDelaunay(tri0, tri0x, tri0y, tri1, tri1x, tri1y, reg0, reg1)) 
     133        i++; 
     134    length = i; 
     135 
    129136    dim[0] = length; 
    130137    dim[1] = 2; 
     
    448455{ 
    449456    PyObject *pyx, *pyy, *pyz, *pycenters, *pynodes, *pyneighbors, *pyintx, *pyinty; 
    450     PyObject *x, *y, *z, *centers, *nodes, *neighbors, *intx, *inty, *intz; 
     457    PyObject *x = NULL, *y = NULL, *z = NULL, *centers = NULL, *nodes = NULL, 
     458        *neighbors = NULL, *intx = NULL, *inty = NULL, *intz; 
    451459    double defvalue; 
    452460    int size, npoints, ntriangles; 
     
    544552        (double*)PyArray_DATA(intz), defvalue); 
    545553 
    546     CLEANUP 
     554    Py_XDECREF(x); 
     555    Py_XDECREF(y); 
     556    Py_XDECREF(z); 
     557    Py_XDECREF(intx); 
     558    Py_XDECREF(inty); 
     559    Py_XDECREF(centers); 
     560    Py_XDECREF(nodes); 
     561    Py_XDECREF(neighbors); 
    547562    return intz; 
    548563} 
  • trunk/delaunay/tests/test_triangulate.py

    r744 r745  
    1 from scikits import delaunay as dlny 
     1import sys 
     2 
    23from numpy import random 
    34import numpy as np 
     5 
     6from scikits import delaunay as dlny 
    47 
    58def onright(x0, y0, x1, y1, x, y): 
     
    6770            good = (r2 <= (alldist2 + 1e-12)) 
    6871            assert np.alltrue(good) 
     72 
     73 
     74data = np.array([ 
     75    [-3.14, -3.14], [-3.14, -2.36], [-3.14, -1.57], [-3.14, -0.79], [-3.14, 0.0], 
     76    [-3.14, 0.79], [-3.14, 1.57], [-3.14, 2.36], [-3.14, 3.14], [-2.36, -3.14], 
     77    [-2.36, -2.36], [-2.36, -1.57], [-2.36, -0.79], [-2.36, 0.0], [-2.36, 0.79], 
     78    [-2.36, 1.57], [-2.36, 2.36], [-2.36, 3.14], [-1.57, -0.79], [-1.57, 0.79], 
     79    [-1.57, -1.57], [-1.57, 0.0], [-1.57, 1.57], [-1.57, -3.14], [-1.57, -2.36], 
     80    [-1.57, 2.36], [-1.57, 3.14], [-0.79, -1.57], [-0.79, 1.57], [-0.79, -3.14], 
     81    [-0.79, -2.36], [-0.79, -0.79], [-0.79, 0.0], [-0.79, 0.79], [-0.79, 2.36], 
     82    [-0.79, 3.14], [0.0, -3.14], [0.0, -2.36], [0.0, -1.57], [0.0, -0.79],  
     83    [0.0, 0.0], [0.0, 0.79], [0.0, 1.57], [0.0, 2.36], [0.0, 3.14],  
     84    [0.79, -3.14], [0.79, -2.36], [0.79, -0.79], [0.79, 0.0], [0.79, 0.79], 
     85    [0.79, 2.36], [0.79, 3.14], [0.79, -1.57], [0.79, 1.57], [1.57, -3.14], 
     86    [1.57, -2.36], [1.57, 2.36], [1.57, 3.14], [1.57, -1.57], [1.57, 0.0], 
     87    [1.57, 1.57], [1.57, -0.79], [1.57, 0.79], [2.36, -3.14], [2.36, -2.36], 
     88    [2.36, -1.57], [2.36, -0.79], [2.36, 0.0], [2.36, 0.79], [2.36, 1.57], 
     89    [2.36, 2.36], [2.36, 3.14], [3.14, -3.14], [3.14, -2.36], [3.14, -1.57], 
     90    [3.14, -0.79], [3.14, 0.0], [3.14, 0.79], [3.14, 1.57], [3.14, 2.36],  
     91    [3.14, 3.14], 
     92]) 
     93 
     94class TestRegression(object): 
     95 
     96    def test_ticket_376(self): 
     97        x  = np.array([0, 1, 0, 1], dtype=np.float64) 
     98        y  = np.array([0, 0, 1, 1], dtype=np.float64) 
     99        z  = np.array([1, 2, 3, 4], dtype=np.float64) 
     100 
     101        tri1 = dlny.Triangulation(x, y) 
     102        nn1 = tri1.nn_interpolator(z) 
     103 
     104        xp = np.r_[x, x] 
     105        yp = np.r_[y, y] 
     106        zp = np.r_[z, z] 
     107 
     108        # shouldn't fail on duplicate points 
     109        tri2 = dlny.Triangulation(xp, yp) 
     110        nn2 = tri2.nn_interpolator(zp) 
     111 
     112        assert nn1(0.3, 0.5) == nn2(0.3, 0.5) 
     113 
     114    def test_ticket_376_2(self): 
     115        tri = dlny.Triangulation(data[:,0], data[:,1]) 
     116        # should pass 
     117 
     118    def test_ticket_382(self): 
     119        x, y = np.meshgrid(np.linspace(0,1,4), np.linspace(0,1,3)) 
     120 
     121        tri = dlny.Triangulation(x.flatten(), y.flatten()) 
     122        refcount1 = sys.getrefcount(tri.x) 
     123        interp = tri.nn_interpolator(x.flatten()) 
     124        refcount2 = sys.getrefcount(tri.x) 
     125        interp(x.flatten(), y.flatten()) 
     126        refcount3 = sys.getrefcount(tri.x) 
     127 
     128        # shouldn't leak references 
     129        assert refcount1 == refcount2 
     130        assert refcount1 == refcount3 
     131 
     132if __name__ == '__main__': 
     133    import nose 
     134    nose.main()