Skip to content

Commit

Permalink
Update nanobind extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
iglesias committed Jun 16, 2024
1 parent a73d276 commit 127968b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/nanobind.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
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
embedded_data = tapkee.withParameters(parameters).embedUsing(data).embedding
plot(data, embedded_data.T, colors)
5 changes: 5 additions & 0 deletions src/cli/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ typename Mapping::mapped_type parse_multiple(Mapping mapping, const std::string&
throw std::logic_error(str);
}

auto parse_reduction_method(const std::string& str)
{
return parse_multiple(DIMENSION_REDUCTION_METHODS, str);
}

template <class PairwiseCallback>
tapkee::DenseMatrix matrix_from_callback(const tapkee::IndexType N, PairwiseCallback callback)
{
Expand Down
10 changes: 4 additions & 6 deletions src/python/nanobind_extension.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <cli/util.hpp> // for parse_reduction_method, TODO consider moving from src to include
#include <cli/util.hpp>

#include <stichwort/parameter.hpp> // for Parameter::create

#include <tapkee/chain_interface.hpp> // for initialize, withParameters
#include <tapkee/chain_interface.hpp>
#include <tapkee/defines.hpp> // for ParametersSet, TapkeeOutput
#include <tapkee/defines/methods.hpp> // for DimensionReductionMethod

Expand All @@ -14,17 +14,15 @@ namespace nb = nanobind;

using stichwort::Parameter;

using tapkee::initialize;
using tapkee::DimensionReductionMethod;
using tapkee::ParametersSet;
using tapkee::TapkeeOutput;
using tapkee::with;

using tapkee::tapkee_internal::ParametersInitializedState; // TODO consider making it part of the "external" API

NB_MODULE(tapkee, m) {
nb::class_<initialize>(m, "initialize")
.def(nb::init<>())
.def("withParameters", &initialize::withParameters);
m.def("withParameters", &with);

nb::class_<ParametersSet>(m, "ParametersSet")
.def(nb::init<>())
Expand Down
2 changes: 1 addition & 1 deletion test/test_nanobind_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def test_exception_unknown_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
embedded_data = tapkee.withParameters(parameters).embedUsing(data).embedding
assert(embedded_data.shape == tuple([data.shape[1], target_dimension]))

0 comments on commit 127968b

Please sign in to comment.