check_input_shape.hpp
Go to the documentation of this file.
1 
16 #ifndef MLPACK_METHODS_ANN_UTIL_CHECK_INPUT_SHAPE_HPP
17 #define MLPACK_METHODS_ANN_UTIL_CHECK_INPUT_SHAPE_HPP
18 
20 
21 namespace mlpack {
22 namespace ann {
23 
24 template<typename T>
25 void CheckInputShape(const T& network,
26  const size_t inputShape,
27  const std::string& functionName)
28 {
29  for (size_t l = 0; l < network.size(); ++l)
30  {
31  size_t layerInShape = boost::apply_visitor(InShapeVisitor(), network[l]);
32  if (layerInShape == 0)
33  {
34  continue;
35  }
36  else if (layerInShape == inputShape)
37  {
38  break;
39  }
40  else
41  {
42  std::string estr = functionName + ": the first layer of the network " +
43  "expects " + std::to_string(layerInShape) + " elements, but the " +
44  "input has " + std::to_string(inputShape) + " dimensions!";
45  throw std::logic_error(estr);
46  }
47  }
48 }
49 
50 } // namespace ann
51 } // namespace mlpack
52 
53 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
void CheckInputShape(const T &network, const size_t inputShape, const std::string &functionName)
InShapeVisitor returns the input shape a Layer expects.