Skip to content

Commit 492bb96

Browse files
committed
test using map
1 parent 9ab1985 commit 492bb96

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

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::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_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::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_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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import igl
2+
import time
3+
4+
V, F = igl.icosahedron()
5+
6+
max_iters = 10
7+
for i in range(max_iters):
8+
A = igl.adjacency_matrix(F)
9+
n = A.shape[0]
10+
11+
start = time.time()
12+
dims = igl.sparse_shape(A)
13+
t_shape = time.time() - start
14+
15+
start = time.time()
16+
A2 = igl.sparse_noop(A)
17+
t_noop = time.time() - start
18+
19+
print(f"{n} {t_shape:.6g} {t_noop:.6g}")
20+
21+
if i != max_iters-1:
22+
V, F = igl.upsample(V, F)

0 commit comments

Comments
 (0)