Skip to content

Commit 6e0d2b8

Browse files
committed
test sparse map
1 parent 492bb96 commit 6e0d2b8

6 files changed

Lines changed: 77 additions & 5 deletions

File tree

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/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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using namespace nb::literals;
99

1010
namespace pyigl
1111
{
12-
auto sparse_noop( const Eigen::Map<const Eigen::SparseMatrix<Integer>> &A)
12+
auto sparse_noop( const Eigen::SparseMatrix<Integer> &A)
1313
{
1414
return A;
1515
}

src/sparse_shape.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using namespace nb::literals;
99

1010
namespace pyigl
1111
{
12-
auto sparse_shape( const Eigen::Map<const Eigen::SparseMatrix<Integer>> &A)
12+
auto sparse_shape( const Eigen::SparseMatrix<Integer> &A)
1313
{
1414
Eigen::Matrix<Integer,2,1> dims(A.rows(), A.cols());
1515
return dims;

test_sparse.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
import time
33

44
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)
511

6-
max_iters = 10
12+
max_iters = 6
713
for i in range(max_iters):
814
A = igl.adjacency_matrix(F)
915
n = A.shape[0]
@@ -16,7 +22,15 @@
1622
A2 = igl.sparse_noop(A)
1723
t_noop = time.time() - start
1824

19-
print(f"{n} {t_shape:.6g} {t_noop:.6g}")
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}")
2034

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

0 commit comments

Comments
 (0)