Skip to content

Commit

Permalink
Pass along float type templating to VpTree, added test.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Dec 19, 2023
1 parent f2928b3 commit ff42321
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/umappp/Umap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ class Umap {
*/
template<typename Input = Float>
Status initialize(int ndim_in, size_t nobs, const Input* input, int ndim_out, Float* embedding) {
knncolle::VpTreeEuclidean<> searcher(ndim_in, nobs, input);
knncolle::VpTreeEuclidean<int, Input, Input, Input> searcher(ndim_in, nobs, input);
return initialize(&searcher, ndim_out, embedding);
}
#endif
Expand Down
28 changes: 28 additions & 0 deletions tests/src/Umap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ TEST_P(UmapTest, Basic) {

status.run();
EXPECT_EQ(status.epoch(), 500);
for (auto o : output){
// Check that we don't get any weirdness.
EXPECT_FALSE(std::isnan(o));
}

// Same results if we ran it from the top.
std::vector<double> copy(nobs * ndim);
Expand Down Expand Up @@ -100,6 +104,30 @@ INSTANTIATE_TEST_SUITE_P(
)
);

TEST(UmapTest, SinglePrecision) {
int nobs = 87;
int k = 5;
int ndim = 7;

std::mt19937_64 rng(nobs * k + 1);
std::normal_distribution<float> dist(0, 1);
std::vector<float> data(nobs * ndim);
for (int r = 0; r < data.size(); ++r) {
data[r] = dist(rng);
}

umappp::Umap<float> runner;
std::vector<float> output(nobs * ndim);
auto status = runner.initialize(ndim, nobs, data.data(), 2, output.data());

status.run();
EXPECT_EQ(status.epoch(), 500);
for (auto o : output){
// Check that we don't get any weirdness.
EXPECT_FALSE(std::isnan(o));
}
}

TEST(UmapTest, EpochDecay) {
EXPECT_EQ(umappp::choose_num_epochs(-1, 1000), 500);
EXPECT_TRUE(umappp::choose_num_epochs(-1, 20000) < 500);
Expand Down

0 comments on commit ff42321

Please sign in to comment.