From 9ab1985b5ff9b9161dfba74d00bbbbff14df6db9 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Tue, 15 Apr 2025 10:57:35 -0400 Subject: [PATCH 1/5] bump nanobind to PR --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a4d576c0..ec58d7ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) From 492bb964f419de1b7c2ab7d3a2624a26b05c8b8c Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Tue, 15 Apr 2025 11:51:19 -0400 Subject: [PATCH 2/5] test using map --- src/sparse_noop.cpp | 27 +++++++++++++++++++++++++++ src/sparse_shape.cpp | 29 +++++++++++++++++++++++++++++ test_sparse.py | 22 ++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/sparse_noop.cpp create mode 100644 src/sparse_shape.cpp create mode 100644 test_sparse.py diff --git a/src/sparse_noop.cpp b/src/sparse_noop.cpp new file mode 100644 index 00000000..33d48fca --- /dev/null +++ b/src/sparse_noop.cpp @@ -0,0 +1,27 @@ +#include "default_types.h" +#include +#include +#include +#include + +namespace nb = nanobind; +using namespace nb::literals; + +namespace pyigl +{ + auto sparse_noop( const Eigen::Map> &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)"); +} + diff --git a/src/sparse_shape.cpp b/src/sparse_shape.cpp new file mode 100644 index 00000000..c7d54be9 --- /dev/null +++ b/src/sparse_shape.cpp @@ -0,0 +1,29 @@ +#include "default_types.h" +#include +#include +#include +#include + +namespace nb = nanobind; +using namespace nb::literals; + +namespace pyigl +{ + auto sparse_shape( const Eigen::Map> &A) + { + Eigen::Matrix 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)"); +} + + diff --git a/test_sparse.py b/test_sparse.py new file mode 100644 index 00000000..f639ecec --- /dev/null +++ b/test_sparse.py @@ -0,0 +1,22 @@ +import igl +import time + +V, F = igl.icosahedron() + +max_iters = 10 +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 + + print(f"{n} {t_shape:.6g} {t_noop:.6g}") + + if i != max_iters-1: + V, F = igl.upsample(V, F) From 6e0d2b88cadea689b0cc2d0824912eec71d41c23 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Tue, 15 Apr 2025 11:56:50 -0400 Subject: [PATCH 3/5] test sparse map --- README.md | 4 +++- src/sparse_map_noop.cpp | 27 +++++++++++++++++++++++++++ src/sparse_map_shape.cpp | 29 +++++++++++++++++++++++++++++ src/sparse_noop.cpp | 2 +- src/sparse_shape.cpp | 2 +- test_sparse.py | 18 ++++++++++++++++-- 6 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 src/sparse_map_noop.cpp create mode 100644 src/sparse_map_shape.cpp diff --git a/README.md b/README.md index 77e6b81e..3733e50c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/sparse_map_noop.cpp b/src/sparse_map_noop.cpp new file mode 100644 index 00000000..66778bfb --- /dev/null +++ b/src/sparse_map_noop.cpp @@ -0,0 +1,27 @@ +#include "default_types.h" +#include +#include +#include +#include + +namespace nb = nanobind; +using namespace nb::literals; + +namespace pyigl +{ + auto sparse_map_noop( const Eigen::Map> &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)"); +} + diff --git a/src/sparse_map_shape.cpp b/src/sparse_map_shape.cpp new file mode 100644 index 00000000..48349e8a --- /dev/null +++ b/src/sparse_map_shape.cpp @@ -0,0 +1,29 @@ +#include "default_types.h" +#include +#include +#include +#include + +namespace nb = nanobind; +using namespace nb::literals; + +namespace pyigl +{ + auto sparse_map_shape( const Eigen::Map> &A) + { + Eigen::Matrix 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)"); +} + + diff --git a/src/sparse_noop.cpp b/src/sparse_noop.cpp index 33d48fca..b28d55c2 100644 --- a/src/sparse_noop.cpp +++ b/src/sparse_noop.cpp @@ -9,7 +9,7 @@ using namespace nb::literals; namespace pyigl { - auto sparse_noop( const Eigen::Map> &A) + auto sparse_noop( const Eigen::SparseMatrix &A) { return A; } diff --git a/src/sparse_shape.cpp b/src/sparse_shape.cpp index c7d54be9..f04b4f0d 100644 --- a/src/sparse_shape.cpp +++ b/src/sparse_shape.cpp @@ -9,7 +9,7 @@ using namespace nb::literals; namespace pyigl { - auto sparse_shape( const Eigen::Map> &A) + auto sparse_shape( const Eigen::SparseMatrix &A) { Eigen::Matrix dims(A.rows(), A.cols()); return dims; diff --git a/test_sparse.py b/test_sparse.py index f639ecec..74074d80 100644 --- a/test_sparse.py +++ b/test_sparse.py @@ -2,8 +2,14 @@ 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 = 10 +max_iters = 6 for i in range(max_iters): A = igl.adjacency_matrix(F) n = A.shape[0] @@ -16,7 +22,15 @@ A2 = igl.sparse_noop(A) t_noop = time.time() - start - print(f"{n} {t_shape:.6g} {t_noop:.6g}") + 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) From 432f247168b8cee275da08e5f43b1d57a1c53fb1 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Tue, 13 May 2025 10:14:52 -0400 Subject: [PATCH 4/5] doc typo --- src/copyleft/cgal/remesh_self_intersections.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/copyleft/cgal/remesh_self_intersections.cpp b/src/copyleft/cgal/remesh_self_intersections.cpp index b85c8d4b..5898127f 100644 --- a/src/copyleft/cgal/remesh_self_intersections.cpp +++ b/src/copyleft/cgal/remesh_self_intersections.cpp @@ -61,7 +61,9 @@ void bind_remesh_self_intersections(nb::module_ &m) - VV: remeshed vertex positions - FF: remeshed face indices - IF: intersecting face pairs - - J: birth triangle indices)"); - + - J: birth triangle indices + - IM if stitch_all = true #VV list from 0 to #VV-1 + elseif stitch_all = false #VV list of indices into VV of unique vertices. + )"); } From 2cde10b90d34183a8d5fbd9fec65a549ff22f1bb Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Wed, 14 May 2025 21:00:07 -0400 Subject: [PATCH 5/5] nanobind on release --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec58d7ed..a5b9251f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ include(FetchContent) FetchContent_Declare( nanobind GIT_REPOSITORY https://github.com/wjakob/nanobind.git - GIT_TAG d698692936bae1c4963e5c42f41fd88e9095b1c0 + GIT_TAG v2.7.0 ) FetchContent_MakeAvailable(nanobind)