| | 72 | |
|---|
| | 73 | |
|---|
| | 74 | data = 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 | |
|---|
| | 94 | class 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 | |
|---|
| | 132 | if __name__ == '__main__': |
|---|
| | 133 | import nose |
|---|
| | 134 | nose.main() |
|---|