Skip to content

Commit f2f597f

Browse files
committed
Use pybind11 for tri module
1 parent 8381ef9 commit f2f597f

6 files changed

Lines changed: 283 additions & 668 deletions

File tree

lib/matplotlib/tests/test_triangulation.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,43 +1167,43 @@ def test_internal_cpp_api():
11671167
# C++ Triangulation.
11681168
with pytest.raises(
11691169
TypeError,
1170-
match=r'function takes exactly 7 arguments \(0 given\)'):
1170+
match=r'__init__\(\): incompatible constructor arguments.'):
11711171
mpl._tri.Triangulation()
11721172

11731173
with pytest.raises(
11741174
ValueError, match=r'x and y must be 1D arrays of the same length'):
1175-
mpl._tri.Triangulation([], [1], [[]], None, None, None, False)
1175+
mpl._tri.Triangulation([], [1], [[]], (), (), (), False)
11761176

11771177
x = [0, 1, 1]
11781178
y = [0, 0, 1]
11791179
with pytest.raises(
11801180
ValueError,
11811181
match=r'triangles must be a 2D array of shape \(\?,3\)'):
1182-
mpl._tri.Triangulation(x, y, [[0, 1]], None, None, None, False)
1182+
mpl._tri.Triangulation(x, y, [[0, 1]], (), (), (), False)
11831183

11841184
tris = [[0, 1, 2]]
11851185
with pytest.raises(
11861186
ValueError,
11871187
match=r'mask must be a 1D array with the same length as the '
11881188
r'triangles array'):
1189-
mpl._tri.Triangulation(x, y, tris, [0, 1], None, None, False)
1189+
mpl._tri.Triangulation(x, y, tris, [0, 1], (), (), False)
11901190

11911191
with pytest.raises(
11921192
ValueError, match=r'edges must be a 2D array with shape \(\?,2\)'):
1193-
mpl._tri.Triangulation(x, y, tris, None, [[1]], None, False)
1193+
mpl._tri.Triangulation(x, y, tris, (), [[1]], (), False)
11941194

11951195
with pytest.raises(
11961196
ValueError,
11971197
match=r'neighbors must be a 2D array with the same shape as the '
11981198
r'triangles array'):
1199-
mpl._tri.Triangulation(x, y, tris, None, None, [[-1]], False)
1199+
mpl._tri.Triangulation(x, y, tris, (), (), [[-1]], False)
12001200

1201-
triang = mpl._tri.Triangulation(x, y, tris, None, None, None, False)
1201+
triang = mpl._tri.Triangulation(x, y, tris, (), (), (), False)
12021202

12031203
with pytest.raises(
12041204
ValueError,
1205-
match=r'z array must have same length as triangulation x and y '
1206-
r'array'):
1205+
match=r'z must be a 1D array with the same length as the '
1206+
r'triangulation x and y arrays'):
12071207
triang.calculate_plane_coefficients([])
12081208

12091209
with pytest.raises(
@@ -1215,7 +1215,7 @@ def test_internal_cpp_api():
12151215
# C++ TriContourGenerator.
12161216
with pytest.raises(
12171217
TypeError,
1218-
match=r'function takes exactly 2 arguments \(0 given\)'):
1218+
match=r'__init__\(\): incompatible constructor arguments.'):
12191219
mpl._tri.TriContourGenerator()
12201220

12211221
with pytest.raises(
@@ -1233,7 +1233,8 @@ def test_internal_cpp_api():
12331233

12341234
# C++ TrapezoidMapTriFinder.
12351235
with pytest.raises(
1236-
TypeError, match=r'function takes exactly 1 argument \(0 given\)'):
1236+
TypeError,
1237+
match=r'__init__\(\): incompatible constructor arguments.'):
12371238
mpl._tri.TrapezoidMapTriFinder()
12381239

12391240
trifinder = mpl._tri.TrapezoidMapTriFinder(triang)

lib/matplotlib/tri/triangulation.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,12 @@ def get_cpp_triangulation(self):
120120
from matplotlib import _tri
121121
if self._cpp_triangulation is None:
122122
self._cpp_triangulation = _tri.Triangulation(
123-
self.x, self.y, self.triangles, self.mask, self._edges,
124-
self._neighbors, not self.is_delaunay)
123+
# For unset arrays use empty tuple which has size of zero.
124+
self.x, self.y, self.triangles,
125+
self.mask if self.mask is not None else (),
126+
self._edges if self._edges is not None else (),
127+
self._neighbors if self._neighbors is not None else (),
128+
not self.is_delaunay)
125129
return self._cpp_triangulation
126130

127131
def get_masked_triangles(self):

setupext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,12 @@ def get_extensions(self):
453453
add_libagg_flags(ext)
454454
yield ext
455455
# tri
456-
ext = Extension(
456+
ext = Pybind11Extension(
457457
"matplotlib._tri", [
458458
"src/tri/_tri.cpp",
459459
"src/tri/_tri_wrapper.cpp",
460-
])
461-
add_numpy_flags(ext)
460+
],
461+
cxx_std=11)
462462
yield ext
463463
# ttconv
464464
ext = Extension(

0 commit comments

Comments
 (0)