Skip to content

Commit 4632f27

Browse files
jiangzhongshiTeseo Schneider
andauthored
fix continuous integration with numpy types (#154)
* Update README.md * deprecate np.float * deprecate np.int * updated deprecated package in setup * fixed types in tests * added default dtype Co-authored-by: Teseo Schneider <teseo@bluewin.ch>
1 parent 2466492 commit 4632f27

4 files changed

Lines changed: 42 additions & 38 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,3 @@ To run the tests:
4545
python setup.py test
4646
```
4747

48-

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
python -m pip install --upgrade pip
5252
pip install numpy
5353
pip install scipy
54+
pip install packaging
5455
displayName: 'Install dependencies'
5556
5657
- script: |

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import platform
55
import subprocess
66

7-
from distutils.version import LooseVersion
7+
from packaging.version import Version
88
from setuptools import setup, Extension, find_packages
99
from setuptools.command.build_ext import build_ext
1010

@@ -24,8 +24,8 @@ def run(self):
2424

2525
# self.debug = True
2626

27-
cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', out.decode()).group(1))
28-
if cmake_version < '3.2.0':
27+
cmake_version = Version(re.search(r'version\s*([\d.]+)', out.decode()).group(1))
28+
if cmake_version < Version('3.2.0'):
2929
raise RuntimeError("CMake >= 3.2.0 is required")
3030

3131
for ext in self.extensions:

tests/test_basic.py

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import igl
66
import numpy as np
77
import scipy as sp
8-
import scipy.sparse.csc as csc
8+
import scipy.sparse as csc
99
import math
1010

1111

@@ -32,6 +32,9 @@ def setUp(self):
3232
self.f = np.random.randint(0, 10, size=(20, 3), dtype=self.f1.dtype)
3333
self.g = np.random.randint(0, 10, size=(20, 4), dtype="int32")
3434

35+
self.default_int = np.array(range(2)).dtype
36+
self.default_float = np.zeros((2,2)).dtype
37+
3538
def tearDown(self):
3639
vv1, ff1 = igl.read_triangle_mesh(
3740
os.path.join(self.test_path, "bunny_small.off"))
@@ -140,8 +143,8 @@ def test_massmatrix(self):
140143
self.v, self.f, type=igl.MASSMATRIX_TYPE_BARYCENTRIC)
141144
self.assertTrue(a.shape == (self.v.shape[0], self.v.shape[0]))
142145
self.assertTrue(b.shape == (self.v.shape[0], self.v.shape[0]))
143-
self.assertTrue(b.dtype == np.float64)
144-
self.assertTrue(a.dtype == np.float64)
146+
self.assertTrue(b.dtype == self.v.dtype)
147+
self.assertTrue(a.dtype == self.v.dtype)
145148
self.assertTrue(type(a) == type(b) == csc.csc_matrix)
146149

147150
def test_massmatrix_intrinsic(self):
@@ -151,8 +154,8 @@ def test_massmatrix_intrinsic(self):
151154
el, self.f, type=igl.MASSMATRIX_TYPE_BARYCENTRIC)
152155
self.assertTrue(a.shape == (self.v.shape[0], self.v.shape[0]))
153156
self.assertTrue(b.shape == (self.v.shape[0], self.v.shape[0]))
154-
self.assertTrue(b.dtype == np.float64)
155-
self.assertTrue(a.dtype == np.float64)
157+
self.assertTrue(b.dtype == el.dtype)
158+
self.assertTrue(a.dtype == el.dtype)
156159
self.assertTrue(type(a) == type(b) == csc.csc_matrix)
157160

158161
def test_principal_curvature(self):
@@ -164,12 +167,12 @@ def test_principal_curvature(self):
164167
self.assertTrue(pv1.shape == qv1.shape == pv2.shape ==
165168
qv2.shape == (self.v.shape[0],))
166169
self.assertTrue(pd1.dtype == pd2.dtype ==
167-
pv1.dtype == pv2.dtype == np.float64)
170+
pv1.dtype == pv2.dtype == self.v.dtype)
168171
v = self.v.copy()
169172

170173
pd1, pd2, pv1, pv2 = igl.principal_curvature(v, self.f)
171174
self.assertTrue(pd1.dtype == pd2.dtype ==
172-
pv1.dtype == pv2.dtype == np.float64)
175+
pv1.dtype == pv2.dtype == v.dtype)
173176
self.assertTrue(type(pd1) == type(pd2) == type(pv1)
174177
== type(pv2) == np.ndarray)
175178
self.assertTrue(pd1.flags.c_contiguous)
@@ -186,7 +189,7 @@ def test_read_obj(self):
186189
self.assertTrue(type(v) == type(f) == type(n) == np.ndarray)
187190
self.assertTrue(v.shape == (25905, 3) and n.shape ==
188191
(0, 0) and f.shape == (51712, 3))
189-
self.assertTrue(v.dtype == np.float64)
192+
self.assertTrue(v.dtype == self.default_float)
190193
self.assertTrue(f.dtype == self.f.dtype)
191194
v, _, n, f, _, _ = igl.read_obj(
192195
self.test_path + "face.obj", dtype="float32")
@@ -202,7 +205,7 @@ def test_read_off(self):
202205
self.assertTrue(type(v) == type(f) == type(n) == np.ndarray)
203206
self.assertTrue(v.shape == (3485, 3) and n.shape ==
204207
(0, 0) and f.shape == (6966, 3))
205-
self.assertTrue(v.dtype == np.float64)
208+
self.assertTrue(v.dtype == self.default_float)
206209
v, f, n = igl.read_off(
207210
self.test_path + "bunny_small.off", read_normals=False, dtype="float32")
208211
self.assertTrue(v.shape == (3485, 3) and n.shape ==
@@ -220,7 +223,7 @@ def test_read_mesh(self):
220223
self.assertTrue(t.flags.c_contiguous)
221224
self.assertTrue(f.flags.c_contiguous)
222225

223-
self.assertTrue(v.dtype == np.float64)
226+
self.assertTrue(v.dtype == self.default_float)
224227
self.assertTrue(t.dtype == self.f1.dtype)
225228
self.assertTrue(f.dtype == self.f1.dtype)
226229

@@ -751,12 +754,12 @@ def test_marching_cubes(self):
751754
self.assertEqual(V.shape, (0, 3))
752755
self.assertEqual(F.shape, (0, 3))
753756

754-
#test marching over a sphere
755-
sphereField = np.linalg.norm(pts, axis=1) - 1
757+
#test marching over a sphere
758+
sphereField = np.linalg.norm(pts, axis=1) - 1
756759
V,F = igl.marching_cubes(sphereField, pts, n, n, n, 0.0)
757760

758761
self.assertTrue(V.dtype == pts.dtype)
759-
self.assertTrue(F.dtype == np.int)
762+
self.assertTrue(F.dtype == self.default_int)
760763

761764
self.assertNotEqual(V.shape, (0,3))
762765
self.assertNotEqual(F.shape, (0,3))
@@ -1233,7 +1236,7 @@ def test_signed_distance(self):
12331236
self.assertTrue(i.flags.c_contiguous)
12341237
self.assertTrue(c.flags.c_contiguous)
12351238

1236-
self.assertTrue(s.dtype == np.float64)
1239+
self.assertTrue(s.dtype == self.v1.dtype)
12371240
self.assertTrue(c.dtype == self.v1.dtype)
12381241
self.assertTrue(i.dtype == self.f1.dtype)
12391242

@@ -1242,7 +1245,7 @@ def test_signed_distance(self):
12421245
p, self.v1, self.f1, return_normals=True)
12431246
self.assertEqual(n.shape, p.shape)
12441247
self.assertTrue(n.flags.c_contiguous)
1245-
self.assertTrue(n.dtype == np.float64)
1248+
self.assertTrue(n.dtype == self.v1.dtype)
12461249

12471250
# ensure error raised when trying param other than pseudonormal for normals
12481251
with self.assertRaises(ValueError):
@@ -1717,15 +1720,16 @@ def test_edges_to_path(self):
17171720
self.assertTrue(k.dtype == e.dtype)
17181721

17191722
def test_path_to_edges(self):
1720-
e1 = igl.path_to_edges(np.array(range(20)), False)
1721-
e2 = igl.path_to_edges(np.array(range(20)), True)
1722-
r2 = np.vstack([np.array(range(20)), np.array(range(1, 21))]).T
1723+
v_indices = np.array(range(20))
1724+
e1 = igl.path_to_edges(v_indices, False)
1725+
e2 = igl.path_to_edges(v_indices, True)
1726+
r2 = np.vstack([v_indices, np.array(range(1, 21))]).T
17231727
r2[19, 1] = 0
17241728
self.assertTrue(np.allclose(e2, r2))
17251729
self.assertTrue(e1.flags.c_contiguous)
17261730
self.assertTrue(e2.flags.c_contiguous)
1727-
self.assertTrue(e1.dtype == np.int)
1728-
self.assertTrue(e2.dtype == np.int)
1731+
self.assertTrue(e1.dtype == v_indices.dtype)
1732+
self.assertTrue(e2.dtype == v_indices.dtype)
17291733

17301734
def test_exterior_edges(self):
17311735
e = igl.exterior_edges(self.f1)
@@ -2097,7 +2101,7 @@ def test_read_msh(self):
20972101
self.assertTrue(v.flags.c_contiguous)
20982102
self.assertTrue(t.flags.c_contiguous)
20992103

2100-
self.assertTrue(v.dtype == np.float64)
2104+
self.assertTrue(v.dtype == self.default_float)
21012105
self.assertTrue(t.dtype == self.f1.dtype)
21022106

21032107
def test_two_axis_valuator_fixed_up(self):
@@ -2287,20 +2291,20 @@ def test_quad_grid(self):
22872291
self.assertTrue(q.shape == (2*2, 4))
22882292
self.assertTrue(v.flags.c_contiguous)
22892293
self.assertTrue(q.flags.c_contiguous)
2290-
self.assertTrue(v.dtype == np.float)
2291-
self.assertTrue(q.dtype == np.int)
2292-
self.assertTrue(e.dtype == np.int)
2294+
self.assertTrue(v.dtype == self.default_float)
2295+
self.assertTrue(q.dtype == self.default_int)
2296+
self.assertTrue(e.dtype == self.default_int)
22932297

22942298
def test_sparse_voxel_grid(self):
22952299
def sphere1(point):
22962300
return np.sqrt(point[0]**2 + point[1]**2 + point[2]**2) - 1.0
22972301
point = np.array([1.0, 0.0, 0.0])
22982302
cs, cv, ci = igl.sparse_voxel_grid(point, sphere1, 1.0, 100)
22992303
self.assertTrue(cv.flags.c_contiguous)
2300-
self.assertTrue(cv.dtype == np.float)
2304+
self.assertTrue(cv.dtype == self.default_float)
23012305
self.assertTrue(cv.shape == (len(cs), 3))
23022306
self.assertTrue(ci.flags.c_contiguous)
2303-
self.assertTrue(ci.dtype == np.int)
2307+
self.assertTrue(ci.dtype == self.default_int)
23042308
self.assertTrue(ci.shape[1] == 8)
23052309

23062310
def test_topological_hole_fill(self):
@@ -2310,7 +2314,7 @@ def test_topological_hole_fill(self):
23102314
ff = igl.topological_hole_fill(f, b, h)
23112315
self.assertTrue(ff.flags.c_contiguous)
23122316
self.assertTrue(ff.shape[1] == 3)
2313-
self.assertTrue(ff.dtype == np.int)
2317+
self.assertTrue(ff.dtype == f.dtype)
23142318
self.assertTrue(ff.shape[0] != f.shape[0])
23152319

23162320
def test_triangulated_grid(self):
@@ -2319,8 +2323,8 @@ def test_triangulated_grid(self):
23192323
self.assertTrue(f.shape == (162, 3))
23202324
self.assertTrue(f.flags.c_contiguous)
23212325
self.assertTrue(v.flags.c_contiguous)
2322-
self.assertTrue(v.dtype == np.float)
2323-
self.assertTrue(f.dtype == np.int)
2326+
self.assertTrue(v.dtype == self.default_float)
2327+
self.assertTrue(f.dtype == self.default_int)
23242328

23252329
def test_unproject_on_line(self):
23262330
pos = np.array([10., 10.])
@@ -2332,7 +2336,7 @@ def test_unproject_on_line(self):
23322336

23332337
self.assertTrue(z.flags.c_contiguous)
23342338
self.assertTrue(z.shape == (3, ))
2335-
self.assertTrue(z.dtype == np.float)
2339+
self.assertTrue(z.dtype == pos.dtype)
23362340

23372341
def test_unproject_on_plane(self):
23382342
pos = np.array([10., 10.])
@@ -2343,7 +2347,7 @@ def test_unproject_on_plane(self):
23432347

23442348
self.assertTrue(z.flags.c_contiguous)
23452349
self.assertTrue(z.shape == (3, ))
2346-
self.assertTrue(z.dtype == np.float)
2350+
self.assertTrue(z.dtype == pos.dtype)
23472351

23482352
def test_fast_winding_number_for_points(self):
23492353
xs = np.linspace(-5.0, 5.0, 10)
@@ -2355,7 +2359,7 @@ def test_fast_winding_number_for_points(self):
23552359
wn = igl.fast_winding_number_for_points(self.v1, n, a, grid)
23562360
self.assertTrue(wn.flags.c_contiguous)
23572361
self.assertTrue(wn.shape == (grid.shape[0], ))
2358-
self.assertTrue(wn.dtype == np.float)
2362+
self.assertTrue(wn.dtype == self.v1.dtype)
23592363

23602364
def test_fast_winding_number_for_meshes(self):
23612365
xs = np.linspace(-5.0, 5.0, 10)
@@ -2365,7 +2369,7 @@ def test_fast_winding_number_for_meshes(self):
23652369
wn = igl.fast_winding_number_for_meshes(self.v1, self.f1, grid)
23662370
self.assertTrue(wn.flags.c_contiguous)
23672371
self.assertTrue(wn.shape == (grid.shape[0], ))
2368-
self.assertTrue(wn.dtype == np.float)
2372+
self.assertTrue(wn.dtype == self.v1.dtype)
23692373

23702374
def test_flip_avoiding_line_search(self):
23712375
def fun(v):
@@ -2387,7 +2391,7 @@ def test_edge_flaps(self):
23872391
self.assertTrue(ef.flags.c_contiguous)
23882392
self.assertTrue(ei.flags.c_contiguous)
23892393
self.assertTrue(e.dtype == emap.dtype ==
2390-
ef.dtype == ei.dtype == np.int)
2394+
ef.dtype == ei.dtype == self.f2.dtype)
23912395

23922396
def test_circulation(self):
23932397
pass

0 commit comments

Comments
 (0)