[mlpack-git] master: Alias properly. (45ccf16)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Mon Jul 13 04:05:01 EDT 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/8b2ca720828224607c70d2b539c43aecf8f4ec32...b4659b668021db631b3c8a48e3d735b513706fdc
>---------------------------------------------------------------
commit 45ccf168f9a239c3ea0f4559a8095241f654244e
Author: Ryan Curtin <ryan at ratml.org>
Date: Mon Jul 13 06:53:21 2015 +0000
Alias properly.
>---------------------------------------------------------------
45ccf168f9a239c3ea0f4559a8095241f654244e
src/mlpack/methods/gmm/eigenvalue_ratio_constraint.hpp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/mlpack/methods/gmm/eigenvalue_ratio_constraint.hpp b/src/mlpack/methods/gmm/eigenvalue_ratio_constraint.hpp
index 5c5b2b0..5ca6832 100644
--- a/src/mlpack/methods/gmm/eigenvalue_ratio_constraint.hpp
+++ b/src/mlpack/methods/gmm/eigenvalue_ratio_constraint.hpp
@@ -29,7 +29,8 @@ class EigenvalueRatioConstraint
* be 1. In addition, all other elements should be less than or equal to 1.
*/
EigenvalueRatioConstraint(const arma::vec& ratios) :
- ratios(ratios.memptr(), ratios.n_rows, ratios.n_cols, false) // Alias.
+ // Make an alias of the ratios vector. It will never be modified here.
+ ratios(const_cast<double*>(ratios.memptr()), ratios.n_elem, false)
{
// Check validity of ratios.
if (std::abs(ratios[0] - 1.0) > 1e-20)
@@ -74,7 +75,9 @@ class EigenvalueRatioConstraint
template<typename Archive>
void Serialize(Archive& ar, const unsigned int /* version */)
{
- ar & data::CreateNVP(ratios, "ratios");
+ // Strip the const for the sake of loading/saving. This is the only time it
+ // is modified (other than the constructor).
+ ar & data::CreateNVP(const_cast<arma::vec&>(ratios), "ratios");
}
private:
More information about the mlpack-git
mailing list