mlpack
set_input_width_visitor_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_VISITOR_SET_INPUT_WIDTH_VISITOR_IMPL_HPP
13 #define MLPACK_METHODS_ANN_VISITOR_SET_INPUT_WIDTH_VISITOR_IMPL_HPP
14 
15 // In case it hasn't been included yet.
17 
18 namespace mlpack {
19 namespace ann {
20 
22 inline SetInputWidthVisitor::SetInputWidthVisitor(const size_t inputWidth,
23  const bool reset) :
24  inputWidth(inputWidth),
25  reset(reset)
26 {
27  /* Nothing to do here. */
28 }
29 
30 template<typename LayerType>
31 inline bool SetInputWidthVisitor::operator()(LayerType* layer) const
32 {
33  return LayerInputWidth(layer);
34 }
35 
36 inline bool SetInputWidthVisitor::operator()(MoreTypes layer) const
37 {
38  return layer.apply_visitor(*this);
39 }
40 
41 template<typename T>
42 inline typename std::enable_if<
43  !HasInputWidth<T, size_t&(T::*)()>::value &&
44  !HasModelCheck<T>::value, bool>::type
45 SetInputWidthVisitor::LayerInputWidth(T* /* layer */) const
46 {
47  return false;
48 }
49 
50 template<typename T>
51 inline typename std::enable_if<
52  HasInputWidth<T, size_t&(T::*)()>::value &&
53  !HasModelCheck<T>::value, bool>::type
54 SetInputWidthVisitor::LayerInputWidth(T* layer) const
55 {
56  if (layer->InputWidth() == 0 || reset)
57  {
58  layer->InputWidth() = inputWidth;
59  }
60 
61  return true;
62 }
63 
64 template<typename T>
65 inline typename std::enable_if<
66  !HasInputWidth<T, size_t&(T::*)()>::value &&
67  HasModelCheck<T>::value, bool>::type
68 SetInputWidthVisitor::LayerInputWidth(T* layer) const
69 {
70  for (size_t i = 0; i < layer->Model().size(); ++i)
71  {
72  boost::apply_visitor(SetInputWidthVisitor(inputWidth, reset),
73  layer->Model()[i]);
74  }
75 
76  return true;
77 }
78 
79 template<typename T>
80 inline typename std::enable_if<
81  HasInputWidth<T, size_t&(T::*)()>::value &&
82  HasModelCheck<T>::value, bool>::type
83 SetInputWidthVisitor::LayerInputWidth(T* layer) const
84 {
85  if (layer->InputWidth() == 0 || reset)
86  {
87  layer->InputWidth() = inputWidth;
88  }
89 
90  for (size_t i = 0; i < layer->Model().size(); ++i)
91  {
92  boost::apply_visitor(SetInputWidthVisitor(inputWidth, reset),
93  layer->Model()[i]);
94  }
95 
96  return true;
97 }
98 
99 } // namespace ann
100 } // namespace mlpack
101 
102 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
bool operator()(LayerType *layer) const
Update the input width parameter.
Definition: set_input_width_visitor_impl.hpp:31
SetInputWidthVisitor(const size_t inputWidth=0, const bool reset=false)
Update the input width parameter with the given input width.
Definition: set_input_width_visitor_impl.hpp:22