diff --git a/src/mlpack/methods/ann/ffn.hpp b/src/mlpack/methods/ann/ffn.hpp index 6f0115f0d0..1b1dfdeec9 100644 --- a/src/mlpack/methods/ann/ffn.hpp +++ b/src/mlpack/methods/ann/ffn.hpp @@ -296,7 +296,7 @@ class FFN * network or parameters for layers, its state may become invalid, so be sure * to call ResetParameters() afterwards. */ - std::vector* >& Model() { return network; } + std::vector*>& Model() { return network; } //! Return the number of separable functions (the number of predictor points). size_t NumFunctions() const { return numFunctions; } diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index 0d5d992c4e..67f5abfce7 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -48,6 +48,7 @@ template FFN::~FFN() { + //network.clear(); for (size_t i = 0; i < network.size(); ++i) delete network[i]; } @@ -234,8 +235,8 @@ void FFN:: OutputType resultsTemp; Forward(arma::mat(predictors.colptr(0), predictors.n_rows, 1, false, true)); - resultsTemp = network.back()->OutputParameter().col(0); + resultsTemp = network.back()->OutputParameter().col(0); results = arma::mat(resultsTemp.n_elem, predictors.n_cols); results.col(0) = resultsTemp.col(0); @@ -629,7 +630,7 @@ FFN::FFN( // Build new layers according to source network for (size_t i = 0; i < network.network.size(); ++i) { - this->network.push_back(network.network[i]); + this->network.push_back(network.network[i]->Clone()); ResetUpdate(this->network.back()); } }; @@ -665,7 +666,7 @@ template FFN& FFN:: -operator = (FFN network) +operator =(FFN network) { Swap(network); return *this; diff --git a/src/mlpack/methods/ann/layer/base_layer.hpp b/src/mlpack/methods/ann/layer/base_layer.hpp index 709bab0f9e..3eb44e19ec 100644 --- a/src/mlpack/methods/ann/layer/base_layer.hpp +++ b/src/mlpack/methods/ann/layer/base_layer.hpp @@ -73,6 +73,9 @@ class BaseLayer : public Layer // Nothing to do here. } + //! Clone the BaseLayer object. This handles polymorphism correctly. + BaseLayer* Clone() const { return new BaseLayer(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. @@ -141,6 +144,7 @@ class BaseLayer : public Layer // typename OutputType = arma::mat // > // using SigmoidLayer = BaseLayer; +typedef BaseLayer Sigmoid; typedef BaseLayer SigmoidLayer; /** diff --git a/src/mlpack/methods/ann/layer/c_relu.hpp b/src/mlpack/methods/ann/layer/c_relu.hpp index bba84c6780..f7ebe79f8a 100644 --- a/src/mlpack/methods/ann/layer/c_relu.hpp +++ b/src/mlpack/methods/ann/layer/c_relu.hpp @@ -53,6 +53,9 @@ class CReLUType : public Layer //! Create the CReLU object. CReLUType(); + //! Clone the CReLUType object. This handles polymorphism correctly. + CReLUType* Clone() const { return new CReLUType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/celu.hpp b/src/mlpack/methods/ann/layer/celu.hpp index d42126c970..b86c42c345 100644 --- a/src/mlpack/methods/ann/layer/celu.hpp +++ b/src/mlpack/methods/ann/layer/celu.hpp @@ -69,6 +69,9 @@ class CELUType : public Layer */ CELUType(const double alpha = 1.0); + //! Clone the CELUType object. This handles polymorphism correctly. + CELUType* Clone() const { return new CELUType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/concat.hpp b/src/mlpack/methods/ann/layer/concat.hpp index 3796c39793..ffef38b3f1 100644 --- a/src/mlpack/methods/ann/layer/concat.hpp +++ b/src/mlpack/methods/ann/layer/concat.hpp @@ -64,6 +64,9 @@ class ConcatType : public Layer */ ~ConcatType(); + //! Clone the ConcatType object. This handles polymorphism correctly. + ConcatType* Clone() const { return new ConcatType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/concatenate.hpp b/src/mlpack/methods/ann/layer/concatenate.hpp index 9a4677685c..a705a1e9de 100644 --- a/src/mlpack/methods/ann/layer/concatenate.hpp +++ b/src/mlpack/methods/ann/layer/concatenate.hpp @@ -53,6 +53,9 @@ class ConcatenateType : public Layer //! Operator= move constructor. ConcatenateType& operator=(ConcatenateType&& layer); + //! Clone the ConcatenateType object. This handles polymorphism correctly. + ConcatenateType* Clone() const { return new ConcatenateType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/constant.hpp b/src/mlpack/methods/ann/layer/constant.hpp index 65e382d1aa..cb1264b12d 100644 --- a/src/mlpack/methods/ann/layer/constant.hpp +++ b/src/mlpack/methods/ann/layer/constant.hpp @@ -43,6 +43,8 @@ class ConstantType : public Layer */ ConstantType(const size_t outSize, const double scalar = 0); + //! Clone the ConstantType object. This handles polymorphism correctly. + ConstantType* Clone() const { return new ConstantType(*this); } /** * Ordinary feed forward pass of a neural network. The forward pass fills the * output with the specified constant parameter. diff --git a/src/mlpack/methods/ann/layer/dropconnect.hpp b/src/mlpack/methods/ann/layer/dropconnect.hpp index 15a4155410..302344e280 100644 --- a/src/mlpack/methods/ann/layer/dropconnect.hpp +++ b/src/mlpack/methods/ann/layer/dropconnect.hpp @@ -73,6 +73,9 @@ class DropConnectType : public Layer const size_t outSize, const double ratio = 0.5); + //! Clone the DropConnectType object. This handles polymorphism correctly. + DropConnectType* Clone() const { return new DropConnectType(*this); } + /** * Ordinary feed forward pass of the DropConnect layer. * diff --git a/src/mlpack/methods/ann/layer/dropout.hpp b/src/mlpack/methods/ann/layer/dropout.hpp index e2385e7ef9..316066512d 100644 --- a/src/mlpack/methods/ann/layer/dropout.hpp +++ b/src/mlpack/methods/ann/layer/dropout.hpp @@ -73,6 +73,9 @@ class DropoutType : public Layer //! Move assignment operator. DropoutType& operator=(DropoutType&& layer); + //! Clone the DropoutType object. This handles polymorphism correctly. + DropoutType* Clone() const { return new DropoutType(*this); } + /** * Ordinary feed forward pass of the dropout layer. * diff --git a/src/mlpack/methods/ann/layer/elu.hpp b/src/mlpack/methods/ann/layer/elu.hpp index 19e1edcfb2..7b1049d78d 100644 --- a/src/mlpack/methods/ann/layer/elu.hpp +++ b/src/mlpack/methods/ann/layer/elu.hpp @@ -127,6 +127,8 @@ class ELUType : public Layer */ ELUType(const double alpha); + //! Clone the ELUType object. This handles polymorphism correctly. + ELUType* Clone() const { return new ELUType(*this); } /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/fast_lstm.hpp b/src/mlpack/methods/ann/layer/fast_lstm.hpp index 7fbce48670..da2c988cd4 100644 --- a/src/mlpack/methods/ann/layer/fast_lstm.hpp +++ b/src/mlpack/methods/ann/layer/fast_lstm.hpp @@ -97,6 +97,9 @@ class FastLSTMType : public Layer const size_t outSize, const size_t rho = std::numeric_limits::max()); + //! Clone the FastLSTMType object. This handles polymorphism correctly. + FastLSTMType* Clone() const { return new FastLSTMType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/flexible_relu.hpp b/src/mlpack/methods/ann/layer/flexible_relu.hpp index ad7ad0d8c7..86607ba3f9 100644 --- a/src/mlpack/methods/ann/layer/flexible_relu.hpp +++ b/src/mlpack/methods/ann/layer/flexible_relu.hpp @@ -67,6 +67,9 @@ class FlexibleReLUType : public Layer */ FlexibleReLUType(const double alpha = 0); + //! Clone the FlexibleReLUType object. This handles polymorphism correctly. + FlexibleReLUType* Clone() const { return new FlexibleReLUType(*this); } + /** * Reset the layer parameter (alpha). The method is called to * assign the allocated memory to the learnable layer parameter. diff --git a/src/mlpack/methods/ann/layer/hard_tanh.hpp b/src/mlpack/methods/ann/layer/hard_tanh.hpp index fec6d8746c..b214ff095b 100644 --- a/src/mlpack/methods/ann/layer/hard_tanh.hpp +++ b/src/mlpack/methods/ann/layer/hard_tanh.hpp @@ -59,6 +59,9 @@ class HardTanHType : public Layer */ HardTanHType(const double maxValue = 1, const double minValue = -1); + //! Clone the HardTanHType object. This handles polymorphism correctly. + HardTanHType* Clone() const { return new HardTanHType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/hardshrink.hpp b/src/mlpack/methods/ann/layer/hardshrink.hpp index 2095491890..df6c61756c 100644 --- a/src/mlpack/methods/ann/layer/hardshrink.hpp +++ b/src/mlpack/methods/ann/layer/hardshrink.hpp @@ -59,6 +59,9 @@ class HardShrinkType : public Layer */ HardShrinkType(const double lambda = 0.5); + //! Clone the HardShrinkType object. This handles polymorphism correctly. + HardShrinkType* Clone() const { return new HardShrinkType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/highway.hpp b/src/mlpack/methods/ann/layer/highway.hpp index 98bff8cf7b..4b92f4610c 100644 --- a/src/mlpack/methods/ann/layer/highway.hpp +++ b/src/mlpack/methods/ann/layer/highway.hpp @@ -65,6 +65,9 @@ class HighwayType : public Layer //! Destroy the Highway object. ~HighwayType(); + //! Clone the HighwayType object. This handles polymorphism correctly. + HighwayType* Clone() const { return new HighwayType(*this); } + /** * Reset the layer parameter. */ diff --git a/src/mlpack/methods/ann/layer/join.hpp b/src/mlpack/methods/ann/layer/join.hpp index bdea5b07d6..51e42591d9 100644 --- a/src/mlpack/methods/ann/layer/join.hpp +++ b/src/mlpack/methods/ann/layer/join.hpp @@ -36,6 +36,9 @@ class JoinType : public Layer //! Create the JoinType object. JoinType(); + //! Clone the JoinType object. This handles polymorphism correctly. + JoinType* Clone() const { return new JoinType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/layer.hpp b/src/mlpack/methods/ann/layer/layer.hpp index b4dfa0ffb8..26a12bc69d 100644 --- a/src/mlpack/methods/ann/layer/layer.hpp +++ b/src/mlpack/methods/ann/layer/layer.hpp @@ -57,12 +57,26 @@ class Layer { public: //! Default constructor. - Layer() : outputWidth(0), outputHeight(0) - { /* Nothing to do here */ } + Layer() : outputWidth(0), outputHeight(0) { /* Nothing to do here */ } //! Default deconstructor. virtual ~Layer() = default; + //! Copy constructor. + Layer(const Layer& /* layer */) { /* Nothing to do here */ } + + //! Make a copy of the object. + virtual Layer* Clone() const = 0; + + //! Move constructor. + Layer(Layer&& /* layer */) { /* Nothing to do here */ } + + //! Copy assignment operator. + virtual Layer& operator=(const Layer& /* layer */) { return *this; } + + //! Move assignment operator. + virtual Layer& operator=(Layer&& /* layer */) { return *this; } + /** * Takes an input object, and computes the corresponding output of the layer. * In general input and output are matrices. However, some special layers like diff --git a/src/mlpack/methods/ann/layer/layer_norm.hpp b/src/mlpack/methods/ann/layer/layer_norm.hpp index 45ec140ab9..84a8fb2e83 100644 --- a/src/mlpack/methods/ann/layer/layer_norm.hpp +++ b/src/mlpack/methods/ann/layer/layer_norm.hpp @@ -76,6 +76,9 @@ class LayerNormType : public Layer */ LayerNormType(const size_t size, const double eps = 1e-8); + //! Clone the LayerNormType object. This handles polymorphism correctly. + LayerNormType* Clone() const { return new LayerNormType(*this); } + /** * Reset the layer parameters. */ diff --git a/src/mlpack/methods/ann/layer/leaky_relu.hpp b/src/mlpack/methods/ann/layer/leaky_relu.hpp index ffff3b1c0b..eb2e707c4f 100644 --- a/src/mlpack/methods/ann/layer/leaky_relu.hpp +++ b/src/mlpack/methods/ann/layer/leaky_relu.hpp @@ -53,6 +53,9 @@ class LeakyReLUType : public Layer */ LeakyReLUType(const double alpha = 0.03); + //! Clone the LeakyReLUType object. This handles polymorphism correctly. + LeakyReLUType* Clone() const { return new LeakyReLUType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/linear.hpp b/src/mlpack/methods/ann/layer/linear.hpp index f550ad98aa..70a3e3b152 100644 --- a/src/mlpack/methods/ann/layer/linear.hpp +++ b/src/mlpack/methods/ann/layer/linear.hpp @@ -73,6 +73,9 @@ class LinearType: public Layer //! Move assignment operator. LinearType& operator=(LinearType&& layer); + //! Clone the LinearType object. This handles polymorphism correctly. + LinearType* Clone() const { return new LinearType(*this); } + /** * Reset the layer parameter (weights and bias). The method is called to * assign the allocated memory to the internal learnable parameters. diff --git a/src/mlpack/methods/ann/layer/linear3d.hpp b/src/mlpack/methods/ann/layer/linear3d.hpp index f26a644abe..0f95a5c178 100644 --- a/src/mlpack/methods/ann/layer/linear3d.hpp +++ b/src/mlpack/methods/ann/layer/linear3d.hpp @@ -67,6 +67,9 @@ class Linear3DType : public Layer //! Move assignment operator. Linear3DType& operator=(Linear3DType&& layer); + //! Clone the Linear3DType object. This handles polymorphism correctly. + Linear3DType* Clone() const { return new Linear3DType(*this); } + /* * Reset the layer parameter. */ diff --git a/src/mlpack/methods/ann/layer/linear_no_bias.hpp b/src/mlpack/methods/ann/layer/linear_no_bias.hpp index dfa27243e1..a5c26620f4 100644 --- a/src/mlpack/methods/ann/layer/linear_no_bias.hpp +++ b/src/mlpack/methods/ann/layer/linear_no_bias.hpp @@ -55,6 +55,9 @@ class LinearNoBiasType : public Layer const size_t outSize, RegularizerType regularizer = RegularizerType()); + //! Clone the LinearNoBiasType object. This handles polymorphism correctly. + LinearNoBiasType* Clone() const { return new LinearNoBiasType(*this); } + //! Reset the layer parameter. void Reset(); diff --git a/src/mlpack/methods/ann/layer/log_softmax.hpp b/src/mlpack/methods/ann/layer/log_softmax.hpp index 53fd2f27c0..0e3473e47e 100644 --- a/src/mlpack/methods/ann/layer/log_softmax.hpp +++ b/src/mlpack/methods/ann/layer/log_softmax.hpp @@ -41,6 +41,9 @@ class LogSoftMaxType : public Layer */ LogSoftMaxType(); + //! Clone the LogSoftMaxType object. This handles polymorphism correctly. + LogSoftMaxType* Clone() const { return new LogSoftMaxType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/lookup.hpp b/src/mlpack/methods/ann/layer/lookup.hpp index d433f8459d..291c110c08 100644 --- a/src/mlpack/methods/ann/layer/lookup.hpp +++ b/src/mlpack/methods/ann/layer/lookup.hpp @@ -49,6 +49,9 @@ class LookupType : public Layer */ LookupType(const size_t vocabSize = 0, const size_t embeddingSize = 0); + //! Clone the LookupType object. This handles polymorphism correctly. + LookupType* Clone() const { return new LookupType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/multihead_attention.hpp b/src/mlpack/methods/ann/layer/multihead_attention.hpp index e08dde097f..153add1354 100644 --- a/src/mlpack/methods/ann/layer/multihead_attention.hpp +++ b/src/mlpack/methods/ann/layer/multihead_attention.hpp @@ -84,6 +84,12 @@ class MultiheadAttentionType : public Layer const InputType& attnmask = InputType(), const InputType& keyPaddingMask = InputType()); + //! Clone the MultiheadAttentionType object. This handles polymorphism correctly. + MultiheadAttentionType* Clone() const + { + return new MultiheadAttentionType(*this); + } + /** * Reset the layer parameters. */ diff --git a/src/mlpack/methods/ann/layer/multiply_constant.hpp b/src/mlpack/methods/ann/layer/multiply_constant.hpp index 35ef9c369c..41782230d2 100644 --- a/src/mlpack/methods/ann/layer/multiply_constant.hpp +++ b/src/mlpack/methods/ann/layer/multiply_constant.hpp @@ -37,6 +37,12 @@ class MultiplyConstantType : public Layer //! Create the MultiplyConstant object. MultiplyConstantType(const double scalar = 1.0); + //! Clone the MultiplyConstantType object. This handles polymorphism correctly. + MultiplyConstantType* Clone() const + { + return new MultiplyConstantType(*this); + } + /** * Ordinary feed forward pass of a neural network. Multiply the input with the * specified constant scalar value. diff --git a/src/mlpack/methods/ann/layer/multiply_merge.hpp b/src/mlpack/methods/ann/layer/multiply_merge.hpp index 5bf1d0a7ab..7f96f8d4de 100644 --- a/src/mlpack/methods/ann/layer/multiply_merge.hpp +++ b/src/mlpack/methods/ann/layer/multiply_merge.hpp @@ -51,6 +51,9 @@ class MultiplyMergeType : public Layer //! Destructor to release allocated memory. ~MultiplyMergeType(); + //! Clone the MultiplyMergeType object. This handles polymorphism correctly. + MultiplyMergeType* Clone() const { return new MultiplyMergeType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/noisylinear.hpp b/src/mlpack/methods/ann/layer/noisylinear.hpp index 8a18a5c175..d017b877d2 100644 --- a/src/mlpack/methods/ann/layer/noisylinear.hpp +++ b/src/mlpack/methods/ann/layer/noisylinear.hpp @@ -57,6 +57,9 @@ class NoisyLinearType : public Layer //! Operator= move constructor. NoisyLinearType& operator=(NoisyLinearType&& layer); + //! Clone the NoisyLinearType object. This handles polymorphism correctly. + NoisyLinearType* Clone() const { return new NoisyLinearType(*this); } + //! Reset the layer parameter. void Reset(); diff --git a/src/mlpack/methods/ann/layer/padding.hpp b/src/mlpack/methods/ann/layer/padding.hpp index 19ad7f2daf..91e2879536 100644 --- a/src/mlpack/methods/ann/layer/padding.hpp +++ b/src/mlpack/methods/ann/layer/padding.hpp @@ -47,6 +47,9 @@ class PaddingType : public Layer const size_t padHTop = 0, const size_t padHBottom = 0); + //! Clone the PaddingType object. This handles polymorphism correctly. + PaddingType* Clone() const { return new PaddingType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/parametric_relu.hpp b/src/mlpack/methods/ann/layer/parametric_relu.hpp index 3a0b9dcefa..9a7cb3efaf 100644 --- a/src/mlpack/methods/ann/layer/parametric_relu.hpp +++ b/src/mlpack/methods/ann/layer/parametric_relu.hpp @@ -55,6 +55,9 @@ class PReLUType : public Layer */ PReLUType(const double userAlpha = 0.03); + //! Clone the PReLUType object. This handles polymorphism correctly. + PReLUType* Clone() const { return new PReLUType(*this); } + //! Reset the layer parameter. void Reset(); diff --git a/src/mlpack/methods/ann/layer/positional_encoding.hpp b/src/mlpack/methods/ann/layer/positional_encoding.hpp index d6e5bc9b98..ba3f337a52 100644 --- a/src/mlpack/methods/ann/layer/positional_encoding.hpp +++ b/src/mlpack/methods/ann/layer/positional_encoding.hpp @@ -51,6 +51,8 @@ class PositionalEncodingType : public Layer PositionalEncodingType(const size_t embedDim, const size_t maxSequenceLength); + //! Clone the PositionalEncodingType object. This handles polymorphism correctly. + PositionalEncodingType* Clone() const { return new PositionalEncodingType(*this); } /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/reinforce_normal.hpp b/src/mlpack/methods/ann/layer/reinforce_normal.hpp index bcb53aac09..f6e08cde68 100644 --- a/src/mlpack/methods/ann/layer/reinforce_normal.hpp +++ b/src/mlpack/methods/ann/layer/reinforce_normal.hpp @@ -42,6 +42,9 @@ class ReinforceNormalType : public Layer */ ReinforceNormalType(const double stdev = 1.0); + //! Clone the ReinforceNormalType object. This handles polymorphism correctly. + ReinforceNormalType* Clone() const { return new ReinforceNormalType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/reparametrization.hpp b/src/mlpack/methods/ann/layer/reparametrization.hpp index 068bd526b4..9e201eb477 100644 --- a/src/mlpack/methods/ann/layer/reparametrization.hpp +++ b/src/mlpack/methods/ann/layer/reparametrization.hpp @@ -72,6 +72,15 @@ class ReparametrizationType : public Layer const bool includeKl = true, const double beta = 1); + /** + * Clone the ReparametrizationType object. This handles polymorphism + * correctly. + */ + ReparametrizationType* Clone() const + { + return new ReparametrizationType(*this); + } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/select.hpp b/src/mlpack/methods/ann/layer/select.hpp index 5b53d5795a..9b12fdc12b 100644 --- a/src/mlpack/methods/ann/layer/select.hpp +++ b/src/mlpack/methods/ann/layer/select.hpp @@ -42,6 +42,9 @@ class SelectType : public Layer */ SelectType(const size_t index = 0, const size_t elements = 0); + //! Clone the SelectType object. This handles polymorphism correctly. + SelectType* Clone() const { return new SelectType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/sequential.hpp b/src/mlpack/methods/ann/layer/sequential.hpp index 15c5e6a281..9c01a8766c 100644 --- a/src/mlpack/methods/ann/layer/sequential.hpp +++ b/src/mlpack/methods/ann/layer/sequential.hpp @@ -88,6 +88,9 @@ class SequentialType : public Layer //! Destroy the Sequential object. ~SequentialType(); + //! Clone the SequentialType object. This handles polymorphism correctly. + SequentialType* Clone() const { return new SequentialType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/softmax.hpp b/src/mlpack/methods/ann/layer/softmax.hpp index c6049c5bb7..01fdd8b0f5 100644 --- a/src/mlpack/methods/ann/layer/softmax.hpp +++ b/src/mlpack/methods/ann/layer/softmax.hpp @@ -41,6 +41,9 @@ class SoftmaxType : public Layer //! Create the Softmax object. SoftmaxType(); + //! Clone the SoftmaxType object. This handles polymorphism correctly. + SoftmaxType* Clone() const { return new SoftmaxType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/softmin.hpp b/src/mlpack/methods/ann/layer/softmin.hpp index 693a90251b..cc3c420bf2 100644 --- a/src/mlpack/methods/ann/layer/softmin.hpp +++ b/src/mlpack/methods/ann/layer/softmin.hpp @@ -38,6 +38,9 @@ class SoftminType : public Layer //! Create the Softmin object. SoftminType(); + //! Clone the SoftminType object. This handles polymorphism correctly. + SoftminType* Clone() const { return new SoftminType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/softshrink.hpp b/src/mlpack/methods/ann/layer/softshrink.hpp index ca8fb95f72..ac3f11319c 100644 --- a/src/mlpack/methods/ann/layer/softshrink.hpp +++ b/src/mlpack/methods/ann/layer/softshrink.hpp @@ -62,6 +62,9 @@ class SoftShrinkType : public Layer */ SoftShrinkType(const double lambda = 0.5); + //! Clone the SoftShrinkType object. This handles polymorphism correctly. + SoftShrinkType* Clone() const { return new SoftShrinkType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/spatial_dropout.hpp b/src/mlpack/methods/ann/layer/spatial_dropout.hpp index 7103befcc6..71df98b857 100644 --- a/src/mlpack/methods/ann/layer/spatial_dropout.hpp +++ b/src/mlpack/methods/ann/layer/spatial_dropout.hpp @@ -58,6 +58,9 @@ class SpatialDropoutType : public Layer */ SpatialDropoutType(const size_t size, const double ratio = 0.5); + //! Clone the SpatialDropoutType object. This handles polymorphism correctly. + SpatialDropoutType* Clone() const { return new SpatialDropoutType(*this); } + /** * Ordinary feed forward pass of the SpatialDropout layer. * diff --git a/src/mlpack/methods/ann/layer/subview.hpp b/src/mlpack/methods/ann/layer/subview.hpp index d0a536fa0d..30c397edbd 100644 --- a/src/mlpack/methods/ann/layer/subview.hpp +++ b/src/mlpack/methods/ann/layer/subview.hpp @@ -59,6 +59,9 @@ class SubviewType : public Layer /* Nothing to do here */ } + //! Clone the SubviewType object. This handles polymorphism correctly. + SubviewType* Clone() const { return new SubviewType(*this); } + /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. diff --git a/src/mlpack/methods/ann/layer/virtual_batch_norm.hpp b/src/mlpack/methods/ann/layer/virtual_batch_norm.hpp index 66479090f6..3a0ec9d9ca 100644 --- a/src/mlpack/methods/ann/layer/virtual_batch_norm.hpp +++ b/src/mlpack/methods/ann/layer/virtual_batch_norm.hpp @@ -62,6 +62,12 @@ class VirtualBatchNormType : public Layer const size_t size, const double eps = 1e-8); + //! Clone the VirtualBatchNormType object. This handles polymorphism correctly. + VirtualBatchNormType* Clone() const + { + return new VirtualBatchNormType(*this); + } + /** * Reset the layer parameters. */ diff --git a/src/mlpack/methods/ann/layer/weight_norm.hpp b/src/mlpack/methods/ann/layer/weight_norm.hpp index 590a16074d..ad0ff58cfb 100644 --- a/src/mlpack/methods/ann/layer/weight_norm.hpp +++ b/src/mlpack/methods/ann/layer/weight_norm.hpp @@ -62,6 +62,9 @@ class WeightNormType : public Layer //! Destructor to release allocated memory. ~WeightNormType(); + //! Clone the WeightNormType object. This handles polymorphism correctly. + WeightNormType* Clone() const { return new WeightNormType(*this); } + /** * Reset the layer parameters. */