Skip to content

[WIP] bump nanobind to PR #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ include(FetchContent)
FetchContent_Declare(
nanobind
GIT_REPOSITORY https://github.com/wjakob/nanobind.git
GIT_TAG v2.2.0
GIT_TAG d698692936bae1c4963e5c42f41fd88e9095b1c0
)
FetchContent_MakeAvailable(nanobind)

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ According to the [scikit-build-core documentation](https://scikit-build-core.rea
2. Then use this very long command:

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

The `CMAKE_BUILD_PARALLEL_LEVEL=10` will invoke with 10 parallel build threads.

### Adding a missing binding

Bindings are fairly mechanical to write. For example, suppose we didn't have a
Expand Down
27 changes: 27 additions & 0 deletions src/sparse_map_noop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "default_types.h"
#include <nanobind/nanobind.h>
#include <nanobind/eigen/sparse.h>
#include <nanobind/ndarray.h>
#include <nanobind/stl/tuple.h>

namespace nb = nanobind;
using namespace nb::literals;

namespace pyigl
{
auto sparse_map_noop( const Eigen::Map<const Eigen::SparseMatrix<Integer>> &A)
{
return A;
}
}

// Bind the wrapper to the Python module
void bind_sparse_map_noop(nb::module_ &m)
{
m.def(
"sparse_map_noop",
&pyigl::sparse_map_noop,
"A"_a,
R"("Returns input A)");
}

29 changes: 29 additions & 0 deletions src/sparse_map_shape.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "default_types.h"
#include <nanobind/nanobind.h>
#include <nanobind/eigen/sparse.h>
#include <nanobind/ndarray.h>
#include <nanobind/stl/tuple.h>

namespace nb = nanobind;
using namespace nb::literals;

namespace pyigl
{
auto sparse_map_shape( const Eigen::Map<const Eigen::SparseMatrix<Integer>> &A)
{
Eigen::Matrix<Integer,2,1> dims(A.rows(), A.cols());
return dims;
}
}

// Bind the wrapper to the Python module
void bind_sparse_map_shape(nb::module_ &m)
{
m.def(
"sparse_map_shape",
&pyigl::sparse_map_shape,
"A"_a,
R"("Returns shape of A as 2-vector)");
}


27 changes: 27 additions & 0 deletions src/sparse_noop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "default_types.h"
#include <nanobind/nanobind.h>
#include <nanobind/eigen/sparse.h>
#include <nanobind/ndarray.h>
#include <nanobind/stl/tuple.h>

namespace nb = nanobind;
using namespace nb::literals;

namespace pyigl
{
auto sparse_noop( const Eigen::SparseMatrix<Integer> &A)
{
return A;
}
}

// Bind the wrapper to the Python module
void bind_sparse_noop(nb::module_ &m)
{
m.def(
"sparse_noop",
&pyigl::sparse_noop,
"A"_a,
R"("Returns input A)");
}

29 changes: 29 additions & 0 deletions src/sparse_shape.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "default_types.h"
#include <nanobind/nanobind.h>
#include <nanobind/eigen/sparse.h>
#include <nanobind/ndarray.h>
#include <nanobind/stl/tuple.h>

namespace nb = nanobind;
using namespace nb::literals;

namespace pyigl
{
auto sparse_shape( const Eigen::SparseMatrix<Integer> &A)
{
Eigen::Matrix<Integer,2,1> dims(A.rows(), A.cols());
return dims;
}
}

// Bind the wrapper to the Python module
void bind_sparse_shape(nb::module_ &m)
{
m.def(
"sparse_shape",
&pyigl::sparse_shape,
"A"_a,
R"("Returns shape of A as 2-vector)");
}


36 changes: 36 additions & 0 deletions test_sparse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import igl
import time

V, F = igl.icosahedron()
V, F = igl.upsample(V, F)
V, F = igl.upsample(V, F)
V, F = igl.upsample(V, F)
V, F = igl.upsample(V, F)
V, F = igl.upsample(V, F)
V, F = igl.upsample(V, F)

max_iters = 6
for i in range(max_iters):
A = igl.adjacency_matrix(F)
n = A.shape[0]

start = time.time()
dims = igl.sparse_shape(A)
t_shape = time.time() - start

start = time.time()
A2 = igl.sparse_noop(A)
t_noop = time.time() - start

start = time.time()
dims = igl.sparse_map_shape(A)
t_map_shape = time.time() - start

start = time.time()
A2 = igl.sparse_map_noop(A)
t_map_noop = time.time() - start

print(f"{n} {t_shape:.6g} {t_noop:.6g} {t_map_shape:.6g} {t_map_noop:.6g}")

if i != max_iters-1:
V, F = igl.upsample(V, F)
Loading