Skip to content

Commit

Permalink
Integrate basic test.
Browse files Browse the repository at this point in the history
  • Loading branch information
iglesias committed May 20, 2024
1 parent 1f18383 commit 07910db
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/nanobind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ jobs:
- name: Build
# TODO there are A LOT of warnings in the logs from nanobind (-pedantic, -Wshadow).
run: cmake --build ${{github.workspace}}/build

- name: Test
working-directory: ${{github.workspace}}
run: PYTHONPATH=. python test/test_nanobind_extension.py
16 changes: 1 addition & 15 deletions examples/nanobind.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
#!/usr/bin/python3.12

import lib.tapkee as tapkee
import numpy as np
from utils import generate_data, plot

def parse_reduction_method(method_name: str):
return tapkee.parse_reduction_method(method_name)

def test_exception_unknown_method():
try:
parse_reduction_method('unknown')
assert(False)
except:
pass

if __name__=='__main__':
test_exception_unknown_method()
parameters = tapkee.ParametersSet()
method = parse_reduction_method('lle')
method = tapkee.parse_reduction_method('lle')
parameters.add(tapkee.Parameter.create('dimension reduction method', method))
data, colors = generate_data('swissroll')
embedded_data = tapkee.initialize().withParameters(parameters).embedUsing(data).embedding
Expand Down
3 changes: 2 additions & 1 deletion src/python/nanobind_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ NB_MODULE(tapkee, m) {
.def_rw("name", &DimensionReductionMethod::name_);

nb::class_<Parameter>(m, "Parameter")
.def_static("create", &Parameter::create<DimensionReductionMethod>);
.def_static("create", &Parameter::create<DimensionReductionMethod>)
.def_static("create", &Parameter::create<int>);
}
21 changes: 21 additions & 0 deletions test/test_nanobind_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import lib.tapkee as tapkee
import numpy as np

def test_exception_unknown_method():
try:
tapkee.parse_reduction_method('unknown')
assert(False)
except:
pass

if __name__=='__main__':
test_exception_unknown_method()
parameters = tapkee.ParametersSet()
method = tapkee.parse_reduction_method('spe')
assert(method.name == 'Stochastic Proximity Embedding (SPE)')
parameters.add(tapkee.Parameter.create('dimension reduction method', method))
target_dimension = 2
parameters.add(tapkee.Parameter.create('target dimension', target_dimension))
data = np.random.randn(124, 3)
embedded_data = tapkee.initialize().withParameters(parameters).embedUsing(data).embedding
assert(embedded_data.shape == tuple([data.shape[1], target_dimension]))

0 comments on commit 07910db

Please sign in to comment.