-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert DimensionReductionMethod to a class instead of enum #94
Changes from 1 commit
206069f
b83d9c6
4752993
7e0f13e
839dc81
9c81877
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,58 +22,53 @@ class DynamicImplementation : public ImplementationBase<RandomAccessIterator, Ke | |
{ | ||
public: | ||
using ImplementationBase<RandomAccessIterator, KernelCallback, DistanceCallback, FeaturesCallback>::ImplementationBase; | ||
TapkeeOutput embedUsing(DimensionReductionMethod method) | ||
TapkeeOutput embedUsing(const DimensionReductionMethod& method) | ||
{ | ||
timed_context tctx__(fmt::format("[+] embedding with {}", method.name())); | ||
|
||
if (this->context.is_cancelled()) | ||
throw cancelled_exception(); | ||
|
||
if (method.needs_kernel && is_dummy<KernelCallback>::value) | ||
{ | ||
throw unsupported_method_error("Kernel callback is missed"); | ||
} | ||
if (method.needs_distance && is_dummy<DistanceCallback>::value) | ||
{ | ||
throw unsupported_method_error("Distance callback is missed"); | ||
} | ||
if (method.needs_features && is_dummy<FeaturesCallback>::value) | ||
{ | ||
throw unsupported_method_error("Features callback is missed"); | ||
} | ||
|
||
#define tapkee_method_handle(X) \ | ||
case X: { \ | ||
timed_context tctx__("[+] embedding with " #X); \ | ||
if (MethodTraits<X>::needs_kernel && is_dummy<KernelCallback>::value) \ | ||
{ \ | ||
throw unsupported_method_error("Kernel callback is missed"); \ | ||
} \ | ||
if (MethodTraits<X>::needs_distance && is_dummy<DistanceCallback>::value) \ | ||
{ \ | ||
throw unsupported_method_error("Distance callback is missed"); \ | ||
} \ | ||
if (MethodTraits<X>::needs_features && is_dummy<FeaturesCallback>::value) \ | ||
{ \ | ||
throw unsupported_method_error("Features callback is missed"); \ | ||
} \ | ||
if (method.is(X)) { \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be |
||
auto self = static_cast<ImplementationBase<RandomAccessIterator, KernelCallback, DistanceCallback, FeaturesCallback>>(*this); \ | ||
auto implementation = \ | ||
X ## Implementation<RandomAccessIterator, KernelCallback, DistanceCallback, FeaturesCallback>(self); \ | ||
return implementation.embed(); \ | ||
} \ | ||
break; | ||
|
||
switch (method) | ||
{ | ||
tapkee_method_handle(KernelLocallyLinearEmbedding); | ||
tapkee_method_handle(KernelLocalTangentSpaceAlignment); | ||
tapkee_method_handle(DiffusionMap); | ||
tapkee_method_handle(MultidimensionalScaling); | ||
tapkee_method_handle(LandmarkMultidimensionalScaling); | ||
tapkee_method_handle(Isomap); | ||
tapkee_method_handle(LandmarkIsomap); | ||
tapkee_method_handle(NeighborhoodPreservingEmbedding); | ||
tapkee_method_handle(LinearLocalTangentSpaceAlignment); | ||
tapkee_method_handle(HessianLocallyLinearEmbedding); | ||
tapkee_method_handle(LaplacianEigenmaps); | ||
tapkee_method_handle(LocalityPreservingProjections); | ||
tapkee_method_handle(PCA); | ||
tapkee_method_handle(KernelPCA); | ||
tapkee_method_handle(RandomProjection); | ||
tapkee_method_handle(StochasticProximityEmbedding); | ||
tapkee_method_handle(PassThru); | ||
tapkee_method_handle(FactorAnalysis); | ||
tapkee_method_handle(tDistributedStochasticNeighborEmbedding); | ||
tapkee_method_handle(ManifoldSculpting); | ||
default: | ||
break; | ||
} | ||
} | ||
tapkee_method_handle(KernelLocallyLinearEmbedding); | ||
tapkee_method_handle(KernelLocalTangentSpaceAlignment); | ||
tapkee_method_handle(DiffusionMap); | ||
tapkee_method_handle(MultidimensionalScaling); | ||
tapkee_method_handle(LandmarkMultidimensionalScaling); | ||
tapkee_method_handle(Isomap); | ||
tapkee_method_handle(LandmarkIsomap); | ||
tapkee_method_handle(NeighborhoodPreservingEmbedding); | ||
tapkee_method_handle(LinearLocalTangentSpaceAlignment); | ||
tapkee_method_handle(HessianLocallyLinearEmbedding); | ||
tapkee_method_handle(LaplacianEigenmaps); | ||
tapkee_method_handle(LocalityPreservingProjections); | ||
tapkee_method_handle(PCA); | ||
tapkee_method_handle(KernelPCA); | ||
tapkee_method_handle(RandomProjection); | ||
tapkee_method_handle(StochasticProximityEmbedding); | ||
tapkee_method_handle(PassThru); | ||
tapkee_method_handle(FactorAnalysis); | ||
tapkee_method_handle(tDistributedStochasticNeighborEmbedding); | ||
tapkee_method_handle(ManifoldSculpting); | ||
#undef tapkee_method_handle | ||
return TapkeeOutput(); | ||
} | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here consider
std::bitset<3>
, it will look a bit more concise, I think particularly below in the lookup withtraits.test(i)
instead ofstd::get<i>(traits)
. Although for readability or expressiveness below, probably a struct with three names fields would be preferable. I think all three are good and probably prefer the bitset one most :-)