From 99a6ada43f6be93ef85205a07bb14e3508fba050 Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 16:31:19 +0800 Subject: [PATCH 1/2] remove move constructor and assignement, let the compiler generated it(Need to define ARMA_USE_CXX11) --- .../methods/ann/layer/sparse_bias_layer.hpp | 16 +--------------- .../methods/ann/layer/sparse_input_layer.hpp | 17 +---------------- .../methods/ann/layer/sparse_output_layer.hpp | 17 ----------------- 3 files changed, 2 insertions(+), 48 deletions(-) diff --git a/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp b/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp index 2723a98d31..8fc33c378e 100644 --- a/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_bias_layer.hpp @@ -42,21 +42,7 @@ class SparseBiasLayer batchSize(batchSize) { weights.set_size(outSize, 1); - } - - SparseBiasLayer(SparseBiasLayer &&layer) noexcept - { - *this = std::move(layer); - } - - SparseBiasLayer& operator=(SparseBiasLayer &&layer) noexcept - { - outSize = layer.outSize; - batchSize = layer.batchSize; - weights.swap(layer.weights); - - return *this; - } + } /** * Ordinary feed forward pass of a neural network, evaluating the function diff --git a/src/mlpack/methods/ann/layer/sparse_input_layer.hpp b/src/mlpack/methods/ann/layer/sparse_input_layer.hpp index efdb7772b8..9b5f27474a 100644 --- a/src/mlpack/methods/ann/layer/sparse_input_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_input_layer.hpp @@ -47,22 +47,7 @@ class SparseInputLayer lambda(lambda) { weights.set_size(outSize, inSize); - } - - SparseInputLayer(SparseInputLayer &&layer) noexcept - { - *this = std::move(layer); - } - - SparseInputLayer& operator=(SparseInputLayer &&layer) noexcept - { - inSize = layer.inSize; - outSize = layer.outSize; - lambda = layer.lambda; - weights.swap(layer.weights); - - return *this; - } + } /** * Ordinary feed forward pass of a neural network, evaluating the function diff --git a/src/mlpack/methods/ann/layer/sparse_output_layer.hpp b/src/mlpack/methods/ann/layer/sparse_output_layer.hpp index 950081a7ef..ae1597fafb 100644 --- a/src/mlpack/methods/ann/layer/sparse_output_layer.hpp +++ b/src/mlpack/methods/ann/layer/sparse_output_layer.hpp @@ -49,23 +49,6 @@ class SparseOutputLayer weights.set_size(outSize, inSize); } - SparseOutputLayer(SparseOutputLayer &&layer) noexcept - { - *this = std::move(layer); - } - - SparseOutputLayer& operator=(SparseOutputLayer &&layer) noexcept - { - beta = layer.beta; - rho = layer.rho; - lambda = layer.lambda; - inSize = layer.inSize; - outSize = layer.outSize; - weights.swap(layer.weights); - - return *this; - } - /** * Ordinary feed forward pass of a neural network, evaluating the function * f(x) by propagating the activity forward through f. From 32d4badb3adc3b3174ee12618e4db28d7f1bcddd Mon Sep 17 00:00:00 2001 From: stereomatchingkiss Date: Sat, 27 Feb 2016 16:36:57 +0800 Subject: [PATCH 2/2] remove move constructor and assignement, let the compiler generated it.Remember to define ARMA_USE_CXX11 --- src/mlpack/methods/ann/layer/conv_layer.hpp | 22 +--------------- .../methods/ann/layer/dropout_layer.hpp | 18 +------------ src/mlpack/methods/ann/layer/linear_layer.hpp | 14 ---------- src/mlpack/methods/ann/layer/lstm_layer.hpp | 17 +----------- .../layer/multiclass_classification_layer.hpp | 8 ++++++ .../methods/ann/layer/one_hot_layer.hpp | 8 ++++++ .../methods/ann/layer/pooling_layer.hpp | 26 +++++++------------ .../methods/ann/layer/recurrent_layer.hpp | 16 +----------- .../methods/ann/layer/softmax_layer.hpp | 16 +----------- 9 files changed, 30 insertions(+), 115 deletions(-) diff --git a/src/mlpack/methods/ann/layer/conv_layer.hpp b/src/mlpack/methods/ann/layer/conv_layer.hpp index 06f38a8bfc..91c090315d 100644 --- a/src/mlpack/methods/ann/layer/conv_layer.hpp +++ b/src/mlpack/methods/ann/layer/conv_layer.hpp @@ -69,27 +69,7 @@ class ConvLayer { weights.set_size(wfilter, hfilter, inMaps * outMaps); } - - ConvLayer(ConvLayer &&layer) noexcept - { - *this = std::move(layer); - } - - ConvLayer& operator=(ConvLayer &&layer) noexcept - { - wfilter = layer.wfilter; - hfilter = layer.hfilter; - inMaps = layer.inMaps; - outMaps = layer.outMaps; - xStride = layer.xStride; - yStride = layer.yStride; - wPad = layer.wPad; - hPad = layer.hPad; - weights.swap(layer.weights); - - return *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/dropout_layer.hpp b/src/mlpack/methods/ann/layer/dropout_layer.hpp index 4fa46afc8d..c9da7216a0 100644 --- a/src/mlpack/methods/ann/layer/dropout_layer.hpp +++ b/src/mlpack/methods/ann/layer/dropout_layer.hpp @@ -64,23 +64,7 @@ class DropoutLayer rescale(rescale) { // Nothing to do here. - } - - DropoutLayer(DropoutLayer &&layer) noexcept - { - *this = std::move(layer); - } - - DropoutLayer& operator=(DropoutLayer &&layer) noexcept - { - mask.swap(layer.mask); - ratio = layer.ratio; - scale = layer.scale; - deterministic = layer.deterministic; - rescale = layer.rescale; - - return *this; - } + } /** * Ordinary feed forward pass of the dropout layer. diff --git a/src/mlpack/methods/ann/layer/linear_layer.hpp b/src/mlpack/methods/ann/layer/linear_layer.hpp index f059bb302f..1c3a1fa60c 100644 --- a/src/mlpack/methods/ann/layer/linear_layer.hpp +++ b/src/mlpack/methods/ann/layer/linear_layer.hpp @@ -42,20 +42,6 @@ class LinearLayer { weights.set_size(outSize, inSize); } - - LinearLayer(LinearLayer &&layer) noexcept - { - *this = std::move(layer); - } - - LinearLayer& operator=(LinearLayer &&layer) noexcept - { - inSize = layer.inSize; - outSize = layer.outSize; - weights.swap(layer.weights); - - return *this; - } /** * Ordinary feed forward pass of a neural network, evaluating the function diff --git a/src/mlpack/methods/ann/layer/lstm_layer.hpp b/src/mlpack/methods/ann/layer/lstm_layer.hpp index 0ac04e7ec5..ee57456346 100644 --- a/src/mlpack/methods/ann/layer/lstm_layer.hpp +++ b/src/mlpack/methods/ann/layer/lstm_layer.hpp @@ -59,22 +59,7 @@ class LSTMLayer peepholeWeights.set_size(outSize, 3); peepholeDerivatives = arma::zeros(outSize, 3); } - } - - LSTMLayer(LSTMLayer &&layer) noexcept - { - *this = std::move(layer); - } - - LSTMLayer& operator=(LSTMLayer &&layer) noexcept - { - outSize = layer.outSize; - seqLen = layer.seqLen; - - peepholeWeights.swap(layer.peepholeWeights); - - return *this; - } + } /** * Ordinary feed forward pass of a neural network, evaluating the function diff --git a/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp b/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp index f74ac2831a..43f87547c2 100644 --- a/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp +++ b/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp @@ -61,6 +61,14 @@ class MulticlassClassificationLayer { output = inputActivations; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + } }; // class MulticlassClassificationLayer //! Layer traits for the multiclass classification layer. diff --git a/src/mlpack/methods/ann/layer/one_hot_layer.hpp b/src/mlpack/methods/ann/layer/one_hot_layer.hpp index e820632652..a4dc6f4360 100644 --- a/src/mlpack/methods/ann/layer/one_hot_layer.hpp +++ b/src/mlpack/methods/ann/layer/one_hot_layer.hpp @@ -62,6 +62,14 @@ class OneHotLayer inputActivations.max(maxIndex); output(maxIndex) = 1; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + } }; // class OneHotLayer //! Layer traits for the one-hot class classification layer. diff --git a/src/mlpack/methods/ann/layer/pooling_layer.hpp b/src/mlpack/methods/ann/layer/pooling_layer.hpp index fdaefad589..64add9b1d3 100644 --- a/src/mlpack/methods/ann/layer/pooling_layer.hpp +++ b/src/mlpack/methods/ann/layer/pooling_layer.hpp @@ -43,23 +43,7 @@ class PoolingLayer kSize(kSize), pooling(pooling) { // Nothing to do here. - } - - PoolingLayer(PoolingLayer &&layer) noexcept - { - *this = std::move(layer); - } - - PoolingLayer& operator=(PoolingLayer &&layer) noexcept - { - kSize = layer.kSize; - delta.swap(layer.delta); - inputParameter.swap(layer.inputParameter); - outputParameter.swap(layer.outputParameter); - pooling = std::move(layer.pooling); - - return *this; - } + } /** * Ordinary feed forward pass of a neural network, evaluating the function @@ -162,6 +146,14 @@ class PoolingLayer OutputDataType& Delta() const { return delta; } //! Modify the delta. OutputDataType& Delta() { return delta; } + + /** + * Serialize the layer + */ + template + void Serialize(Archive& ar, const unsigned int /* version */) + { + } private: /** diff --git a/src/mlpack/methods/ann/layer/recurrent_layer.hpp b/src/mlpack/methods/ann/layer/recurrent_layer.hpp index 332a659983..729179f7ed 100644 --- a/src/mlpack/methods/ann/layer/recurrent_layer.hpp +++ b/src/mlpack/methods/ann/layer/recurrent_layer.hpp @@ -55,21 +55,7 @@ class RecurrentLayer recurrentParameter(arma::zeros(outSize, 1)) { weights.set_size(outSize, inSize); - } - - RecurrentLayer(RecurrentLayer &&layer) noexcept - { - *this = std::move(layer); - } - - RecurrentLayer& operator=(RecurrentLayer &&layer) noexcept - { - inSize = layer.inSize; - outSize = layer.outSize; - weights.swap(layer.weights); - - return *this; - } + } /** * Ordinary feed forward pass of a neural network, evaluating the function diff --git a/src/mlpack/methods/ann/layer/softmax_layer.hpp b/src/mlpack/methods/ann/layer/softmax_layer.hpp index 12e0146cbc..4bfd27d64e 100644 --- a/src/mlpack/methods/ann/layer/softmax_layer.hpp +++ b/src/mlpack/methods/ann/layer/softmax_layer.hpp @@ -34,21 +34,7 @@ class SoftmaxLayer SoftmaxLayer() { // Nothing to do here. - } - - SoftmaxLayer(SoftmaxLayer &&layer) noexcept - { - *this = std::move(layer); - } - - SoftmaxLayer& operator=(SoftmaxLayer &&layer) noexcept - { - delta.swap(layer.delta); - inputParameter.swap(layer.inputParameter); - outputParameter.swap(layer.outputParameter); - - return *this; - } + } /** * Ordinary feed forward pass of a neural network, evaluating the function