mlpack
run_set_visitor_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_VISITOR_RUN_SET_VISITOR_IMPL_HPP
13 #define MLPACK_METHODS_ANN_VISITOR_RUN_SET_VISITOR_IMPL_HPP
14 
15 // In case it hasn't been included yet.
16 #include "run_set_visitor.hpp"
17 
18 namespace mlpack {
19 namespace ann {
20 
23  const bool run) : run(run)
24 {
25  /* Nothing to do here. */
26 }
27 
28 template<typename LayerType>
29 inline void RunSetVisitor::operator()(LayerType* layer) const
30 {
31  LayerRun(layer);
32 }
33 
34 inline void RunSetVisitor::operator()(MoreTypes layer) const
35 {
36  layer.apply_visitor(*this);
37 }
38 
39 template<typename T>
40 inline typename std::enable_if<
41  HasRunCheck<T, bool&(T::*)(void)>::value &&
42  HasModelCheck<T>::value, void>::type
43 RunSetVisitor::LayerRun(T* layer) const
44 {
45  layer->Run() = run;
46 
47  for (size_t i = 0; i < layer->Model().size(); ++i)
48  {
49  boost::apply_visitor(RunSetVisitor(run),
50  layer->Model()[i]);
51  }
52 }
53 
54 template<typename T>
55 inline typename std::enable_if<
56  !HasRunCheck<T, bool&(T::*)(void)>::value &&
57  HasModelCheck<T>::value, void>::type
58 RunSetVisitor::LayerRun(T* layer) const
59 {
60  for (size_t i = 0; i < layer->Model().size(); ++i)
61  {
62  boost::apply_visitor(RunSetVisitor(run),
63  layer->Model()[i]);
64  }
65 }
66 
67 template<typename T>
68 inline typename std::enable_if<
69  HasRunCheck<T, bool&(T::*)(void)>::value &&
70  !HasModelCheck<T>::value, void>::type
71 RunSetVisitor::LayerRun(T* layer) const
72 {
73  layer->Run() = run;
74 }
75 
76 template<typename T>
77 inline typename std::enable_if<
78  !HasRunCheck<T, bool&(T::*)(void)>::value &&
79  !HasModelCheck<T>::value, void>::type
80 RunSetVisitor::LayerRun(T* /* input */) const
81 {
82  /* Nothing to do here. */
83 }
84 
85 } // namespace ann
86 } // namespace mlpack
87 
88 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void operator()(LayerType *layer) const
Set the run parameter.
Definition: run_set_visitor_impl.hpp:29
RunSetVisitor(const bool run=true)
Set the run parameter given the current run value.
Definition: run_set_visitor_impl.hpp:22