mlpack
multiply_constant_impl.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LAYER_MULTIPLY_CONSTANT_IMPL_HPP
14 #define MLPACK_METHODS_ANN_LAYER_MULTIPLY_CONSTANT_IMPL_HPP
15 
16 // In case it hasn't yet been included.
17 #include "multiply_constant.hpp"
18 
19 namespace mlpack {
20 namespace ann {
21 
22 template<typename InputDataType, typename OutputDataType>
24  const double scalar) : scalar(scalar)
25 {
26  // Nothing to do here.
27 }
28 
29 template<typename InputDataType, typename OutputDataType>
31  const MultiplyConstant& layer) :
32  scalar(layer.scalar)
33 {
34  // Nothing to do here.
35 }
36 
37 template<typename InputDataType, typename OutputDataType>
39  MultiplyConstant&& layer) :
40  scalar(std::move(layer.scalar))
41 {
42  // Nothing to do here.
43 }
44 
45 template<typename InputDataType, typename OutputDataType>
48  const MultiplyConstant& layer)
49 {
50  if (this != &layer)
51  {
52  scalar = layer.scalar;
53  }
54  return *this;
55 }
56 
57 template<typename InputDataType, typename OutputDataType>
60  MultiplyConstant&& layer)
61 {
62  if (this != &layer)
63  {
64  scalar = std::move(layer.scalar);
65  }
66  return *this;
67 }
68 
69 template<typename InputDataType, typename OutputDataType>
70 template<typename InputType, typename OutputType>
72  const InputType& input, OutputType& output)
73 {
74  output = input * scalar;
75 }
76 
77 template<typename InputDataType, typename OutputDataType>
78 template<typename DataType>
80  const DataType& /* input */, const DataType& gy, DataType& g)
81 {
82  g = gy * scalar;
83 }
84 
85 template<typename InputDataType, typename OutputDataType>
86 template<typename Archive>
88  Archive& ar, const uint32_t /* version */)
89 {
90  ar(CEREAL_NVP(scalar));
91 }
92 
93 } // namespace ann
94 } // namespace mlpack
95 
96 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
Definition: pointer_wrapper.hpp:23
void Backward(const DataType &, const DataType &gy, DataType &g)
Ordinary feed backward pass of a neural network.
Definition: multiply_constant_impl.hpp:79
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: multiply_constant_impl.hpp:87
void Forward(const InputType &input, OutputType &output)
Ordinary feed forward pass of a neural network.
Definition: multiply_constant_impl.hpp:71
Implementation of the multiply constant layer.
Definition: multiply_constant.hpp:34
MultiplyConstant & operator=(const MultiplyConstant &layer)
Copy assignment operator.
Definition: multiply_constant_impl.hpp:47
MultiplyConstant(const double scalar=1.0)
Create the MultiplyConstant object.
Definition: multiply_constant_impl.hpp:23