2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/tap.hpp>
|
2018-04-18 21:48:24 +10:00
|
|
|
|
2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/kmeans.hpp>
|
2018-04-18 21:48:24 +10:00
|
|
|
|
2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/point.hpp>
|
2018-04-18 21:48:24 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int
|
|
|
|
main ()
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2018-04-18 21:48:24 +10:00
|
|
|
|
|
|
|
// create one point and check it 'converges' to this one point
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
const std::array<cruft::point3f,1> p { {{1,2,3}} };
|
|
|
|
std::array<cruft::point3f,1> q;
|
2018-04-18 21:48:24 +10:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::kmeans (cruft::view{p}, cruft::view{q});
|
2024-08-06 14:49:36 +10:00
|
|
|
// clang#19-rc2: ICE when instantiating p == q
|
|
|
|
//
|
|
|
|
// clang++-19: clang/include/clang/AST/DeclTemplate.h:1938:
|
|
|
|
// void clang::ClassTemplateSpecializationDecl::setPointOfInstantiation(clang::SourceLocation):
|
|
|
|
// Assertion `Loc.isValid() && "point of instantiation must be valid!"' failed.
|
|
|
|
//
|
|
|
|
// So just compare the items directly.
|
|
|
|
static_assert (p.size () == q.size ());
|
|
|
|
tap.expect_eq (p[0], q[0], "single point, single k");
|
2018-04-18 21:48:24 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
// create two vectors, check if the mean converges to their average
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
const std::array<cruft::vector3f,2> p {{
|
2018-04-18 21:48:24 +10:00
|
|
|
{1}, {2}
|
|
|
|
}};
|
2018-08-05 14:42:02 +10:00
|
|
|
std::array<cruft::vector3f,1> q;
|
2018-04-18 21:48:24 +10:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::kmeans (cruft::view{p}, cruft::view{q});
|
2018-04-18 21:48:24 +10:00
|
|
|
tap.expect_eq (q[0], (p[0]+p[1])/2, "two point, single k");
|
|
|
|
}
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|