mlpack
select_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_LAYER_SELECT_IMPL_HPP
13 #define MLPACK_METHODS_ANN_LAYER_SELECT_IMPL_HPP
14 
15 // In case it hasn't yet been included.
16 #include "constant.hpp"
17 
18 namespace mlpack {
19 namespace ann {
20 
21 template<typename InputDataType, typename OutputDataType>
23  const size_t index,
24  const size_t elements) :
25  index(index),
26  elements(elements)
27  {
28  // Nothing to do here.
29  }
30 
31 template<typename InputDataType, typename OutputDataType>
32 template<typename eT>
34  const arma::Mat<eT>& input, arma::Mat<eT>& output)
35 {
36  if (elements == 0)
37  {
38  output = input.col(index);
39  }
40  else
41  {
42  output = input.submat(0, index, elements - 1, index);
43  }
44 }
45 
46 template<typename InputDataType, typename OutputDataType>
47 template<typename eT>
49  const arma::Mat<eT>& /* input */,
50  const arma::Mat<eT>& gy,
51  arma::Mat<eT>& g)
52 {
53  if (elements == 0)
54  {
55  g = gy;
56  }
57  else
58  {
59  g = gy.submat(0, 0, elements - 1, 0);
60  }
61 }
62 
63 template<typename InputDataType, typename OutputDataType>
64 template<typename Archive>
66  Archive& ar, const uint32_t /* version */)
67 {
68  ar(CEREAL_NVP(index));
69  ar(CEREAL_NVP(elements));
70 }
71 
72 } // namespace ann
73 } // namespace mlpack
74 
75 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void Backward(const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
Definition: select_impl.hpp:48
Select(const size_t index=0, const size_t elements=0)
Create the Select object.
Definition: select_impl.hpp:22
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: select_impl.hpp:65
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
Definition: select_impl.hpp:33