Skip to content

Commit 4f0669e

Browse files
authored
Merge pull request #261 from libigl/alecjacobson/bump-nanobind
[WIP] bump nanobind to PR
2 parents 51439ef + 2cde10b commit 4f0669e

File tree

8 files changed

+156
-4
lines changed

8 files changed

+156
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ include(FetchContent)
3636
FetchContent_Declare(
3737
nanobind
3838
GIT_REPOSITORY https://github.com/wjakob/nanobind.git
39-
GIT_TAG v2.2.0
39+
GIT_TAG v2.7.0
4040
)
4141
FetchContent_MakeAvailable(nanobind)
4242

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ According to the [scikit-build-core documentation](https://scikit-build-core.rea
4545
2. Then use this very long command:
4646

4747
```
48-
python -m pip install --no-build-isolation --config-settings=editable.rebuild=true -Cbuild-dir=build -ve.
48+
CMAKE_BUILD_PARALLEL_LEVEL=10 python -m pip install --no-build-isolation --config-settings=editable.rebuild=true -Cbuild-dir=build -ve.
4949
```
5050

51+
The `CMAKE_BUILD_PARALLEL_LEVEL=10` will invoke with 10 parallel build threads.
52+
5153
### Adding a missing binding
5254

5355
Bindings are fairly mechanical to write. For example, suppose we didn't have a

src/copyleft/cgal/remesh_self_intersections.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ void bind_remesh_self_intersections(nb::module_ &m)
6161
- VV: remeshed vertex positions
6262
- FF: remeshed face indices
6363
- IF: intersecting face pairs
64-
- J: birth triangle indices)");
65-
64+
- J: birth triangle indices
65+
- IM if stitch_all = true #VV list from 0 to #VV-1
66+
elseif stitch_all = false #VV list of indices into VV of unique vertices.
67+
)");
6668
}
6769

src/sparse_map_noop.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "default_types.h"
2+
#include <nanobind/nanobind.h>
3+
#include <nanobind/eigen/sparse.h>
4+
#include <nanobind/ndarray.h>
5+
#include <nanobind/stl/tuple.h>
6+
7+
namespace nb = nanobind;
8+
using namespace nb::literals;
9+
10+
namespace pyigl
11+
{
12+
auto sparse_map_noop( const Eigen::Map<const Eigen::SparseMatrix<Integer>> &A)
13+
{
14+
return A;
15+
}
16+
}
17+
18+
// Bind the wrapper to the Python module
19+
void bind_sparse_map_noop(nb::module_ &m)
20+
{
21+
m.def(
22+
"sparse_map_noop",
23+
&pyigl::sparse_map_noop,
24+
"A"_a,
25+
R"("Returns input A)");
26+
}
27+

src/sparse_map_shape.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "default_types.h"
2+
#include <nanobind/nanobind.h>
3+
#include <nanobind/eigen/sparse.h>
4+
#include <nanobind/ndarray.h>
5+
#include <nanobind/stl/tuple.h>
6+
7+
namespace nb = nanobind;
8+
using namespace nb::literals;
9+
10+
namespace pyigl
11+
{
12+
auto sparse_map_shape( const Eigen::Map<const Eigen::SparseMatrix<Integer>> &A)
13+
{
14+
Eigen::Matrix<Integer,2,1> dims(A.rows(), A.cols());
15+
return dims;
16+
}
17+
}
18+
19+
// Bind the wrapper to the Python module
20+
void bind_sparse_map_shape(nb::module_ &m)
21+
{
22+
m.def(
23+
"sparse_map_shape",
24+
&pyigl::sparse_map_shape,
25+
"A"_a,
26+
R"("Returns shape of A as 2-vector)");
27+
}
28+
29+

src/sparse_noop.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "default_types.h"
2+
#include <nanobind/nanobind.h>
3+
#include <nanobind/eigen/sparse.h>
4+
#include <nanobind/ndarray.h>
5+
#include <nanobind/stl/tuple.h>
6+
7+
namespace nb = nanobind;
8+
using namespace nb::literals;
9+
10+
namespace pyigl
11+
{
12+
auto sparse_noop( const Eigen::SparseMatrix<Integer> &A)
13+
{
14+
return A;
15+
}
16+
}
17+
18+
// Bind the wrapper to the Python module
19+
void bind_sparse_noop(nb::module_ &m)
20+
{
21+
m.def(
22+
"sparse_noop",
23+
&pyigl::sparse_noop,
24+
"A"_a,
25+
R"("Returns input A)");
26+
}
27+

src/sparse_shape.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "default_types.h"
2+
#include <nanobind/nanobind.h>
3+
#include <nanobind/eigen/sparse.h>
4+
#include <nanobind/ndarray.h>
5+
#include <nanobind/stl/tuple.h>
6+
7+
namespace nb = nanobind;
8+
using namespace nb::literals;
9+
10+
namespace pyigl
11+
{
12+
auto sparse_shape( const Eigen::SparseMatrix<Integer> &A)
13+
{
14+
Eigen::Matrix<Integer,2,1> dims(A.rows(), A.cols());
15+
return dims;
16+
}
17+
}
18+
19+
// Bind the wrapper to the Python module
20+
void bind_sparse_shape(nb::module_ &m)
21+
{
22+
m.def(
23+
"sparse_shape",
24+
&pyigl::sparse_shape,
25+
"A"_a,
26+
R"("Returns shape of A as 2-vector)");
27+
}
28+
29+

test_sparse.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import igl
2+
import time
3+
4+
V, F = igl.icosahedron()
5+
V, F = igl.upsample(V, F)
6+
V, F = igl.upsample(V, F)
7+
V, F = igl.upsample(V, F)
8+
V, F = igl.upsample(V, F)
9+
V, F = igl.upsample(V, F)
10+
V, F = igl.upsample(V, F)
11+
12+
max_iters = 6
13+
for i in range(max_iters):
14+
A = igl.adjacency_matrix(F)
15+
n = A.shape[0]
16+
17+
start = time.time()
18+
dims = igl.sparse_shape(A)
19+
t_shape = time.time() - start
20+
21+
start = time.time()
22+
A2 = igl.sparse_noop(A)
23+
t_noop = time.time() - start
24+
25+
start = time.time()
26+
dims = igl.sparse_map_shape(A)
27+
t_map_shape = time.time() - start
28+
29+
start = time.time()
30+
A2 = igl.sparse_map_noop(A)
31+
t_map_noop = time.time() - start
32+
33+
print(f"{n} {t_shape:.6g} {t_noop:.6g} {t_map_shape:.6g} {t_map_noop:.6g}")
34+
35+
if i != max_iters-1:
36+
V, F = igl.upsample(V, F)

0 commit comments

Comments
 (0)