Commit fdc89507 authored by Davis King's avatar Davis King

Changed code a little to make the reject_labeling() routine optional.

Now if you don't define it you get a reasonable default behavior
rather than a compiler error.
parent 2904fa35
......@@ -55,6 +55,69 @@ namespace dlib
}
// ----------------------------------------------------------------------------------------
namespace impl
{
template <
typename T,
bool (T::*funct)(const std::vector<typename T::sample_type>&, const matrix_exp<matrix<unsigned long> >&, unsigned long)const
>
struct hrlh_helper
{
typedef double type;
};
template <typename T>
char has_reject_labeling_helper( typename hrlh_helper<T,&T::template reject_labeling<matrix<unsigned long> > >::type = 0 ) { return 0;}
struct two_bytes
{
char a[2];
};
template <typename T>
two_bytes has_reject_labeling_helper(int) { return two_bytes();}
// This is a template to tell you if a feature_extractor has a reject_labeling function or not.
template <typename T, typename U = void >
struct has_reject_labeling
{
static const bool value = false;
};
template <typename T>
struct has_reject_labeling <T,typename dlib::enable_if_c<sizeof(dlib::impl::has_reject_labeling_helper<T>(2.2)) == 1 >::type >
{
static const bool value = true;
};
template <typename feature_extractor, typename EXP, typename sample_type>
typename enable_if<has_reject_labeling<feature_extractor>,bool>::type call_reject_labeling_if_exists (
const feature_extractor& fe,
const std::vector<sample_type>& x,
const matrix_exp<EXP>& y,
unsigned long position
)
{
return fe.reject_labeling(x, y, position);
}
template <typename feature_extractor, typename EXP, typename sample_type>
typename disable_if<has_reject_labeling<feature_extractor>,bool>::type call_reject_labeling_if_exists (
const feature_extractor& ,
const std::vector<sample_type>& ,
const matrix_exp<EXP>& ,
unsigned long
)
{
return false;
}
}
// ----------------------------------------------------------------------------------------
template <
......@@ -99,7 +162,7 @@ namespace dlib
const matrix_exp<EXP>& node_states
) const
{
if (fe.reject_labeling(sequence, node_states, node_id))
if (dlib::impl::call_reject_labeling_if_exists(fe, sequence, node_states, node_id))
return -std::numeric_limits<double>::infinity();
return fe_helpers::dot(weights, fe, sequence, node_states, node_id);
......
......@@ -94,8 +94,9 @@ namespace dlib
- returns true
(note that reject_labeling() is just an optional tool to allow you
to overrule the normal labeling algorithm. You don't have to use
it. So if you prefer you can set reject_labeling() to always return
false.)
it. So if you don't include a reject_labeling() method in your
feature extractor it is the same as including one that always
returns false.)
- else
- returns false
!*/
......
......@@ -51,16 +51,6 @@ public:
return num_label_states;
}
template <typename EXP>
bool reject_labeling (
const std::vector<sample_type>& x,
const matrix_exp<EXP>& y,
unsigned long position
) const
{
return false;
}
template <typename feature_setter, typename EXP>
void get_features (
feature_setter& set_feature,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment