diff --git a/src/mlpack/methods/ann/layer/add_impl.hpp b/src/mlpack/methods/ann/layer/add_impl.hpp index 8df9a38002..8cd582c5ab 100644 --- a/src/mlpack/methods/ann/layer/add_impl.hpp +++ b/src/mlpack/methods/ann/layer/add_impl.hpp @@ -95,7 +95,7 @@ template void AddType::SetWeights(typename MatType::elem_type* weightPtr) { // Set the weights to wrap the given memory. - weights = MatType(weightPtr, 1, outSize, false, true); + MakeAlias(weights, weightPtr, 1, outSize); } template diff --git a/src/mlpack/methods/ann/layer/linear3d_impl.hpp b/src/mlpack/methods/ann/layer/linear3d_impl.hpp index fde77b31a8..cc4ae74375 100644 --- a/src/mlpack/methods/ann/layer/linear3d_impl.hpp +++ b/src/mlpack/methods/ann/layer/linear3d_impl.hpp @@ -89,11 +89,10 @@ template void Linear3DType::SetWeights( typename MatType::elem_type* weightsPtr) { - weights = MatType(weightsPtr, outSize * this->inputDimensions[0] + outSize, - 1, false, false); - weight = MatType(weightsPtr, outSize, this->inputDimensions[0], false, - false); - bias = MatType(weightsPtr + weight.n_elem, outSize, 1, false, false); + MakeAlias(weights, weightsPtr, outSize * this->inputDimensions[0] + outSize, + 1); + MakeAlias(weight, weightsPtr, outSize, this->inputDimensions[0]); + MakeAlias(bias, weightsPtr + weight.n_elem, outSize, 1); } template diff --git a/src/mlpack/methods/ann/layer/linear_impl.hpp b/src/mlpack/methods/ann/layer/linear_impl.hpp index 2e75efe683..fe7841e791 100644 --- a/src/mlpack/methods/ann/layer/linear_impl.hpp +++ b/src/mlpack/methods/ann/layer/linear_impl.hpp @@ -97,9 +97,9 @@ template void LinearType::SetWeights( typename MatType::elem_type* weightsPtr) { - weights = MatType(weightsPtr, outSize * inSize + outSize, 1, false, false); - weight = MatType(weightsPtr, outSize, inSize, false, false); - bias = MatType(weightsPtr + weight.n_elem, outSize, 1, false, false); + MakeAlias(weights, weightsPtr, outSize * inSize + outSize, 1); + MakeAlias(weight, weightsPtr, outSize, inSize); + MakeAlias(bias, weightsPtr + weight.n_elem, outSize, 1); } template diff --git a/src/mlpack/methods/ann/layer/linear_no_bias_impl.hpp b/src/mlpack/methods/ann/layer/linear_no_bias_impl.hpp index 309fce8803..bc2f18702c 100644 --- a/src/mlpack/methods/ann/layer/linear_no_bias_impl.hpp +++ b/src/mlpack/methods/ann/layer/linear_no_bias_impl.hpp @@ -98,7 +98,7 @@ template void LinearNoBiasType::SetWeights( typename MatType::elem_type* weightsPtr) { - weight = arma::mat(weightsPtr, outSize, inSize, false, false); + MakeAlias(weight, weightsPtr, outSize, inSize); } template diff --git a/src/mlpack/methods/ann/layer/lstm_impl.hpp b/src/mlpack/methods/ann/layer/lstm_impl.hpp index 3c560879ea..41b39e3668 100644 --- a/src/mlpack/methods/ann/layer/lstm_impl.hpp +++ b/src/mlpack/methods/ann/layer/lstm_impl.hpp @@ -98,66 +98,55 @@ void LSTMType::SetWeights( typename MatType::elem_type* weightsPtr) { // Set the weight parameter for the output gate. - input2GateOutputWeight = MatType(weightsPtr, outSize, inSize, - false, false); - input2GateOutputBias = MatType(weightsPtr + input2GateOutputWeight.n_elem, - outSize, 1, false, false); - size_t offset = input2GateOutputWeight.n_elem + input2GateOutputBias.n_elem; + MakeAlias(input2GateOutputWeight, weightsPtr, outSize, inSize); + size_t offset = input2GateOutputWeight.n_elem; + MakeAlias(input2GateOutputBias, weightsPtr + offset, outSize, 1); + offset += input2GateOutputBias.n_elem; // Set the weight parameter for the forget gate. - input2GateForgetWeight = MatType(weightsPtr + offset, outSize, inSize, - false, false); - input2GateForgetBias = MatType(weightsPtr + offset + - input2GateForgetWeight.n_elem, outSize, 1, false, false); - offset += input2GateForgetWeight.n_elem + input2GateForgetBias.n_elem; + MakeAlias(input2GateForgetWeight, weightsPtr + offset, outSize, inSize); + offset += input2GateForgetWeight.n_elem; + MakeAlias(input2GateForgetBias, weightsPtr + offset, outSize, 1); + offset += input2GateForgetBias.n_elem; // Set the weight parameter for the input gate. - input2GateInputWeight = MatType(weightsPtr + offset, outSize, inSize, - false, false); - input2GateInputBias = MatType(weightsPtr + offset + - input2GateInputWeight.n_elem, outSize, 1, false, false); - offset += input2GateInputWeight.n_elem + input2GateInputBias.n_elem; + MakeAlias(input2GateInputWeight, weightsPtr + offset, outSize, inSize); + offset += input2GateInputWeight.n_elem; + MakeAlias(input2GateInputBias, weightsPtr + offset, outSize, 1); + offset += input2GateInputBias.n_elem; // Set the weight parameter for the hidden gate. - input2HiddenWeight = MatType(weightsPtr + offset, outSize, inSize, false, - false); - input2HiddenBias = MatType(weightsPtr + offset + input2HiddenWeight.n_elem, - outSize, 1, false, false); - offset += input2HiddenWeight.n_elem + input2HiddenBias.n_elem; + MakeAlias(input2HiddenWeight, weightsPtr + offset, outSize, inSize); + offset += input2HiddenWeight.n_elem; + MakeAlias(input2HiddenBias, weightsPtr + offset, outSize, 1); + offset += input2HiddenBias.n_elem; // Set the weight parameter for the output multiplication. - output2GateOutputWeight = MatType(weightsPtr + offset, outSize, outSize, - false, false); + MakeAlias(output2GateOutputWeight, weightsPtr + offset, outSize, outSize); offset += output2GateOutputWeight.n_elem; // Set the weight parameter for the output multiplication. - output2GateForgetWeight = MatType(weightsPtr + offset, outSize, outSize, - false, false); + MakeAlias(output2GateForgetWeight, weightsPtr + offset, outSize, outSize); offset += output2GateForgetWeight.n_elem; // Set the weight parameter for the input multiplication. - output2GateInputWeight = MatType(weightsPtr + offset, outSize, outSize, - false, false); + MakeAlias(output2GateInputWeight, weightsPtr + offset, outSize, outSize); offset += output2GateInputWeight.n_elem; // Set the weight parameter for the hidden multiplication. - output2HiddenWeight = MatType(weightsPtr + offset, outSize, outSize, false, - false); + MakeAlias(output2HiddenWeight, weightsPtr + offset, outSize, outSize); offset += output2HiddenWeight.n_elem; // Set the weight parameter for the cell multiplication. - cell2GateOutputWeight = MatType(weightsPtr + offset, outSize, 1, false, - false); + MakeAlias(cell2GateOutputWeight, weightsPtr + offset, outSize, 1); offset += cell2GateOutputWeight.n_elem; // Set the weight parameter for the cell - forget gate multiplication. - cell2GateForgetWeight = MatType(weightsPtr + offset, outSize, 1, false, - false); + MakeAlias(cell2GateForgetWeight, weightsPtr + offset, outSize, 1); offset += cell2GateOutputWeight.n_elem; // Set the weight parameter for the cell - input gate multiplication. - cell2GateInputWeight = MatType(weightsPtr + offset, outSize, 1, false, - false); + MakeAlias(cell2GateInputWeight, weightsPtr + offset, outSize, 1); } // Forward when cellState is not needed. diff --git a/src/mlpack/methods/ann/layer/noisylinear_impl.hpp b/src/mlpack/methods/ann/layer/noisylinear_impl.hpp index 57da526025..4df8685283 100644 --- a/src/mlpack/methods/ann/layer/noisylinear_impl.hpp +++ b/src/mlpack/methods/ann/layer/noisylinear_impl.hpp @@ -77,15 +77,14 @@ template void NoisyLinearType::SetWeights( typename MatType::elem_type* weightsPtr) { - weights = MatType(weightsPtr, 1, (outSize * inSize + outSize) * 2, false, - true); + MakeAlias(weights, weightsPtr, 1, (outSize * inSize + outSize) * 2); - weightMu = MatType(weightsPtr, outSize, inSize, false, true); - biasMu = MatType(weightsPtr + weightMu.n_elem, outSize, 1, false, true); - weightSigma = MatType(weightsPtr + weightMu.n_elem + biasMu.n_elem, - outSize, inSize, false, true); - biasSigma = MatType(weightsPtr + weightMu.n_elem * 2 + biasMu.n_elem, - outSize, 1, false, true); + MakeAlias(weightMu, weightsPtr, outSize, inSize); + MakeAlias(biasMu, weightsPtr + weightMu.n_elem, outSize, 1); + MakeAlias(weightSigma, weightsPtr + weightMu.n_elem + biasMu.n_elem, outSize, + inSize); + MakeAlias(biasSigma, weightsPtr + weightMu.n_elem * 2 + biasMu.n_elem, + outSize, 1); this->ResetNoise(); }