mlpack
deterministic_set_visitor_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_VISITOR_DETERMINISTIC_SET_VISITOR_IMPL_HPP
13 #define MLPACK_METHODS_ANN_VISITOR_DETERMINISTIC_SET_VISITOR_IMPL_HPP
14 
15 // In case it hasn't been included yet.
17 
18 namespace mlpack {
19 namespace ann {
20 
23  const bool deterministic) : deterministic(deterministic)
24 {
25  /* Nothing to do here. */
26 }
27 
28 template<typename LayerType>
29 inline void DeterministicSetVisitor::operator()(LayerType* layer) const
30 {
31  LayerDeterministic(layer);
32 }
33 
34 inline void DeterministicSetVisitor::operator()(MoreTypes layer) const
35 {
36  layer.apply_visitor(*this);
37 }
38 
39 template<typename T>
40 inline typename std::enable_if<
41  HasDeterministicCheck<T, bool&(T::*)(void)>::value &&
42  HasModelCheck<T>::value, void>::type
43 DeterministicSetVisitor::LayerDeterministic(T* layer) const
44 {
45  layer->Deterministic() = deterministic;
46 
47  for (size_t i = 0; i < layer->Model().size(); ++i)
48  {
49  boost::apply_visitor(DeterministicSetVisitor(deterministic),
50  layer->Model()[i]);
51  }
52 }
53 
54 template<typename T>
55 inline typename std::enable_if<
56  !HasDeterministicCheck<T, bool&(T::*)(void)>::value &&
57  HasModelCheck<T>::value, void>::type
58 DeterministicSetVisitor::LayerDeterministic(T* layer) const
59 {
60  for (size_t i = 0; i < layer->Model().size(); ++i)
61  {
62  boost::apply_visitor(DeterministicSetVisitor(deterministic),
63  layer->Model()[i]);
64  }
65 }
66 
67 template<typename T>
68 inline typename std::enable_if<
69  HasDeterministicCheck<T, bool&(T::*)(void)>::value &&
70  !HasModelCheck<T>::value, void>::type
71 DeterministicSetVisitor::LayerDeterministic(T* layer) const
72 {
73  layer->Deterministic() = deterministic;
74 }
75 
76 template<typename T>
77 inline typename std::enable_if<
78  !HasDeterministicCheck<T, bool&(T::*)(void)>::value &&
79  !HasModelCheck<T>::value, void>::type
80 DeterministicSetVisitor::LayerDeterministic(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 deterministic parameter.
Definition: deterministic_set_visitor_impl.hpp:29
DeterministicSetVisitor(const bool deterministic=true)
Set the deterministic parameter given the current deterministic value.
Definition: deterministic_set_visitor_impl.hpp:22