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