diff --git a/src/mlpack/core/boost_backport/detail/bernoulli_details.hpp b/src/mlpack/core/boost_backport/detail/bernoulli_details.hpp index d07d796b1f..b4838ec4cc 100644 --- a/src/mlpack/core/boost_backport/detail/bernoulli_details.hpp +++ b/src/mlpack/core/boost_backport/detail/bernoulli_details.hpp @@ -308,7 +308,7 @@ public: BOOST_MATH_INSTRUMENT_VARIABLE(tn[1]); } - for(std::size_t i = std::max(2, prev_size); i < m; i++) + for(std::size_t i = std::max(2, prev_size); i < m; ++i) { bool overflow_check = false; if(i >= min_overflow_index && (boost::math::tools::max_value() / (i-1) < m_intermediates[1]) ) @@ -317,7 +317,7 @@ public: break; } m_intermediates[1] = m_intermediates[1] * (i-1); - for(std::size_t j = 2; j <= i; j++) + for(std::size_t j = 2; j <= i; ++j) { overflow_check = (i >= min_overflow_index) && ( @@ -360,7 +360,7 @@ public: T power_two(ldexp(T(1), static_cast(2 * old_size))); - for(std::size_t i = old_size; i < m; i++) + for(std::size_t i = old_size; i < m; ++i) { T b(static_cast(i * 2)); // diff --git a/src/mlpack/core/data/load_image_impl.hpp b/src/mlpack/core/data/load_image_impl.hpp index 9dbf96ff73..8cd9b9a2ef 100644 --- a/src/mlpack/core/data/load_image_impl.hpp +++ b/src/mlpack/core/data/load_image_impl.hpp @@ -76,7 +76,7 @@ bool Load(const std::vector& files, info.Width() * info.Height() * info.Channels(), files.size()); tmpMatrix.col(0) = img; - for (size_t i = 1; i < files.size() ; i++) + for (size_t i = 1; i < files.size() ; ++i) { arma::Mat colImg(tmpMatrix.colptr(i), tmpMatrix.n_rows, 1, false, true); diff --git a/src/mlpack/core/data/save_impl.hpp b/src/mlpack/core/data/save_impl.hpp index 0aba733ee1..4aecee9db7 100644 --- a/src/mlpack/core/data/save_impl.hpp +++ b/src/mlpack/core/data/save_impl.hpp @@ -158,10 +158,14 @@ bool Save(const std::string& filename, { arma::Mat tmp = trans(matrix); +#ifdef ARMA_USE_HDF5 // We can't save with streams for HDF5. const bool success = (saveType == arma::hdf5_binary) ? tmp.quiet_save(filename, saveType) : tmp.quiet_save(stream, saveType); +#else + const bool success = tmp.quiet_save(stream, saveType); +#endif if (!success) { Timer::Stop("saving_data"); @@ -175,10 +179,14 @@ bool Save(const std::string& filename, } else { +#ifdef ARMA_USE_HDF5 // We can't save with streams for HDF5. const bool success = (saveType == arma::hdf5_binary) ? matrix.quiet_save(filename, saveType) : matrix.quiet_save(stream, saveType); +#else + const bool success = matrix.quiet_save(stream, saveType); +#endif if (!success) { Timer::Stop("saving_data"); @@ -439,7 +447,7 @@ bool Save(const std::vector& files, arma::Mat img; bool status = true; - for (size_t i = 0; i < files.size() ; i++) + for (size_t i = 0; i < files.size() ; ++i) { arma::Mat colImg(matrix.colptr(i), matrix.n_rows, 1, false, true); diff --git a/src/mlpack/core/data/string_encoding_impl.hpp b/src/mlpack/core/data/string_encoding_impl.hpp index f18bd776c8..41b3b5c2c4 100644 --- a/src/mlpack/core/data/string_encoding_impl.hpp +++ b/src/mlpack/core/data/string_encoding_impl.hpp @@ -110,7 +110,7 @@ EncodeHelper(const std::vector& input, policy.Reset(); // The first pass adds the extracted tokens to the dictionary. - for (size_t i = 0; i < input.size(); i++) + for (size_t i = 0; i < input.size(); ++i) { boost::string_view strView(input[i]); auto token = tokenizer(strView); @@ -141,7 +141,7 @@ EncodeHelper(const std::vector& input, policy.InitMatrix(output, input.size(), numColumns, dictionary.Size()); // The second pass writes the encoded values to the output. - for (size_t i = 0; i < input.size(); i++) + for (size_t i = 0; i < input.size(); ++i) { boost::string_view strView(input[i]); auto token = tokenizer(strView); @@ -170,7 +170,7 @@ EncodeHelper(const std::vector& input, // The loop below extracts the tokens and writes the encoded values // at once. - for (size_t i = 0; i < input.size(); i++) + for (size_t i = 0; i < input.size(); ++i) { boost::string_view strView(input[i]); auto token = tokenizer(strView); diff --git a/src/mlpack/core/dists/discrete_distribution.cpp b/src/mlpack/core/dists/discrete_distribution.cpp index 042f5788a3..2fd64aea73 100644 --- a/src/mlpack/core/dists/discrete_distribution.cpp +++ b/src/mlpack/core/dists/discrete_distribution.cpp @@ -66,7 +66,7 @@ void DiscreteDistribution::Train(const arma::mat& observations) const size_t dimensions = probabilities.size(); // Clear the old probabilities. - for (size_t i = 0; i < dimensions; i++) + for (size_t i = 0; i < dimensions; ++i) probabilities[i].zeros(); // Iterate over all the probabilities in each dimension. @@ -121,13 +121,13 @@ void DiscreteDistribution::Train(const arma::mat& observations, size_t dimensions = probabilities.size(); // Clear the old probabilities. - for (size_t i = 0; i < dimensions; i++) + for (size_t i = 0; i < dimensions; ++i) probabilities[i].zeros(); // Ensure that the observation is within the bounds. for (size_t r = 0; r < observations.n_cols; r++) { - for (size_t i = 0; i < dimensions; i++) + for (size_t i = 0; i < dimensions; ++i) { // Add the probability of each observation. The addition of 0.5 // to the observation is to turn the default flooring operation diff --git a/src/mlpack/core/dists/discrete_distribution.hpp b/src/mlpack/core/dists/discrete_distribution.hpp index 6bdbe3390b..29dd99e1b7 100644 --- a/src/mlpack/core/dists/discrete_distribution.hpp +++ b/src/mlpack/core/dists/discrete_distribution.hpp @@ -75,7 +75,7 @@ class DiscreteDistribution */ DiscreteDistribution(const arma::Col& numObservations) { - for (size_t i = 0; i < numObservations.n_elem; i++) + for (size_t i = 0; i < numObservations.n_elem; ++i) { const size_t numObs = size_t(numObservations[i]); if (numObs <= 0) @@ -97,7 +97,7 @@ class DiscreteDistribution */ DiscreteDistribution(const std::vector& probabilities) { - for (size_t i = 0; i < probabilities.size(); i++) + for (size_t i = 0; i < probabilities.size(); ++i) { arma::vec temp = probabilities[i]; double sum = accu(temp); @@ -179,7 +179,7 @@ class DiscreteDistribution void Probability(const arma::mat& x, arma::vec& probabilities) const { probabilities.set_size(x.n_cols); - for (size_t i = 0; i < x.n_cols; i++) + for (size_t i = 0; i < x.n_cols; ++i) probabilities(i) = Probability(x.unsafe_col(i)); } @@ -194,7 +194,7 @@ class DiscreteDistribution void LogProbability(const arma::mat& x, arma::vec& logProbabilities) const { logProbabilities.set_size(x.n_cols); - for (size_t i = 0; i < x.n_cols; i++) + for (size_t i = 0; i < x.n_cols; ++i) logProbabilities(i) = log(Probability(x.unsafe_col(i))); } diff --git a/src/mlpack/core/dists/gamma_distribution.cpp b/src/mlpack/core/dists/gamma_distribution.cpp index f5764d3fc1..bf93106fff 100644 --- a/src/mlpack/core/dists/gamma_distribution.cpp +++ b/src/mlpack/core/dists/gamma_distribution.cpp @@ -78,7 +78,7 @@ void GammaDistribution::Train(const arma::mat& rdata, arma::vec meanxVec(rdata.n_rows, arma::fill::zeros); arma::vec logMeanxVec(rdata.n_rows, arma::fill::zeros); - for (size_t i = 0; i < rdata.n_cols; i++) + for (size_t i = 0; i < rdata.n_cols; ++i) { meanLogxVec += probabilities(i) * arma::log(rdata.col(i)); meanxVec += probabilities(i) * rdata.col(i); diff --git a/src/mlpack/core/dists/gaussian_distribution.cpp b/src/mlpack/core/dists/gaussian_distribution.cpp index d3cf8c959c..8d4f496012 100644 --- a/src/mlpack/core/dists/gaussian_distribution.cpp +++ b/src/mlpack/core/dists/gaussian_distribution.cpp @@ -19,7 +19,7 @@ using namespace mlpack::distribution; GaussianDistribution::GaussianDistribution(const arma::vec& mean, const arma::mat& covariance) - : mean(mean) + : mean(mean), logDetCov(0.0) { Covariance(covariance); } @@ -102,14 +102,14 @@ void GaussianDistribution::Train(const arma::mat& observations) } // Calculate the mean. - for (size_t i = 0; i < observations.n_cols; i++) + for (size_t i = 0; i < observations.n_cols; ++i) mean += observations.col(i); // Normalize the mean. mean /= observations.n_cols; // Now calculate the covariance. - for (size_t i = 0; i < observations.n_cols; i++) + for (size_t i = 0; i < observations.n_cols; ++i) { arma::vec obsNoMean = observations.col(i) - mean; covariance += obsNoMean * trans(obsNoMean); @@ -150,7 +150,7 @@ void GaussianDistribution::Train(const arma::mat& observations, // First calculate the mean, and save the sum of all the probabilities for // later normalization. - for (size_t i = 0; i < observations.n_cols; i++) + for (size_t i = 0; i < observations.n_cols; ++i) { mean += probabilities[i] * observations.col(i); sumProb += probabilities[i]; @@ -170,7 +170,7 @@ void GaussianDistribution::Train(const arma::mat& observations, mean /= sumProb; // Now find the covariance. - for (size_t i = 0; i < observations.n_cols; i++) + for (size_t i = 0; i < observations.n_cols; ++i) { arma::vec obsNoMean = observations.col(i) - mean; covariance += probabilities[i] * (obsNoMean * trans(obsNoMean)); diff --git a/src/mlpack/core/dists/gaussian_distribution.hpp b/src/mlpack/core/dists/gaussian_distribution.hpp index bfa892b7d7..0e470052b5 100644 --- a/src/mlpack/core/dists/gaussian_distribution.hpp +++ b/src/mlpack/core/dists/gaussian_distribution.hpp @@ -91,7 +91,7 @@ class GaussianDistribution void Probability(const arma::mat& x, arma::vec& probabilities) const { probabilities.set_size(x.n_cols); - for (size_t i = 0; i < x.n_cols; i++) + for (size_t i = 0; i < x.n_cols; ++i) { probabilities(i) = Probability(x.unsafe_col(i)); } @@ -116,7 +116,7 @@ class GaussianDistribution // so that later we are referencing columns, not rows -- that is faster. const arma::mat rhs = -0.5 * invCov * diffs; arma::vec logExponents(diffs.n_cols); // We will now fill this. - for (size_t i = 0; i < diffs.n_cols; i++) + for (size_t i = 0; i < diffs.n_cols; ++i) logExponents(i) = accu(diffs.unsafe_col(i) % rhs.unsafe_col(i)); logProbabilities = -0.5 * x.n_rows * log2pi - 0.5 * logDetCov + diff --git a/src/mlpack/core/dists/laplace_distribution.cpp b/src/mlpack/core/dists/laplace_distribution.cpp index e1b30f3320..58ef9ba842 100644 --- a/src/mlpack/core/dists/laplace_distribution.cpp +++ b/src/mlpack/core/dists/laplace_distribution.cpp @@ -37,7 +37,7 @@ void LaplaceDistribution::Probability(const arma::mat& x, arma::vec& probabilities) const { probabilities.set_size(x.n_cols); - for (size_t i = 0; i < x.n_cols; i++) + for (size_t i = 0; i < x.n_cols; ++i) { probabilities(i) = Probability(x.unsafe_col(i)); } diff --git a/src/mlpack/core/dists/laplace_distribution.hpp b/src/mlpack/core/dists/laplace_distribution.hpp index a92358f715..91b746f382 100644 --- a/src/mlpack/core/dists/laplace_distribution.hpp +++ b/src/mlpack/core/dists/laplace_distribution.hpp @@ -113,7 +113,7 @@ class LaplaceDistribution void LogProbability(const arma::mat& x, arma::vec& logProbabilities) const { logProbabilities.set_size(x.n_cols); - for (size_t i = 0; i < x.n_cols; i++) + for (size_t i = 0; i < x.n_cols; ++i) { logProbabilities(i) = LogProbability(x.unsafe_col(i)); } diff --git a/src/mlpack/core/math/lin_alg.cpp b/src/mlpack/core/math/lin_alg.cpp index 12506bf1ae..11f4f93fcd 100644 --- a/src/mlpack/core/math/lin_alg.cpp +++ b/src/mlpack/core/math/lin_alg.cpp @@ -23,7 +23,7 @@ using namespace math; */ void mlpack::math::VectorPower(arma::vec& vec, const double power) { - for (size_t i = 0; i < vec.n_elem; i++) + for (size_t i = 0; i < vec.n_elem; ++i) { if (std::abs(vec(i)) > 1e-12) vec(i) = (vec(i) > 0) ? std::pow(vec(i), (double) power) : @@ -197,9 +197,9 @@ void mlpack::math::Svec(const arma::mat& input, arma::vec& output) output.zeros(n2bar); size_t idx = 0; - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; ++i) { - for (size_t j = i; j < n; j++) + for (size_t j = i; j < n; ++j) { if (i == j) output(idx++) = input(i, j); @@ -238,9 +238,9 @@ void mlpack::math::Smat(const arma::vec& input, arma::mat& output) output.zeros(n, n); size_t idx = 0; - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; ++i) { - for (size_t j = i; j < n; j++) + for (size_t j = i; j < n; ++j) { if (i == j) output(i, j) = input(idx++); @@ -259,11 +259,11 @@ void mlpack::math::SymKronId(const arma::mat& A, arma::mat& op) op.zeros(n2bar, n2bar); size_t idx = 0; - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; ++i) { - for (size_t j = i; j < n; j++) + for (size_t j = i; j < n; ++j) { - for (size_t k = 0; k < n; k++) + for (size_t k = 0; k < n; ++k) { op(idx, SvecIndex(k, j, n)) += ((k == j) ? 1. : M_SQRT1_2) * A(i, k); diff --git a/src/mlpack/core/math/random.hpp b/src/mlpack/core/math/random.hpp index 5697463f90..6a90cf75c1 100644 --- a/src/mlpack/core/math/random.hpp +++ b/src/mlpack/core/math/random.hpp @@ -158,7 +158,7 @@ inline void ObtainDistinctSamples(const size_t loInclusive, samples.zeros(samplesRangeSize); - for (size_t i = 0; i < maxNumSamples; i++) + for (size_t i = 0; i < maxNumSamples; ++i) samples [ (size_t) math::RandInt(samplesRangeSize) ]++; distinctSamples = arma::find(samples > 0); @@ -169,7 +169,7 @@ inline void ObtainDistinctSamples(const size_t loInclusive, else { distinctSamples.set_size(samplesRangeSize); - for (size_t i = 0; i < samplesRangeSize; i++) + for (size_t i = 0; i < samplesRangeSize; ++i) distinctSamples[i] = loInclusive + i; } } diff --git a/src/mlpack/core/metrics/lmetric_impl.hpp b/src/mlpack/core/metrics/lmetric_impl.hpp index 75dd3876e7..6c2b3703ae 100644 --- a/src/mlpack/core/metrics/lmetric_impl.hpp +++ b/src/mlpack/core/metrics/lmetric_impl.hpp @@ -26,7 +26,7 @@ typename VecTypeA::elem_type LMetric::Evaluate( const VecTypeB& b) { typename VecTypeA::elem_type sum = 0; - for (size_t i = 0; i < a.n_elem; i++) + for (size_t i = 0; i < a.n_elem; ++i) sum += std::pow(fabs(a[i] - b[i]), Power); if (!TakeRoot) // The compiler should optimize this correctly at compile-time. @@ -81,7 +81,7 @@ typename VecTypeA::elem_type LMetric<3, true>::Evaluate( const VecTypeB& b) { typename VecTypeA::elem_type sum = 0; - for (size_t i = 0; i < a.n_elem; i++) + for (size_t i = 0; i < a.n_elem; ++i) sum += std::pow(fabs(a[i] - b[i]), 3.0); return std::pow(arma::accu(arma::pow(arma::abs(a - b), 3.0)), 1.0 / 3.0); diff --git a/src/mlpack/core/tree/address.hpp b/src/mlpack/core/tree/address.hpp index 869b575852..26caa76e5b 100644 --- a/src/mlpack/core/tree/address.hpp +++ b/src/mlpack/core/tree/address.hpp @@ -79,7 +79,7 @@ void PointToAddress(AddressType& address, const VecType& point) assert(point.n_elem == address.n_elem); assert(address.n_elem > 0); - for (size_t i = 0; i < point.n_elem; i++) + for (size_t i = 0; i < point.n_elem; ++i) { int e; VecElemType normalizedVal = std::frexp(point(i), &e); @@ -128,8 +128,8 @@ void PointToAddress(AddressType& address, const VecType& point) // Interleave the bits of the new representation across all the elements // in the address vector. - for (size_t i = 0; i < order; i++) - for (size_t j = 0; j < point.n_elem; j++) + for (size_t i = 0; i < order; ++i) + for (size_t j = 0; j < point.n_elem; ++j) { size_t bit = (i * point.n_elem + j) % order; size_t row = (i * point.n_elem + j) / order; @@ -176,8 +176,8 @@ void AddressToPoint(VecType& point, const AddressType& address) // Calculate the number of bits for the mantissa. const int numMantBits = order - numExpBits - 1; - for (size_t i = 0; i < order; i++) - for (size_t j = 0; j < address.n_elem; j++) + for (size_t i = 0; i < order; ++i) + for (size_t j = 0; j < address.n_elem; ++j) { size_t bit = (i * address.n_elem + j) % order; size_t row = (i * address.n_elem + j) / order; @@ -186,7 +186,7 @@ void AddressToPoint(VecType& point, const AddressType& address) (order - 1 - i)); } - for (size_t i = 0; i < rearrangedAddress.n_elem; i++) + for (size_t i = 0; i < rearrangedAddress.n_elem; ++i) { bool sgn = rearrangedAddress(i) & ((AddressElemType) 1 << (order - 1)); @@ -238,7 +238,7 @@ int CompareAddresses(const AddressType1& addr1, const AddressType2& addr2) assert(addr1.n_elem == addr2.n_elem); - for (size_t i = 0; i < addr1.n_elem; i++) + for (size_t i = 0; i < addr1.n_elem; ++i) { if (addr1[i] < addr2[i]) return -1; diff --git a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp index f3deba46fa..d531d7dc72 100644 --- a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp @@ -72,7 +72,7 @@ BinarySpaceTree( { // Initialize oldFromNew correctly. oldFromNew.resize(data.n_cols); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) oldFromNew[i] = i; // Fill with unharmed indices. // Now do the actual splitting. @@ -106,7 +106,7 @@ BinarySpaceTree( { // Initialize the oldFromNew vector correctly. oldFromNew.resize(data.n_cols); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) oldFromNew[i] = i; // Fill with unharmed indices. // Now do the actual splitting. @@ -118,7 +118,7 @@ BinarySpaceTree( // Map the newFromOld indices correctly. newFromOld.resize(data.n_cols); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) newFromOld[oldFromNew[i]] = i; } @@ -169,7 +169,7 @@ BinarySpaceTree( { // Initialize oldFromNew correctly. oldFromNew.resize(dataset->n_cols); - for (size_t i = 0; i < dataset->n_cols; i++) + for (size_t i = 0; i < dataset->n_cols; ++i) oldFromNew[i] = i; // Fill with unharmed indices. // Now do the actual splitting. @@ -203,7 +203,7 @@ BinarySpaceTree( { // Initialize the oldFromNew vector correctly. oldFromNew.resize(dataset->n_cols); - for (size_t i = 0; i < dataset->n_cols; i++) + for (size_t i = 0; i < dataset->n_cols; ++i) oldFromNew[i] = i; // Fill with unharmed indices. // Now do the actual splitting. @@ -215,7 +215,7 @@ BinarySpaceTree( // Map the newFromOld indices correctly. newFromOld.resize(dataset->n_cols); - for (size_t i = 0; i < dataset->n_cols; i++) + for (size_t i = 0; i < dataset->n_cols; ++i) newFromOld[oldFromNew[i]] = i; } @@ -315,7 +315,7 @@ BinarySpaceTree( // Map the newFromOld indices correctly. newFromOld.resize(dataset->n_cols); - for (size_t i = 0; i < dataset->n_cols; i++) + for (size_t i = 0; i < dataset->n_cols; ++i) newFromOld[oldFromNew[i]] = i; } diff --git a/src/mlpack/core/tree/binary_space_tree/rp_tree_max_split_impl.hpp b/src/mlpack/core/tree/binary_space_tree/rp_tree_max_split_impl.hpp index 6fea3d9dfe..514dc69a41 100644 --- a/src/mlpack/core/tree/binary_space_tree/rp_tree_max_split_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/rp_tree_max_split_impl.hpp @@ -54,7 +54,7 @@ bool RPTreeMaxSplit::GetSplitVal( arma::Col values(samples.n_elem); // Find the median of scalar products of the samples and the normal vector. - for (size_t k = 0; k < samples.n_elem; k++) + for (size_t k = 0; k < samples.n_elem; ++k) values[k] = arma::dot(data.col(samples[k]), direction); const ElemType maximum = arma::max(values); diff --git a/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split_impl.hpp b/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split_impl.hpp index 522de1cad4..1ec2cbacb5 100644 --- a/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/rp_tree_mean_split_impl.hpp @@ -70,8 +70,8 @@ GetAveragePointDistance( { ElemType dist = 0; - for (size_t i = 0; i < samples.n_elem; i++) - for (size_t j = i + 1; j < samples.n_elem; j++) + for (size_t i = 0; i < samples.n_elem; ++i) + for (size_t j = i + 1; j < samples.n_elem; ++j) dist += metric::SquaredEuclideanDistance::Evaluate(data.col(samples[i]), data.col(samples[j])); @@ -89,7 +89,7 @@ bool RPTreeMeanSplit::GetDotMedian( { arma::Col values(samples.n_elem); - for (size_t k = 0; k < samples.n_elem; k++) + for (size_t k = 0; k < samples.n_elem; ++k) values[k] = arma::dot(data.col(samples[k]), direction); const ElemType maximum = arma::max(values); @@ -118,7 +118,7 @@ bool RPTreeMeanSplit::GetMeanMedian( arma::Col tmp(data.n_rows); - for (size_t k = 0; k < samples.n_elem; k++) + for (size_t k = 0; k < samples.n_elem; ++k) { tmp = data.col(samples[k]); tmp -= mean; diff --git a/src/mlpack/core/tree/binary_space_tree/ub_tree_split_impl.hpp b/src/mlpack/core/tree/binary_space_tree/ub_tree_split_impl.hpp index 5e0422581b..6ea00e9732 100644 --- a/src/mlpack/core/tree/binary_space_tree/ub_tree_split_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/ub_tree_split_impl.hpp @@ -132,7 +132,7 @@ bool UBTreeSplit::SplitNode(BoundType& bound, } // Set the minimum and the maximum addresses. - for (size_t k = 0; k < bound.Dim(); k++) + for (size_t k = 0; k < bound.Dim(); ++k) { bound.LoAddress()[k] = addresses[begin].first[k]; bound.HiAddress()[k] = addresses[begin + count - 1].first[k]; @@ -148,7 +148,7 @@ void UBTreeSplit::InitializeAddresses(const MatType& data) addresses.resize(data.n_cols); // Calculate all addresses. - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { addresses[i].first.zeros(data.n_rows); bound::addr::PointToAddress(addresses[i].first, data.col(i)); @@ -169,13 +169,13 @@ size_t UBTreeSplit::PerformSplit( std::vector newFromOld(data.n_cols); std::vector oldFromNew(data.n_cols); - for (size_t i = 0; i < splitInfo.addresses->size(); i++) + for (size_t i = 0; i < splitInfo.addresses->size(); ++i) { newFromOld[i] = i; oldFromNew[i] = i; } - for (size_t i = 0; i < splitInfo.addresses->size(); i++) + for (size_t i = 0; i < splitInfo.addresses->size(); ++i) { size_t index = (*splitInfo.addresses)[i].second; size_t oldI = oldFromNew[i]; @@ -210,10 +210,10 @@ size_t UBTreeSplit::PerformSplit( { std::vector newFromOld(data.n_cols); - for (size_t i = 0; i < splitInfo.addresses->size(); i++) + for (size_t i = 0; i < splitInfo.addresses->size(); ++i) newFromOld[i] = i; - for (size_t i = 0; i < splitInfo.addresses->size(); i++) + for (size_t i = 0; i < splitInfo.addresses->size(); ++i) { size_t index = (*splitInfo.addresses)[i].second; size_t oldI = oldFromNew[i]; diff --git a/src/mlpack/core/tree/binary_space_tree/vantage_point_split_impl.hpp b/src/mlpack/core/tree/binary_space_tree/vantage_point_split_impl.hpp index 6dc149bcc1..2c390288c0 100644 --- a/src/mlpack/core/tree/binary_space_tree/vantage_point_split_impl.hpp +++ b/src/mlpack/core/tree/binary_space_tree/vantage_point_split_impl.hpp @@ -55,7 +55,7 @@ SelectVantagePoint(const MetricType& metric, const MatType& data, arma::uvec samples; // Evaluate each candidate - for (size_t i = 0; i < vantagePointCandidates.n_elem; i++) + for (size_t i = 0; i < vantagePointCandidates.n_elem; ++i) { // Get no more than min(MaxNumSamples, count) random samples math::ObtainDistinctSamples(begin, begin + count, MaxNumSamples, samples); @@ -64,7 +64,7 @@ SelectVantagePoint(const MetricType& metric, const MatType& data, // candidate using these random samples. distances.set_size(samples.n_elem); - for (size_t j = 0; j < samples.n_elem; j++) + for (size_t j = 0; j < samples.n_elem; ++j) distances[j] = metric.Evaluate(data.col(vantagePointCandidates[i]), data.col(samples[j])); diff --git a/src/mlpack/core/tree/cellbound_impl.hpp b/src/mlpack/core/tree/cellbound_impl.hpp index 5c960e7d89..d3bc6fbde2 100644 --- a/src/mlpack/core/tree/cellbound_impl.hpp +++ b/src/mlpack/core/tree/cellbound_impl.hpp @@ -51,7 +51,7 @@ inline CellBound::CellBound(const size_t dimension) : hiAddress(dim), minWidth(0) { - for (size_t k = 0; k < dim ; k++) + for (size_t k = 0; k < dim ; ++k) { loAddress[k] = std::numeric_limits::max(); hiAddress[k] = 0; @@ -74,7 +74,7 @@ inline CellBound::CellBound( minWidth(other.MinWidth()) { // Copy other bounds over. - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) bounds[i] = other.bounds[i]; } @@ -87,9 +87,13 @@ inline CellBound< ElemType>& CellBound::operator=( const CellBound& other) { - if (dim != other.Dim()) + if (this == &other) + return *this; + + if (dim != other.Dim()) { // Reallocation is necessary. + delete[] bounds; dim = other.Dim(); bounds = new math::RangeType[dim]; @@ -102,7 +106,7 @@ inline CellBound< hiAddress = other.hiAddress; // Now copy each of the bound values. - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) bounds[i] = other.bounds[i]; minWidth = other.MinWidth(); @@ -147,7 +151,7 @@ inline CellBound::~CellBound() template inline void CellBound::Clear() { - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; ++k) { bounds[k] = math::RangeType(); @@ -171,7 +175,7 @@ inline void CellBound::Center( if (!(center.n_elem == dim)) center.set_size(dim); - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) center(i) = bounds[i].Mid(); } @@ -187,17 +191,17 @@ void CellBound::AddBound( assert(loCorner.n_elem == dim); assert(hiCorner.n_elem == dim); - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; ++k) { loBound(k, numBounds) = std::numeric_limits::max(); hiBound(k, numBounds) = std::numeric_limits::lowest(); } - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { size_t k = 0; // Check if the point is contained in the hyperrectangle. - for (k = 0; k < dim; k++) + for (k = 0; k < dim; ++k) if (data(k, i) < loCorner[k] || data(k, i) > hiCorner[k]) break; @@ -205,14 +209,14 @@ void CellBound::AddBound( continue; // The point is not contained in the hyperrectangle. // Shrink the bound. - for (k = 0; k < dim; k++) + for (k = 0; k < dim; ++k) { loBound(k, numBounds) = std::min(loBound(k, numBounds), data(k, i)); hiBound(k, numBounds) = std::max(hiBound(k, numBounds), data(k, i)); } } - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; ++k) if (loBound(k, numBounds) > hiBound(k, numBounds)) return; // The hyperrectangle does not contain points. @@ -415,7 +419,7 @@ void CellBound::UpdateAddressBounds(const MatType& data) // If the high address is equal to the lower address. if (row == hiAddress.n_elem) { - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { loBound(i, 0) = bounds[i].Lo(); hiBound(i, 0) = bounds[i].Hi(); @@ -434,7 +438,7 @@ void CellBound::UpdateAddressBounds(const MatType& data) if ((row == hiAddress.n_elem - 1) && (bit == order - 1)) { // If the addresses differ in the last bit. - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { loBound(i, 0) = bounds[i].Lo(); hiBound(i, 0) = bounds[i].Hi(); @@ -454,7 +458,7 @@ void CellBound::UpdateAddressBounds(const MatType& data) if (numBounds == 0) { // I think this should never happen. - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { loBound(i, 0) = bounds[i].Lo(); hiBound(i, 0) = bounds[i].Hi(); @@ -479,7 +483,7 @@ inline ElemType CellBound::MinDistance( ElemType lower, higher; - for (size_t i = 0; i < numBounds; i++) + for (size_t i = 0; i < numBounds; ++i) { ElemType sum = 0; @@ -549,8 +553,8 @@ ElemType CellBound::MinDistance(const CellBound& other) ElemType lower, higher; - for (size_t i = 0; i < numBounds; i++) - for (size_t j = 0; j < other.numBounds; j++) + for (size_t i = 0; i < numBounds; ++i) + for (size_t j = 0; j < other.numBounds; ++j) { ElemType sum = 0; for (size_t d = 0; d < dim; d++) @@ -616,7 +620,7 @@ inline ElemType CellBound::MaxDistance( Log::Assert(point.n_elem == dim); - for (size_t i = 0; i < numBounds; i++) + for (size_t i = 0; i < numBounds; ++i) { ElemType sum = 0; for (size_t d = 0; d < dim; d++) @@ -663,8 +667,8 @@ inline ElemType CellBound::MaxDistance( Log::Assert(dim == other.dim); ElemType v; - for (size_t i = 0; i < numBounds; i++) - for (size_t j = 0; j < other.numBounds; j++) + for (size_t i = 0; i < numBounds; ++i) + for (size_t j = 0; j < other.numBounds; ++j) { ElemType sum = 0; for (size_t d = 0; d < dim; d++) @@ -714,8 +718,8 @@ CellBound::RangeDistance( ElemType v1, v2, vLo, vHi; - for (size_t i = 0; i < numBounds; i++) - for (size_t j = 0; j < other.numBounds; j++) + for (size_t i = 0; i < numBounds; ++i) + for (size_t j = 0; j < other.numBounds; ++j) { ElemType loSum = 0; ElemType hiSum = 0; @@ -793,7 +797,7 @@ CellBound::RangeDistance( Log::Assert(point.n_elem == dim); ElemType v1, v2, vLo, vHi; - for (size_t i = 0; i < numBounds; i++) + for (size_t i = 0; i < numBounds; ++i) { ElemType loSum = 0; ElemType hiSum = 0; @@ -876,7 +880,7 @@ CellBound::operator|=(const MatType& data) arma::Col maxs(arma::max(data, 1)); minWidth = std::numeric_limits::max(); - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { bounds[i] |= math::RangeType(mins[i], maxs[i]); const ElemType width = bounds[i].Width(); @@ -902,7 +906,7 @@ CellBound::operator|=(const CellBound& other) assert(other.dim == dim); minWidth = std::numeric_limits::max(); - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { bounds[i] |= other.bounds[i]; const ElemType width = bounds[i].Width(); @@ -918,7 +922,7 @@ CellBound::operator|=(const CellBound& other) if (loAddress[0] > hiAddress[0]) { - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { loBound(i, 0) = bounds[i].Lo(); hiBound(i, 0) = bounds[i].Hi(); @@ -936,7 +940,7 @@ template inline bool CellBound::Contains( const VecType& point) const { - for (size_t i = 0; i < point.n_elem; i++) + for (size_t i = 0; i < point.n_elem; ++i) { if (!bounds[i].Contains(point(i))) return false; diff --git a/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp b/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp index 52cee2d198..1231850e85 100644 --- a/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp +++ b/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp @@ -30,7 +30,7 @@ CosineTree::CosineTree(const arma::mat& dataset) : l2NormsSquared.zeros(numColumns); // Set indices and calculate squared norms of the columns. - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { indices[i] = i; double l2Norm = arma::norm(dataset.col(i), 2); @@ -60,7 +60,7 @@ CosineTree::CosineTree(CosineTree& parentNode, l2NormsSquared.zeros(numColumns); // Set indices and squared norms of the columns. - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { indices[i] = parentNode.indices[subIndices[i]]; l2NormsSquared(i) = parentNode.l2NormsSquared(subIndices[i]); @@ -381,7 +381,7 @@ void CosineTree::ModifiedGramSchmidt(CosineNodeQueue& treeQueue, // For every vector in the current basis, remove its projection from the // centroid. - for ( ; i != treeQueue.end(); i++) + for ( ; i != treeQueue.end(); ++i) { currentNode = *i; @@ -430,7 +430,7 @@ double CosineTree::MonteCarloError(CosineTree* node, projectionSize = treeQueue.size(); // For each sample, calculate the weighted projection onto the current basis. - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { // Initialize projection as a vector of zeros. arma::vec projection; @@ -441,7 +441,7 @@ double CosineTree::MonteCarloError(CosineTree* node, size_t k = 0; // Compute the projection of the sampled vector onto the existing subspace. - for ( ; j != treeQueue.end(); j++, k++) + for ( ; j != treeQueue.end(); ++j, ++k) { currentNode = *j; @@ -497,7 +497,7 @@ void CosineTree::ConstructBasis(CosineNodeQueue& treeQueue) // Transfer basis vectors from the queue to the basis matrix. size_t j = 0; - for ( ; i != treeQueue.end(); i++, j++) + for ( ; i != treeQueue.end(); ++i, ++j) { currentNode = *i; basis.col(j) = currentNode->BasisVector(); @@ -528,7 +528,7 @@ void CosineTree::CosineNodeSplit() // We deviate from the paper here and use < instead of <= in order to handle // the edge case where cosineMax == cosineMin, and force there to be at least // one point in the right node. - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { if (cosineMax - cosines(i) < cosines(i) - cosineMin) leftIndices.push_back(i); @@ -550,7 +550,7 @@ void CosineTree::ColumnSamplesLS(std::vector& sampledIndices, cDistribution.zeros(numColumns + 1); // Calculate cumulative length-squared distribution for the node. - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { cDistribution(i + 1) = cDistribution(i) + (l2NormsSquared(i) / frobNormSquared); @@ -560,7 +560,7 @@ void CosineTree::ColumnSamplesLS(std::vector& sampledIndices, sampledIndices.resize(numSamples); probabilities.zeros(numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { // Generate a random value for sampling. double randValue = arma::randu(); @@ -586,7 +586,7 @@ size_t CosineTree::ColumnSampleLS() cDistribution.zeros(numColumns + 1); // Calculate cumulative length-squared distribution for the node. - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { cDistribution(i + 1) = cDistribution(i) + (l2NormsSquared(i) / frobNormSquared); @@ -633,7 +633,7 @@ void CosineTree::CalculateCosines(arma::vec& cosines) // Initialize cosine vector as a vector of zeros. cosines.zeros(numColumns); - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { // If norm is zero, store cosine value as zero. Else, calculate cosine value // between two vectors. @@ -656,7 +656,7 @@ void CosineTree::CalculateCentroid() centroid.zeros(dataset->n_rows); // Calculate centroid of columns in the node. - for (size_t i = 0; i < numColumns; i++) + for (size_t i = 0; i < numColumns; ++i) { centroid += dataset->col(indices[i]); } diff --git a/src/mlpack/core/tree/hrectbound_impl.hpp b/src/mlpack/core/tree/hrectbound_impl.hpp index 109d1d33b2..f8166e00aa 100644 --- a/src/mlpack/core/tree/hrectbound_impl.hpp +++ b/src/mlpack/core/tree/hrectbound_impl.hpp @@ -52,7 +52,7 @@ inline HRectBound::HRectBound( minWidth(other.MinWidth()) { // Copy other bounds over. - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) bounds[i] = other[i]; } @@ -65,6 +65,9 @@ inline HRectBound< ElemType>& HRectBound::operator=(const HRectBound& other) { + if (this == &other) + return *this; + if (dim != other.Dim()) { // Reallocation is necessary. @@ -76,7 +79,7 @@ inline HRectBound< } // Now copy each of the bound values. - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) bounds[i] = other[i]; minWidth = other.MinWidth(); @@ -116,7 +119,7 @@ inline HRectBound::~HRectBound() template inline void HRectBound::Clear() { - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) bounds[i] = math::RangeType(); minWidth = 0; } @@ -134,7 +137,7 @@ inline void HRectBound::Center( if (!(center.n_elem == dim)) center.set_size(dim); - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) center(i) = bounds[i].Mid(); } @@ -516,7 +519,7 @@ HRectBound::operator|=(const MatType& data) arma::Col maxs(max(data, 1)); minWidth = std::numeric_limits::max(); - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { bounds[i] |= math::RangeType(mins[i], maxs[i]); const ElemType width = bounds[i].Width(); @@ -537,7 +540,7 @@ HRectBound::operator|=(const HRectBound& other) assert(other.dim == dim); minWidth = std::numeric_limits::max(); - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { bounds[i] |= other.bounds[i]; const ElemType width = bounds[i].Width(); @@ -556,7 +559,7 @@ template inline bool HRectBound::Contains( const VecType& point) const { - for (size_t i = 0; i < point.n_elem; i++) + for (size_t i = 0; i < point.n_elem; ++i) { if (!bounds[i].Contains(point(i))) return false; @@ -572,7 +575,7 @@ template inline bool HRectBound::Contains( const HRectBound& bound) const { - for (size_t i = 0; i < dim; i++) + for (size_t i = 0; i < dim; ++i) { const math::RangeType& r_a = bounds[i]; const math::RangeType& r_b = bound.bounds[i]; @@ -594,7 +597,7 @@ HRectBound::operator&(const HRectBound& bound) const { HRectBound result(dim); - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; ++k) { result[k].Lo() = std::max(bounds[k].Lo(), bound.bounds[k].Lo()); result[k].Hi() = std::min(bounds[k].Hi(), bound.bounds[k].Hi()); @@ -609,7 +612,7 @@ template inline HRectBound& HRectBound::operator&=(const HRectBound& bound) { - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; ++k) { bounds[k].Lo() = std::max(bounds[k].Lo(), bound.bounds[k].Lo()); bounds[k].Hi() = std::min(bounds[k].Hi(), bound.bounds[k].Hi()); @@ -626,7 +629,7 @@ inline ElemType HRectBound::Overlap( { ElemType volume = 1.0; - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; ++k) { ElemType lo = std::max(bounds[k].Lo(), bound.bounds[k].Lo()); ElemType hi = std::min(bounds[k].Hi(), bound.bounds[k].Hi()); diff --git a/src/mlpack/core/tree/octree/octree_impl.hpp b/src/mlpack/core/tree/octree/octree_impl.hpp index 917663e209..80e95aeb3b 100644 --- a/src/mlpack/core/tree/octree/octree_impl.hpp +++ b/src/mlpack/core/tree/octree/octree_impl.hpp @@ -141,7 +141,7 @@ Octree::Octree( // Map the newFromOld indices correctly. newFromOld.resize(this->dataset->n_cols); - for (size_t i = 0; i < this->dataset->n_cols; i++) + for (size_t i = 0; i < this->dataset->n_cols; ++i) newFromOld[oldFromNew[i]] = i; } @@ -267,7 +267,7 @@ Octree::Octree( // Map the newFromOld indices correctly. newFromOld.resize(this->dataset->n_cols); - for (size_t i = 0; i < this->dataset->n_cols; i++) + for (size_t i = 0; i < this->dataset->n_cols; ++i) newFromOld[oldFromNew[i]] = i; } diff --git a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp index 6d4efb422e..24604fe67c 100644 --- a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp @@ -163,7 +163,7 @@ CalculateValue(const VecType& pt, // Calculate the number of bits for the mantissa. const int numMantBits = order - numExpBits - 1; - for (size_t i = 0; i < pt.n_rows; i++) + for (size_t i = 0; i < pt.n_rows; ++i) { int e; VecElemType normalizedVal = std::frexp(pt(i), &e); @@ -216,7 +216,7 @@ CalculateValue(const VecType& pt, { HilbertElemType P = Q - 1; - for (size_t i = 0; i < pt.n_rows; i++) + for (size_t i = 0; i < pt.n_rows; ++i) { if (res(i) & Q) // Invert. res(0) ^= P; @@ -230,7 +230,7 @@ CalculateValue(const VecType& pt, } // Gray encode. - for (size_t i = 1; i < pt.n_rows; i++) + for (size_t i = 1; i < pt.n_rows; ++i) res(i) ^= res(i - 1); HilbertElemType t = 0; @@ -240,14 +240,14 @@ CalculateValue(const VecType& pt, if (res(pt.n_rows - 1) & Q) t ^= Q - 1; - for (size_t i = 0; i < pt.n_rows; i++) + for (size_t i = 0; i < pt.n_rows; ++i) res(i) ^= t; // We should rearrange bits in order to compare two Hilbert values faster. arma::Col rearrangedResult(pt.n_rows, arma::fill::zeros); - for (size_t i = 0; i < order; i++) - for (size_t j = 0; j < pt.n_rows; j++) + for (size_t i = 0; i < order; ++i) + for (size_t j = 0; j < pt.n_rows; ++j) { size_t bit = (i * pt.n_rows + j) % order; size_t row = (i * pt.n_rows + j) / order; @@ -264,7 +264,7 @@ int DiscreteHilbertValue:: CompareValues(const arma::Col& value1, const arma::Col& value2) { - for (size_t i = 0; i < value1.n_rows; i++) + for (size_t i = 0; i < value1.n_rows; ++i) { if (value1(i) > value2(i)) return 1; @@ -355,7 +355,7 @@ InsertPoint(TreeType *node, if (node->IsLeaf()) { // Find an appropriate place. - for (i = 0; i < numValues; i++) + for (i = 0; i < numValues; ++i) if (CompareValues(localHilbertValues->col(i), *valueToInsert) > 0) break; @@ -436,6 +436,12 @@ template DiscreteHilbertValue& DiscreteHilbertValue:: operator=(const DiscreteHilbertValue& val) { + if (this == &val) + return *this; + + if (ownsLocalHilbertValues) + delete localHilbertValues; + localHilbertValues = const_cast* > (val.LocalHilbertValues()); ownsLocalHilbertValues = false; @@ -473,19 +479,19 @@ void DiscreteHilbertValue::RedistributeHilbertValues( { // We need to update the local dataset if points were redistributed. size_t numPoints = 0; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) numPoints += parent->Child(i).NumPoints(); // Copy the local Hilbert values. arma::Mat tmp(localHilbertValues->n_rows, numPoints); size_t iPoint = 0; - for (size_t i = firstSibling; i<= lastSibling; i++) + for (size_t i = firstSibling; i<= lastSibling; ++i) { DiscreteHilbertValue &value = parent->Child(i).AuxiliaryInfo().HilbertValue(); - for (size_t j = 0; j < value.NumValues(); j++) + for (size_t j = 0; j < value.NumValues(); ++j) { tmp.col(iPoint) = value.LocalHilbertValues()->col(j); iPoint++; @@ -496,12 +502,12 @@ void DiscreteHilbertValue::RedistributeHilbertValues( iPoint = 0; // Redistribute the Hilbert values. - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) { DiscreteHilbertValue &value = parent->Child(i).AuxiliaryInfo().HilbertValue(); - for (size_t j = 0; j < parent->Child(i).NumPoints(); j++) + for (size_t j = 0; j < parent->Child(i).NumPoints(); ++j) { value.LocalHilbertValues()->col(j) = tmp.col(iPoint); iPoint++; diff --git a/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp b/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp index b507c8ef7c..d1b2827b6b 100644 --- a/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp @@ -105,7 +105,7 @@ DualTreeTraverser::Traverse(RectangleTree& queryNode, // We sort the children of the reference node by their scores. std::vector nodesAndScores(referenceNode.NumChildren()); - for (size_t i = 0; i < referenceNode.NumChildren(); i++) + for (size_t i = 0; i < referenceNode.NumChildren(); ++i) { rule.TraversalInfo() = traversalInfo; nodesAndScores[i].node = &(referenceNode.Child(i)); @@ -116,7 +116,7 @@ DualTreeTraverser::Traverse(RectangleTree& queryNode, std::sort(nodesAndScores.begin(), nodesAndScores.end(), nodeComparator); numScores += nodesAndScores.size(); - for (size_t i = 0; i < nodesAndScores.size(); i++) + for (size_t i = 0; i < nodesAndScores.size(); ++i) { rule.TraversalInfo() = nodesAndScores[i].travInfo; if (rule.Rescore(queryNode, *(nodesAndScores[i].node), @@ -136,11 +136,11 @@ DualTreeTraverser::Traverse(RectangleTree& queryNode, // We need to traverse down both the reference and the query trees. // We loop through all of the query nodes, and for each of them, we // loop through the reference nodes to see where we need to descend. - for (size_t j = 0; j < queryNode.NumChildren(); j++) + for (size_t j = 0; j < queryNode.NumChildren(); ++j) { // We sort the children of the reference node by their scores. std::vector nodesAndScores(referenceNode.NumChildren()); - for (size_t i = 0; i < referenceNode.NumChildren(); i++) + for (size_t i = 0; i < referenceNode.NumChildren(); ++i) { rule.TraversalInfo() = traversalInfo; nodesAndScores[i].node = &(referenceNode.Child(i)); @@ -151,7 +151,7 @@ DualTreeTraverser::Traverse(RectangleTree& queryNode, std::sort(nodesAndScores.begin(), nodesAndScores.end(), nodeComparator); numScores += nodesAndScores.size(); - for (size_t i = 0; i < nodesAndScores.size(); i++) + for (size_t i = 0; i < nodesAndScores.size(); ++i) { rule.TraversalInfo() = nodesAndScores[i].travInfo; if (rule.Rescore(queryNode.Child(j), *(nodesAndScores[i].node), diff --git a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_auxiliary_information_impl.hpp b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_auxiliary_information_impl.hpp index 30f7deba50..cea8808356 100644 --- a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_auxiliary_information_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_auxiliary_information_impl.hpp @@ -128,7 +128,7 @@ HandlePointDeletion(TreeType* node, const size_t localIndex) // Update the largest Hilbert value. hilbertValue.DeletePoint(node, localIndex); - for (size_t i = localIndex + 1; localIndex < node->NumPoints(); i++) + for (size_t i = localIndex + 1; localIndex < node->NumPoints(); ++i) node->Point(i - 1) = node->Point(i); node->NumPoints()--; @@ -143,7 +143,7 @@ HandleNodeRemoval(TreeType* node, const size_t nodeIndex) // Update the largest Hilbert value. hilbertValue.RemoveNode(node, nodeIndex); - for (size_t i = nodeIndex + 1; nodeIndex < node->NumChildren(); i++) + for (size_t i = nodeIndex + 1; nodeIndex < node->NumChildren(); ++i) node->children[i - 1] = node->children[i]; node->NumChildren()--; diff --git a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp index 15366feb8c..18223c2275 100644 --- a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp @@ -76,7 +76,6 @@ void HilbertRTreeSplit::SplitLeafNode(TreeType* tree, firstSibling = (lastSibling > splitOrder ? lastSibling - splitOrder : 0); assert(lastSibling - firstSibling <= splitOrder); - assert(firstSibling >= 0); assert(lastSibling < parent->NumChildren()); // Redistribute the points among (splitOrder + 1) cooperating siblings evenly. @@ -141,7 +140,6 @@ SplitNonLeafNode(TreeType* tree, std::vector& relevels) lastSibling - splitOrder : 0); assert(lastSibling - firstSibling <= splitOrder); - assert(firstSibling >= 0); assert(lastSibling < parent->NumChildren()); // Redistribute children among (splitOrder + 1) cooperating siblings evenly. @@ -203,7 +201,6 @@ bool HilbertRTreeSplit::FindCooperatingSiblings( } assert(lastSibling - firstSibling <= splitOrder - 1); - assert(firstSibling >= 0); assert(lastSibling < parent->NumChildren()); return true; @@ -218,7 +215,7 @@ RedistributeNodesEvenly(const TreeType *parent, size_t numChildren = 0; size_t numChildrenPerNode, numRestChildren; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) numChildren += parent->Child(i).NumChildren(); numChildrenPerNode = numChildren / (lastSibling - firstSibling + 1); @@ -228,9 +225,9 @@ RedistributeNodesEvenly(const TreeType *parent, // Copy children's children in order to redistribute them. size_t iChild = 0; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) { - for (size_t j = 0; j < parent->Child(i).NumChildren(); j++) + for (size_t j = 0; j < parent->Child(i).NumChildren(); ++j) { children[iChild] = parent->Child(i).children[j]; iChild++; @@ -238,14 +235,14 @@ RedistributeNodesEvenly(const TreeType *parent, } iChild = 0; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) { // Since we redistribute children of a sibling we should recalculate the // bound. parent->Child(i).Bound().Clear(); parent->Child(i).numDescendants = 0; - for (size_t j = 0; j < numChildrenPerNode; j++) + for (size_t j = 0; j < numChildrenPerNode; ++j) { parent->Child(i).Bound() |= children[iChild]->Bound(); parent->Child(i).numDescendants += children[iChild]->numDescendants; @@ -286,7 +283,7 @@ RedistributePointsEvenly(TreeType* parent, size_t numPoints = 0; size_t numPointsPerNode, numRestPoints; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) numPoints += parent->Child(i).NumPoints(); numPointsPerNode = numPoints / (lastSibling - firstSibling + 1); @@ -296,21 +293,21 @@ RedistributePointsEvenly(TreeType* parent, // Copy children's points in order to redistribute them. size_t iPoint = 0; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) { - for (size_t j = 0; j < parent->Child(i).NumPoints(); j++) + for (size_t j = 0; j < parent->Child(i).NumPoints(); ++j) points[iPoint++] = parent->Child(i).Point(j); } iPoint = 0; - for (size_t i = firstSibling; i <= lastSibling; i++) + for (size_t i = firstSibling; i <= lastSibling; ++i) { // Since we redistribute points of a sibling we should recalculate the // bound. parent->Child(i).Bound().Clear(); size_t j; - for (j = 0; j < numPointsPerNode; j++) + for (j = 0; j < numPointsPerNode; ++j) { parent->Child(i).Bound() |= parent->Dataset().col(points[iPoint]); parent->Child(i).Point(j) = points[iPoint]; diff --git a/src/mlpack/core/tree/rectangle_tree/minimal_coverage_sweep_impl.hpp b/src/mlpack/core/tree/rectangle_tree/minimal_coverage_sweep_impl.hpp index 158cb9a676..86f22739ea 100644 --- a/src/mlpack/core/tree/rectangle_tree/minimal_coverage_sweep_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/minimal_coverage_sweep_impl.hpp @@ -30,7 +30,7 @@ SweepNonLeafNode(const size_t axis, std::vector> sorted(node->NumChildren()); - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { sorted[i].first = SplitPolicy::Bound(node->Child(i))[axis].Hi(); sorted[i].second = i; @@ -66,10 +66,10 @@ SweepNonLeafNode(const size_t axis, BoundType bound2(node->Bound().Dim()); // Find bounds of two resulting nodes. - for (size_t i = 0; i < splitPointer; i++) + for (size_t i = 0; i < splitPointer; ++i) bound1 |= node->Child(sorted[i].second).Bound(); - for (size_t i = splitPointer; i < node->NumChildren(); i++) + for (size_t i = splitPointer; i < node->NumChildren(); ++i) bound2 |= node->Child(sorted[i].second).Bound(); @@ -96,7 +96,7 @@ SweepLeafNode(const size_t axis, sorted.resize(node->Count()); - for (size_t i = 0; i < node->NumPoints(); i++) + for (size_t i = 0; i < node->NumPoints(); ++i) { sorted[i].first = node->Dataset().col(node->Point(i))[axis]; sorted[i].second = i; @@ -122,10 +122,10 @@ SweepLeafNode(const size_t axis, BoundType bound2(node->Bound().Dim()); // Find bounds of two resulting nodes. - for (size_t i = 0; i < splitPointer; i++) + for (size_t i = 0; i < splitPointer; ++i) bound1 |= node->Dataset().col(node->Point(sorted[i].second)); - for (size_t i = splitPointer; i < node->NumChildren(); i++) + for (size_t i = splitPointer; i < node->NumChildren(); ++i) bound2 |= node->Dataset().col(node->Point(sorted[i].second)); // Evaluate the cost of the split i.e. calculate the total coverage @@ -145,7 +145,7 @@ CheckNonLeafSweep(const TreeType* node, size_t numTreeTwoChildren = 0; // Calculate the number of children in the resulting nodes. - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { const TreeType& child = node->Child(i); int policy = SplitPolicy::GetSplitPolicy(child, cutAxis, cut); @@ -178,7 +178,7 @@ CheckLeafSweep(const TreeType* node, size_t numTreeTwoPoints = 0; // Calculate the number of points in the resulting nodes. - for (size_t i = 0; i < node->NumPoints(); i++) + for (size_t i = 0; i < node->NumPoints(); ++i) { if (node->Dataset().col(node->Point(i))[cutAxis] <= cut) numTreeOnePoints++; diff --git a/src/mlpack/core/tree/rectangle_tree/minimal_splits_number_sweep_impl.hpp b/src/mlpack/core/tree/rectangle_tree/minimal_splits_number_sweep_impl.hpp index b099f2bd9d..aa2a382a86 100644 --- a/src/mlpack/core/tree/rectangle_tree/minimal_splits_number_sweep_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/minimal_splits_number_sweep_impl.hpp @@ -29,7 +29,7 @@ size_t MinimalSplitsNumberSweep::SweepNonLeafNode( std::vector> sorted(node->NumChildren()); - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { sorted[i].first = SplitPolicy::Bound(node->Child(i))[axis].Hi(); sorted[i].second = i; @@ -46,14 +46,14 @@ size_t MinimalSplitsNumberSweep::SweepNonLeafNode( size_t minCost = SIZE_MAX; // Find a split with the minimal cost. - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { size_t numTreeOneChildren = 0; size_t numTreeTwoChildren = 0; size_t numSplits = 0; // Calculate the number of splits. - for (size_t j = 0; j < node->NumChildren(); j++) + for (size_t j = 0; j < node->NumChildren(); ++j) { const TreeType& child = node->Child(j); int policy = SplitPolicy::GetSplitPolicy(child, axis, sorted[i].first); diff --git a/src/mlpack/core/tree/rectangle_tree/r_plus_plus_tree_auxiliary_information_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_plus_plus_tree_auxiliary_information_impl.hpp index 97562f240d..d046d27fe3 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_plus_plus_tree_auxiliary_information_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_plus_plus_tree_auxiliary_information_impl.hpp @@ -35,7 +35,7 @@ RPlusPlusTreeAuxiliaryInformation(const TreeType* tree) : // Initialize the maximum bounding rectangle if the node is the root if (!tree->Parent()) { - for (size_t k = 0; k < outerBound.Dim(); k++) + for (size_t k = 0; k < outerBound.Dim(); ++k) { outerBound[k].Lo() = std::numeric_limits::lowest(); outerBound[k].Hi() = std::numeric_limits::max(); diff --git a/src/mlpack/core/tree/rectangle_tree/r_plus_tree_descent_heuristic_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_plus_tree_descent_heuristic_impl.hpp index 17be73b153..d10460afc2 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_plus_tree_descent_heuristic_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_plus_tree_descent_heuristic_impl.hpp @@ -45,14 +45,14 @@ size_t RPlusTreeDescentHeuristic::ChooseDescentNode(TreeType* node, success = true; - for (size_t j = 0; j < node->NumChildren(); j++) + for (size_t j = 0; j < node->NumChildren(); ++j) { if (j == bestIndex) continue; success = false; // Two nodes overlap if and only if there are no dimension in which // they do not overlap each other. - for (size_t k = 0; k < node->Bound().Dim(); k++) + for (size_t k = 0; k < node->Bound().Dim(); ++k) { if (bound[k].Lo() >= node->Child(j).Bound()[k].Hi() || node->Child(j).Bound()[k].Lo() >= bound[k].Hi()) diff --git a/src/mlpack/core/tree/rectangle_tree/r_plus_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_plus_tree_split_impl.hpp index 80899159bf..0ce62e3514 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_plus_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_plus_tree_split_impl.hpp @@ -100,7 +100,7 @@ SplitLeafNode(TreeType* tree, std::vector& relevels) TreeType* parent = tree->Parent(); size_t i = 0; while (parent->children[i] != tree) - i++; + ++i; assert(i < parent->NumChildren()); @@ -170,7 +170,7 @@ SplitNonLeafNode(TreeType* tree, std::vector& relevels) TreeType* parent = tree->Parent(); size_t i = 0; while (parent->children[i] != tree) - i++; + ++i; assert(i < parent->NumChildren()); @@ -216,7 +216,7 @@ void RPlusTreeSplit::SplitLeafNodeAlongPartition( } // Insert points into the corresponding subtree. - for (size_t i = 0; i < tree->NumPoints(); i++) + for (size_t i = 0; i < tree->NumPoints(); ++i) { if (tree->Dataset().col(tree->Point(i))[cutAxis] <= cut) { @@ -254,7 +254,7 @@ void RPlusTreeSplit::SplitNonLeafNodeAlongPartition( tree->AuxiliaryInfo().SplitAuxiliaryInfo(treeOne, treeTwo, cutAxis, cut); // Insert children into the corresponding subtree. - for (size_t i = 0; i < tree->NumChildren(); i++) + for (size_t i = 0; i < tree->NumChildren(); ++i) { TreeType* child = tree->children[i]; int policy = SplitPolicyType::GetSplitPolicy(*child, cutAxis, cut); @@ -313,7 +313,7 @@ AddFakeNodes(const TreeType* tree, TreeType* emptyTree) size_t numDescendantNodes = tree->TreeDepth() - 1; TreeType* node = emptyTree; - for (size_t i = 0; i < numDescendantNodes; i++) + for (size_t i = 0; i < numDescendantNodes; ++i) { TreeType* child = new TreeType(node); node->children[node->NumChildren()++] = child; @@ -342,7 +342,7 @@ PartitionNode(const TreeType* node, size_t& minCutAxis, minCutAxis = node->Bound().Dim(); // Find the sweep with a minimal cost. - for (size_t k = 0; k < node->Bound().Dim(); k++) + for (size_t k = 0; k < node->Bound().Dim(); ++k) { typename TreeType::ElemType cut; SweepCostType cost; diff --git a/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp index 0ec42929da..fa8e6c1e60 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp @@ -35,16 +35,16 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( // If its children are leaf nodes, use minimum overlap to choose. size_t bestIndex = 0; - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { ElemType sc = 0; - for (size_t j = 0; j < node->NumChildren(); j++) + for (size_t j = 0; j < node->NumChildren(); ++j) { if (j != i) { ElemType overlap = 1.0; ElemType newOverlap = 1.0; - for (size_t k = 0; k < node->Bound().Dim(); k++) + for (size_t k = 0; k < node->Bound().Dim(); ++k) { ElemType newHigh = std::max(node->Dataset().col(point)[k], node->Child(i).Bound()[k].Hi()); @@ -89,7 +89,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( if (tiedOne) { // If the first heuristic was tied, we need to eliminate garbage values. - for (size_t i = 0; i < scores.size(); i++) + for (size_t i = 0; i < scores.size(); ++i) scores[i] = std::numeric_limits::max(); } @@ -98,13 +98,13 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( size_t bestIndex = 0; bool tied = false; - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { if (!tiedOne || originalScores[i] == origMinScore) { ElemType v1 = 1.0; ElemType v2 = 1.0; - for (size_t j = 0; j < node->Bound().Dim(); j++) + for (size_t j = 0; j < node->Bound().Dim(); ++j) { v1 *= node->Child(i).Bound()[j].Width(); v2 *= node->Child(i).Bound()[j].Contains( @@ -136,7 +136,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( // We break ties by choosing the smallest bound. ElemType minVol = std::numeric_limits::max(); bestIndex = 0; - for (size_t i = 0; i < scores.size(); i++) + for (size_t i = 0; i < scores.size(); ++i) { if (scores[i] == minScore) { @@ -173,11 +173,11 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( size_t bestIndex = 0; bool tied = false; - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { ElemType v1 = 1.0; ElemType v2 = 1.0; - for (size_t j = 0; j < node->Child(i).Bound().Dim(); j++) + for (size_t j = 0; j < node->Child(i).Bound().Dim(); ++j) { v1 *= node->Child(i).Bound()[j].Width(); v2 *= node->Child(i).Bound()[j].Contains(insertedNode->Bound()[j]) ? @@ -209,7 +209,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode( // We break ties by choosing the smallest bound. ElemType minVol = std::numeric_limits::max(); bestIndex = 0; - for (size_t i = 0; i < scores.size(); i++) + for (size_t i = 0; i < scores.size(); ++i) { if (scores[i] == minScore) { diff --git a/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp index c46abea67c..539315b149 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp @@ -50,7 +50,7 @@ size_t RStarTreeSplit::ReinsertPoints(TreeType* tree, std::vector> sorted(tree->Count()); arma::Col center; tree->Bound().Center(center); - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Metric().Evaluate(center, tree->Dataset().col(tree->Point(i))); @@ -60,7 +60,7 @@ size_t RStarTreeSplit::ReinsertPoints(TreeType* tree, std::sort(sorted.begin(), sorted.end(), PairComp); // Remove the points furthest from the center of the node. - for (size_t i = 0; i < p; i++) + for (size_t i = 0; i < p; ++i) root->DeletePoint(sorted[sorted.size() - 1 - i].second, relevels); // Now reinsert the points, but reverse the order---insert the closest to @@ -94,7 +94,7 @@ void RStarTreeSplit::PickLeafSplit(TreeType* tree, /** * Check each dimension, to find which dimension is best to split on. */ - for (size_t j = 0; j < tree->Bound().Dim(); j++) + for (size_t j = 0; j < tree->Bound().Dim(); ++j) { ElemType axisScore = 0.0; @@ -111,7 +111,7 @@ void RStarTreeSplit::PickLeafSplit(TreeType* tree, arma::Col margins(numPossibleSplits, arma::fill::zeros); arma::Col overlaps(numPossibleSplits, arma::fill::zeros); - for (size_t i = 0; i < numPossibleSplits; i++) + for (size_t i = 0; i < numPossibleSplits; ++i) { // The ith arrangement is obtained by placing the first // tree->MinLeafSize() + i points in one rectangle and the rest in @@ -130,7 +130,7 @@ void RStarTreeSplit::PickLeafSplit(TreeType* tree, areas[i] = bound1.Volume() + bound2.Volume(); overlaps[i] = bound1.Overlap(bound2); - for (size_t k = 0; k < bound1.Dim(); k++) + for (size_t k = 0; k < bound1.Dim(); ++k) margins[i] += bound1[k].Width() + bound2[k].Width(); axisScore += margins[i]; @@ -145,7 +145,7 @@ void RStarTreeSplit::PickLeafSplit(TreeType* tree, size_t areaIndex = 0; bool tiedOnOverlap = false; - for (size_t i = 1; i < areas.n_elem; i++) + for (size_t i = 1; i < areas.n_elem; ++i) { if (overlaps[i] < overlaps[overlapIndex]) { @@ -198,7 +198,7 @@ void RStarTreeSplit::SplitLeafNode(TreeType *tree, std::vector& relevels) * dimension to prepare for reinsertion of points into the new nodes. */ std::vector> sorted(tree->Count()); - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Dataset().col(tree->Point(i))[bestAxis]; sorted[i].second = tree->Point(i); @@ -232,7 +232,7 @@ void RStarTreeSplit::SplitLeafNode(TreeType *tree, std::vector& relevels) tree->bound.Clear(); // Insert the points into the appropriate tree. - for (size_t i = 0; i < numPoints; i++) + for (size_t i = 0; i < numPoints; ++i) { if (i < bestIndex + tree->MinLeafSize()) treeOne->InsertPoint(sorted[i].second); @@ -289,7 +289,7 @@ bool RStarTreeSplit::SplitNonLeafNode( /** * Check over each dimension to see which is best to use for splitting. */ - for (size_t j = 0; j < tree->Bound().Dim(); j++) + for (size_t j = 0; j < tree->Bound().Dim(); ++j) { ElemType axisLoScore = 0.0; ElemType axisHiScore = 0.0; @@ -298,7 +298,7 @@ bool RStarTreeSplit::SplitNonLeafNode( // bound. arma::Col loDimValues(tree->NumChildren()); arma::Col hiDimValues(tree->NumChildren()); - for (size_t i = 0; i < tree->NumChildren(); i++) + for (size_t i = 0; i < tree->NumChildren(); ++i) { loDimValues[i] = tree->Child(i).Bound()[j].Lo(); hiDimValues[i] = tree->Child(i).Bound()[j].Hi(); @@ -347,7 +347,7 @@ bool RStarTreeSplit::SplitNonLeafNode( overlaps[2 * i + 1] = hb1.Overlap(hb2); // Now calculate margins for each. - for (size_t k = 0; k < lb1.Dim(); k++) + for (size_t k = 0; k < lb1.Dim(); ++k) { margins[2 * i] += lb1[k].Width() + lb2[k].Width(); margins[2 * i + 1] += hb1[k].Width() + hb2[k].Width(); @@ -381,7 +381,7 @@ bool RStarTreeSplit::SplitNonLeafNode( // Find the best possible split (and whether it is on the low values or // high values of the bounds). - for (size_t i = 1; i < numPossibleSplits; i++) + for (size_t i = 1; i < numPossibleSplits; ++i) { // Check bounds. if (overlaps[2 * i + indexOffset] < overlaps[overlapIndex]) @@ -458,12 +458,12 @@ bool RStarTreeSplit::SplitNonLeafNode( // We have to update the children of treeOne so that they record the correct // parent. - for (size_t i = 0; i < treeOne->NumChildren(); i++) + for (size_t i = 0; i < treeOne->NumChildren(); ++i) treeOne->children[i]->Parent() = treeOne; } // Update the children of treeTwo to have the correct parent. - for (size_t i = 0; i < treeTwo->NumChildren(); i++) + for (size_t i = 0; i < treeTwo->NumChildren(); ++i) treeTwo->children[i]->Parent() = treeTwo; // If we have overflowed hte parent's children, then we need to split that diff --git a/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp index e6249c5777..8f73de9fbc 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp @@ -29,11 +29,11 @@ inline size_t RTreeDescentHeuristic::ChooseDescentNode(const TreeType* node, int bestIndex = 0; ElemType bestVol = 0.0; - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { ElemType v1 = 1.0; ElemType v2 = 1.0; - for (size_t j = 0; j < node->Child(i).Bound().Dim(); j++) + for (size_t j = 0; j < node->Child(i).Bound().Dim(); ++j) { v1 *= node->Child(i).Bound()[j].Width(); v2 *= node->Child(i).Bound()[j].Contains(node->Dataset().col(point)[j]) ? @@ -73,11 +73,11 @@ inline size_t RTreeDescentHeuristic::ChooseDescentNode( int bestIndex = 0; ElemType bestVol = 0.0; - for (size_t i = 0; i < node->NumChildren(); i++) + for (size_t i = 0; i < node->NumChildren(); ++i) { ElemType v1 = 1.0; ElemType v2 = 1.0; - for (size_t j = 0; j < node->Child(i).Bound().Dim(); j++) + for (size_t j = 0; j < node->Child(i).Bound().Dim(); ++j) { v1 *= node->Child(i).Bound()[j].Width(); v2 *= node->Child(i).Bound()[j].Contains(insertedNode->Bound()[j]) ? diff --git a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp index 77a9467d95..6819d0700d 100644 --- a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp @@ -130,7 +130,7 @@ bool RTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) par->children[index] = treeOne; par->children[par->NumChildren()++] = treeTwo; - for (size_t i = 0; i < par->NumChildren(); i++) + for (size_t i = 0; i < par->NumChildren(); ++i) assert(par->children[i] != tree); // We only add one at a time, so should only need to test for equality just in @@ -142,10 +142,10 @@ bool RTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) // We have to update the children of each of these new nodes so that they // record the correct parent. - for (size_t i = 0; i < treeOne->NumChildren(); i++) + for (size_t i = 0; i < treeOne->NumChildren(); ++i) treeOne->children[i]->Parent() = treeOne; - for (size_t i = 0; i < treeTwo->NumChildren(); i++) + for (size_t i = 0; i < treeTwo->NumChildren(); ++i) treeTwo->children[i]->Parent() = treeTwo; assert(treeOne->NumChildren() <= treeOne->MaxNumChildren()); @@ -170,9 +170,9 @@ void RTreeSplit::GetPointSeeds(const TreeType *tree, int& iRet, int& jRet) // same node. Because we are just using points, we will simply choose the two // that would create the most voluminous hyperrectangle. typename TreeType::ElemType worstPairScore = -1.0; - for (size_t i = 0; i < tree->Count(); i++) + for (size_t i = 0; i < tree->Count(); ++i) { - for (size_t j = i + 1; j < tree->Count(); j++) + for (size_t j = i + 1; j < tree->Count(); ++j) { const typename TreeType::ElemType score = arma::prod(arma::abs( tree->Dataset().col(tree->Point(i)) - @@ -199,12 +199,12 @@ void RTreeSplit::GetBoundSeeds(const TreeType *tree, int& iRet, int& jRet) typedef typename TreeType::ElemType ElemType; ElemType worstPairScore = -1.0; - for (size_t i = 0; i < tree->NumChildren(); i++) + for (size_t i = 0; i < tree->NumChildren(); ++i) { - for (size_t j = i + 1; j < tree->NumChildren(); j++) + for (size_t j = i + 1; j < tree->NumChildren(); ++j) { ElemType score = 1.0; - for (size_t k = 0; k < tree->Bound().Dim(); k++) + for (size_t k = 0; k < tree->Bound().Dim(); ++k) { const ElemType hiMax = std::max(tree->Child(i).Bound()[k].Hi(), tree->Child(j).Bound()[k].Hi()); @@ -283,7 +283,7 @@ void RTreeSplit::AssignPointDestNode(TreeType* oldTree, // First, calculate the starting volume. ElemType volOne = 1.0; ElemType volTwo = 1.0; - for (size_t i = 0; i < oldTree->Bound().Dim(); i++) + for (size_t i = 0; i < oldTree->Bound().Dim(); ++i) { volOne *= treeOne->Bound()[i].Width(); volTwo *= treeTwo->Bound()[i].Width(); @@ -295,7 +295,7 @@ void RTreeSplit::AssignPointDestNode(TreeType* oldTree, { ElemType newVolOne = 1.0; ElemType newVolTwo = 1.0; - for (size_t i = 0; i < oldTree->Bound().Dim(); i++) + for (size_t i = 0; i < oldTree->Bound().Dim(); ++i) { ElemType c = oldTree->Dataset().col(oldTree->Point(index))[i]; newVolOne *= treeOne->Bound()[i].Contains(c) ? @@ -348,12 +348,12 @@ void RTreeSplit::AssignPointDestNode(TreeType* oldTree, { if (numAssignedOne < numAssignedTwo) { - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) treeOne->InsertPoint(oldTree->Point(i)); } else { - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) treeTwo->InsertPoint(oldTree->Point(i)); } } @@ -374,8 +374,8 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, assert(intI != intJ); - for (size_t i = 0; i < oldTree->NumChildren(); i++) - for (size_t j = i + 1; j < oldTree->NumChildren(); j++) + for (size_t i = 0; i < oldTree->NumChildren(); ++i) + for (size_t j = i + 1; j < oldTree->NumChildren(); ++j) assert(oldTree->children[i] != oldTree->children[j]); InsertNodeIntoTree(treeOne, oldTree->children[intI]); @@ -397,14 +397,14 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, assert(treeOne->NumChildren() == 1); assert(treeTwo->NumChildren() == 1); - for (size_t i = 0; i < end; i++) - for (size_t j = i + 1; j < end; j++) + for (size_t i = 0; i < end; ++i) + for (size_t j = i + 1; j < end; ++j) assert(oldTree->children[i] != oldTree->children[j]); - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) assert(oldTree->children[i] != treeOne->children[0]); - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) assert(oldTree->children[i] != treeTwo->children[0]); size_t numAssignTreeOne = 1; @@ -424,7 +424,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, // new rectangles. ElemType volOne = 1.0; ElemType volTwo = 1.0; - for (size_t i = 0; i < oldTree->Bound().Dim(); i++) + for (size_t i = 0; i < oldTree->Bound().Dim(); ++i) { volOne *= treeOne->Bound()[i].Width(); volTwo *= treeTwo->Bound()[i].Width(); @@ -434,7 +434,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, { ElemType newVolOne = 1.0; ElemType newVolTwo = 1.0; - for (size_t i = 0; i < oldTree->Bound().Dim(); i++) + for (size_t i = 0; i < oldTree->Bound().Dim(); ++i) { // For each of the new rectangles, find the width in this dimension if // we add the rectangle at index to the new rectangle. @@ -495,7 +495,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, { if (numAssignTreeOne < numAssignTreeTwo) { - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) { InsertNodeIntoTree(treeOne, oldTree->children[i]); numAssignTreeOne++; @@ -503,7 +503,7 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, } else { - for (size_t i = 0; i < end; i++) + for (size_t i = 0; i < end; ++i) { InsertNodeIntoTree(treeTwo, oldTree->children[i]); numAssignTreeTwo++; @@ -511,12 +511,12 @@ void RTreeSplit::AssignNodeDestNode(TreeType* oldTree, } } - for (size_t i = 0; i < treeOne->NumChildren(); i++) - for (size_t j = i + 1; j < treeOne->NumChildren(); j++) + for (size_t i = 0; i < treeOne->NumChildren(); ++i) + for (size_t j = i + 1; j < treeOne->NumChildren(); ++j) assert(treeOne->children[i] != treeOne->children[j]); - for (size_t i = 0; i < treeTwo->NumChildren(); i++) - for (size_t j = i + 1; j < treeTwo->NumChildren(); j++) + for (size_t i = 0; i < treeTwo->NumChildren(); ++i) + for (size_t j = i + 1; j < treeTwo->NumChildren(); ++j) assert(treeTwo->children[i] != treeTwo->children[j]); } diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp index 66facadc60..137c30b04e 100644 --- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp @@ -74,7 +74,7 @@ RectangleTree(const MatType& data, // For now, just insert the points in order. RectangleTree* root = this; - for (size_t i = firstDataIndex; i < data.n_cols; i++) + for (size_t i = firstDataIndex; i < data.n_cols; ++i) root->InsertPoint(i); // Initialize statistic recursively after tree construction is complete. @@ -115,7 +115,7 @@ RectangleTree(MatType&& data, // For now, just insert the points in order. RectangleTree* root = this; - for (size_t i = firstDataIndex; i < dataset->n_cols; i++) + for (size_t i = firstDataIndex; i < dataset->n_cols; ++i) root->InsertPoint(i); // Initialize statistic recursively after tree construction is complete. @@ -196,7 +196,7 @@ RectangleTree( { if (numChildren > 0) { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) children[i] = new RectangleTree(other.Child(i), true, this); } } @@ -244,7 +244,7 @@ RectangleTree(RectangleTree&& other) : } if (!IsLeaf()) { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) children[i]->parent = this; } // Now we are a clone of the other tree. But we must also clear the other @@ -283,7 +283,7 @@ operator=(const RectangleTree& other) return *this; // Freeing memory that will not be used anymore. - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) delete children[i]; if (ownsDataset) @@ -309,7 +309,7 @@ operator=(const RectangleTree& other) if (numChildren > 0) { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) children[i] = new RectangleTree(other.Child(i), true, this); } @@ -336,7 +336,7 @@ operator=(RectangleTree&& other) return *this; // Freeing memory that will not be used anymore. - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) delete children[i]; if (ownsDataset) @@ -414,7 +414,7 @@ RectangleTree:: ~RectangleTree() { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) delete children[i]; if (ownsDataset) @@ -437,7 +437,7 @@ void RectangleTreeBound().Contains(dataset->col(point))) if (children[i]->DeletePoint(point, lvls)) return true; @@ -641,7 +641,7 @@ bool RectangleTreeBound().Contains(dataset->col(point))) if (children[i]->DeletePoint(point, relevels)) return true; @@ -684,7 +684,7 @@ bool RectangleTree:: RemoveNode(const RectangleTree* node, std::vector& relevels) { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (children[i] == node) { @@ -703,7 +703,7 @@ bool RectangleTreeBound().Dim(); j++) + for (size_t j = 0; j < node->Bound().Dim(); ++j) contains &= Child(i).Bound()[j].Contains(node->Bound()[j]); if (contains) @@ -724,7 +724,7 @@ size_t RectangleTree::TreeSize() const { int n = 0; - for (int i = 0; i < numChildren; i++) + for (int i = 0; i < numChildren; ++i) n += children[i]->TreeSize(); return n + 1; // Add one for this node. @@ -1084,7 +1084,7 @@ void RectangleTreeNumChildren(); i++) + for (size_t i = 0; i < parent->NumChildren(); ++i) { if (parent->children[i] == this) { @@ -1125,7 +1125,7 @@ void RectangleTreeAuxiliaryInfo().UpdateAuxiliaryInfo(root); // Reinsert the points at the root node. - for (size_t j = 0; j < count; j++) + for (size_t j = 0; j < count; ++j) root->InsertPoint(points[j], relevels); // This will check the minFill of the parent. @@ -1144,7 +1144,7 @@ void RectangleTreeNumChildren(); j++) + for (size_t j = 0; j < parent->NumChildren(); ++j) { if (parent->children[j] == this) { @@ -1186,7 +1186,7 @@ void RectangleTreeAuxiliaryInfo().UpdateAuxiliaryInfo(root); // Reinsert the nodes at the root node. - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) root->InsertNode(children[i], level, relevels); // This will check the minFill of the point. @@ -1210,7 +1210,7 @@ void RectangleTreeNumChildren(); i++) + for (size_t i = 0; i < child->NumChildren(); ++i) { children[i] = child->children[i]; children[i]->Parent() = this; @@ -1220,7 +1220,7 @@ void RectangleTreeNumChildren(); child->NumChildren() = 0; - for (size_t i = 0; i < child->Count(); i++) + for (size_t i = 0; i < child->Count(); ++i) { // In case the tree has a height of two. points[i] = child->Point(i); @@ -1264,12 +1264,12 @@ bool RectangleTree::max(); - for (size_t j = 0; j < count; j++) + for (size_t j = 0; j < count; ++j) { if (dataset->col(points[j])[i] < min) min = dataset->col(points[j])[i]; @@ -1288,7 +1288,7 @@ bool RectangleTree::lowest(); - for (size_t j = 0; j < count; j++) + for (size_t j = 0; j < count; ++j) { if (dataset->col(points[j])[i] > max) max = dataset->col(points[j])[i]; @@ -1308,12 +1308,12 @@ bool RectangleTree::max(); - for (size_t j = 0; j < numChildren; j++) + for (size_t j = 0; j < numChildren; ++j) { if (children[j]->Bound()[i].Lo() < min) min = children[j]->Bound()[i].Lo(); @@ -1328,7 +1328,7 @@ bool RectangleTree::lowest(); - for (size_t j = 0; j < numChildren; j++) + for (size_t j = 0; j < numChildren; ++j) { if (children[j]->Bound()[i].Hi() > max) max = children[j]->Bound()[i].Hi(); @@ -1363,20 +1363,20 @@ bool RectangleTree::max(); bound[i].Hi() = std::numeric_limits::lowest(); } - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { bound |= children[i]->Bound(); } ElemType sum2 = 0; - for (size_t i = 0; i < bound.Dim(); i++) + for (size_t i = 0; i < bound.Dim(); ++i) sum2 += bound[i].Width(); return sum != sum2; @@ -1400,7 +1400,7 @@ void RectangleTree::Traverse( // If we reach a leaf node, we need to run the base case. if (referenceNode.IsLeaf()) { - for (size_t i = 0; i < referenceNode.Count(); i++) + for (size_t i = 0; i < referenceNode.Count(); ++i) rule.BaseCase(queryIndex, referenceNode.Point(i)); return; @@ -61,7 +61,7 @@ SingleTreeTraverser::Traverse( // This is not a leaf node so we sort the children of this node by their // scores. std::vector nodesAndScores(referenceNode.NumChildren()); - for (size_t i = 0; i < referenceNode.NumChildren(); i++) + for (size_t i = 0; i < referenceNode.NumChildren(); ++i) { nodesAndScores[i].node = &(referenceNode.Child(i)); nodesAndScores[i].score = rule.Score(queryIndex, *nodesAndScores[i].node); @@ -71,7 +71,7 @@ SingleTreeTraverser::Traverse( // Now iterate through them starting with the best and stopping when we reach // one that isn't good enough. - for (size_t i = 0; i < referenceNode.NumChildren(); i++) + for (size_t i = 0; i < referenceNode.NumChildren(); ++i) { if (rule.Rescore(queryIndex, *nodesAndScores[i].node, nodesAndScores[i].score) != DBL_MAX) diff --git a/src/mlpack/core/tree/rectangle_tree/x_tree_auxiliary_information.hpp b/src/mlpack/core/tree/rectangle_tree/x_tree_auxiliary_information.hpp index a1487722ad..a893bde5c3 100644 --- a/src/mlpack/core/tree/rectangle_tree/x_tree_auxiliary_information.hpp +++ b/src/mlpack/core/tree/rectangle_tree/x_tree_auxiliary_information.hpp @@ -173,7 +173,7 @@ class XTreeAuxiliaryInformation SplitHistoryStruct(int dim) : lastDimension(0), history(dim) { - for (int i = 0; i < dim; i++) + for (int i = 0; i < dim; ++i) history[i] = false; } diff --git a/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp index 5fa732d8cf..c977f0fecb 100644 --- a/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp @@ -49,7 +49,7 @@ void XTreeSplit::SplitLeafNode(TreeType *tree, std::vector& relevels) * dimension to prepare for reinsertion of points into the new nodes. */ std::vector> sorted(tree->Count()); - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Dataset().col(tree->Point(i))[bestAxis]; sorted[i].second = tree->Point(i); @@ -83,7 +83,7 @@ void XTreeSplit::SplitLeafNode(TreeType *tree, std::vector& relevels) tree->bound.Clear(); // Insert the points into the appropriate tree. - for (size_t i = 0; i < numPoints; i++) + for (size_t i = 0; i < numPoints; ++i) { if (i < bestIndex + tree->MinLeafSize()) treeOne->InsertPoint(sorted[i].second); @@ -137,7 +137,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) // Find the next split axis. std::vector axes(tree->Bound().Dim(), true); std::vector dimensionsLastUsed(tree->NumChildren()); - for (size_t i = 0; i < tree->NumChildren(); i++) + for (size_t i = 0; i < tree->NumChildren(); ++i) dimensionsLastUsed[i] = tree->Child(i).AuxiliaryInfo().SplitHistory().lastDimension; std::sort(dimensionsLastUsed.begin(), dimensionsLastUsed.end()); @@ -146,9 +146,9 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) size_t minOverlapSplitDimension = tree->Bound().Dim(); // See if we can use a new dimension. - for (size_t i = lastDim + 1; i < axes.size(); i++) + for (size_t i = lastDim + 1; i < axes.size(); ++i) { - for (size_t j = 0; j < tree->NumChildren(); j++) + for (size_t j = 0; j < tree->NumChildren(); ++j) axes[i] = axes[i] & tree->Child(j).AuxiliaryInfo().SplitHistory().history[i]; if (axes[i] == true) @@ -160,10 +160,10 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) if (minOverlapSplitDimension == tree->Bound().Dim()) { - for (size_t i = 0; i < lastDim + 1; i++) + for (size_t i = 0; i < lastDim + 1; ++i) { axes[i] = true; - for (size_t j = 0; j < tree->NumChildren(); j++) + for (size_t j = 0; j < tree->NumChildren(); ++j) axes[i] = axes[i] & tree->Child(j).AuxiliaryInfo().SplitHistory().history[i]; if (axes[i] == true) @@ -190,13 +190,13 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) ElemType overlapBestAreaAxis = 0; ElemType areaBestAreaAxis = 0; - for (size_t j = 0; j < tree->Bound().Dim(); j++) + for (size_t j = 0; j < tree->Bound().Dim(); ++j) { ElemType axisScore = 0.0; // We'll do Bound().Lo() now and use Bound().Hi() later. std::vector> sorted(tree->NumChildren()); - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Child(i).Bound()[j].Lo(); sorted[i].second = &tree->Child(i); @@ -211,14 +211,14 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) 2 * tree->MinNumChildren() + 2); std::vector overlapedAreas(tree->MaxNumChildren() - 2 * tree->MinNumChildren() + 2); - for (size_t i = 0; i < areas.size(); i++) + for (size_t i = 0; i < areas.size(); ++i) { areas[i] = 0.0; margins[i] = 0.0; overlapedAreas[i] = 0.0; } - for (size_t i = 0; i < areas.size(); i++) + for (size_t i = 0; i < areas.size(); ++i) { // The ith arrangement is obtained by placing the first // tree->MinNumChildren() + i points in one rectangle and the rest in @@ -239,7 +239,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) ElemType area2 = bound2.Volume(); ElemType oArea = bound1.Overlap(bound2); - for (size_t k = 0; k < bound1.Dim(); k++) + for (size_t k = 0; k < bound1.Dim(); ++k) margins[i] += bound1[k].Width() + bound2[k].Width(); areas[i] += area1 + area2; @@ -255,7 +255,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) bestAreaIndexOnBestAxis = 0; overlapBestOverlapAxis = overlapedAreas[bestOverlapIndexOnBestAxis]; areaBestOverlapAxis = areas[bestAreaIndexOnBestAxis]; - for (size_t i = 1; i < areas.size(); i++) + for (size_t i = 1; i < areas.size(); ++i) { if (overlapedAreas[i] < overlapedAreas[bestOverlapIndexOnBestAxis]) { @@ -283,7 +283,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) if (minOverlapSplitDimension != tree->Bound().Dim() && j == minOverlapSplitDimension) { - for (size_t i = 0; i < overlapedAreas.size(); i++) + for (size_t i = 0; i < overlapedAreas.size(); ++i) { if (overlapedAreas[i] < bestScoreMinOverlapSplit) { @@ -296,12 +296,12 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) } // Now we do the same thing using Bound().Hi() and choose the best of the two. - for (size_t j = 0; j < tree->Bound().Dim(); j++) + for (size_t j = 0; j < tree->Bound().Dim(); ++j) { ElemType axisScore = 0.0; std::vector> sorted(tree->NumChildren()); - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Child(i).Bound()[j].Hi(); sorted[i].second = &tree->Child(i); @@ -316,14 +316,14 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) 2 * tree->MinNumChildren() + 2); std::vector overlapedAreas(tree->MaxNumChildren() - 2 * tree->MinNumChildren() + 2); - for (size_t i = 0; i < areas.size(); i++) + for (size_t i = 0; i < areas.size(); ++i) { areas[i] = 0.0; margins[i] = 0.0; overlapedAreas[i] = 0.0; } - for (size_t i = 0; i < areas.size(); i++) + for (size_t i = 0; i < areas.size(); ++i) { // The ith arrangement is obtained by placing the first // tree->MinNumChildren() + i points in one rectangle and the rest in @@ -344,7 +344,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) ElemType area2 = bound2.Volume(); ElemType oArea = bound1.Overlap(bound2); - for (size_t k = 0; k < bound1.Dim(); k++) + for (size_t k = 0; k < bound1.Dim(); ++k) margins[i] += bound1[k].Width() + bound2[k].Width(); @@ -362,7 +362,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) bestAreaIndexOnBestAxis = 0; overlapBestOverlapAxis = overlapedAreas[bestOverlapIndexOnBestAxis]; areaBestOverlapAxis = areas[bestAreaIndexOnBestAxis]; - for (size_t i = 1; i < areas.size(); i++) + for (size_t i = 1; i < areas.size(); ++i) { if (overlapedAreas[i] < overlapedAreas[bestOverlapIndexOnBestAxis]) { @@ -390,7 +390,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) if (minOverlapSplitDimension != tree->Bound().Dim() && j == minOverlapSplitDimension) { - for (size_t i = 0; i < overlapedAreas.size(); i++) + for (size_t i = 0; i < overlapedAreas.size(); ++i) { if (overlapedAreas[i] < bestScoreMinOverlapSplit) { @@ -406,7 +406,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) std::vector> sorted(tree->NumChildren()); if (lowIsBest) { - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Child(i).Bound()[bestAxis].Lo(); sorted[i].second = &tree->Child(i); @@ -414,7 +414,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) } else { - for (size_t i = 0; i < sorted.size(); i++) + for (size_t i = 0; i < sorted.size(); ++i) { sorted[i].first = tree->Child(i).Bound()[bestAxis].Hi(); sorted[i].second = &tree->Child(i); @@ -439,7 +439,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) { tree->numDescendants = 0; tree->bound.Clear(); - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (i < bestAreaIndexOnBestAxis + tree->MinNumChildren()) InsertNodeIntoTree(tree, sorted[i].second); @@ -456,7 +456,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) { tree->numDescendants = 0; tree->bound.Clear(); - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (i < bestOverlapIndexOnBestAxis + tree->MinNumChildren()) InsertNodeIntoTree(tree, sorted[i].second); @@ -480,7 +480,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) std::vector> sorted2(numChildren); if (minOverlapSplitUsesHi) { - for (size_t i = 0; i < sorted2.size(); i++) + for (size_t i = 0; i < sorted2.size(); ++i) { sorted2[i].first = sorted[i].second->Bound()[bestAxis].Hi(); sorted2[i].second = sorted[i].second; @@ -488,7 +488,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) } else { - for (size_t i = 0; i < sorted2.size(); i++) + for (size_t i = 0; i < sorted2.size(); ++i) { sorted2[i].first = sorted[i].second->Bound()[bestAxis].Lo(); sorted2[i].second = sorted[i].second; @@ -499,7 +499,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) tree->numDescendants = 0; tree->bound.Clear(); - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (i < bestIndexMinOverlapSplit + tree->MinNumChildren()) InsertNodeIntoTree(tree, sorted2[i].second); @@ -544,7 +544,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) tree->AuxiliaryInfo().NormalNodeMaxNumChildren(); tree->children.resize(tree->MaxNumChildren() + 1); tree->numChildren = numChildren; - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) tree->Child(i).Parent() = tree; delete treeTwo; @@ -574,7 +574,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) // We have to update the children of each of these new nodes so that they // record the correct parent. - for (size_t i = 0; i < treeTwo->NumChildren(); i++) + for (size_t i = 0; i < treeTwo->NumChildren(); ++i) treeTwo->Child(i).Parent() = treeTwo; assert(tree->Parent()->NumChildren() <= @@ -602,7 +602,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) { if (overlapBestAreaAxis/areaBestAreaAxis < MAX_OVERLAP) { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (i < bestAreaIndexOnBestAxis + tree->MinNumChildren()) InsertNodeIntoTree(treeOne, sorted[i].second); @@ -617,7 +617,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) { if (overlapBestOverlapAxis/areaBestOverlapAxis < MAX_OVERLAP) { - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (i < bestOverlapIndexOnBestAxis + tree->MinNumChildren()) InsertNodeIntoTree(treeOne, sorted[i].second); @@ -641,7 +641,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) std::vector> sorted2(numChildren); if (minOverlapSplitUsesHi) { - for (size_t i = 0; i < sorted2.size(); i++) + for (size_t i = 0; i < sorted2.size(); ++i) { sorted2[i].first = sorted[i].second->Bound()[bestAxis].Hi(); sorted2[i].second = sorted[i].second; @@ -649,7 +649,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) } else { - for (size_t i = 0; i < sorted2.size(); i++) + for (size_t i = 0; i < sorted2.size(); ++i) { sorted2[i].first = sorted[i].second->Bound()[bestAxis].Lo(); sorted2[i].second = sorted[i].second; @@ -658,7 +658,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) std::sort(sorted2.begin(), sorted2.end(), PairComp); - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) { if (i < bestIndexMinOverlapSplit + tree->MinNumChildren()) InsertNodeIntoTree(treeOne, sorted2[i].second); @@ -673,7 +673,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) tree->AuxiliaryInfo().NormalNodeMaxNumChildren(); tree->children.resize(tree->MaxNumChildren() + 1); tree->numChildren = numChildren; - for (size_t i = 0; i < numChildren; i++) + for (size_t i = 0; i < numChildren; ++i) tree->Child(i).Parent() = tree; delete treeOne; @@ -698,7 +698,7 @@ bool XTreeSplit::SplitNonLeafNode(TreeType *tree, std::vector& relevels) // record the correct parent. for (size_t i = 0; i < treeOne->NumChildren(); ++i) treeOne->Child(i).Parent() = treeOne; - for (size_t i = 0; i < treeTwo->NumChildren(); i++) + for (size_t i = 0; i < treeTwo->NumChildren(); ++i) treeTwo->Child(i).Parent() = treeTwo; return false; diff --git a/src/mlpack/core/tree/space_split/mean_space_split_impl.hpp b/src/mlpack/core/tree/space_split/mean_space_split_impl.hpp index 1c2968e5e9..8e0dc1c7fd 100644 --- a/src/mlpack/core/tree/space_split/mean_space_split_impl.hpp +++ b/src/mlpack/core/tree/space_split/mean_space_split_impl.hpp @@ -35,7 +35,7 @@ bool MeanSpaceSplit::SplitSpace( return false; double splitVal = 0.0; - for (size_t i = 0; i < points.n_elem; i++) + for (size_t i = 0; i < points.n_elem; ++i) splitVal += projVector.Project(data.col(points[i])); splitVal /= points.n_elem; diff --git a/src/mlpack/core/tree/space_split/space_split_impl.hpp b/src/mlpack/core/tree/space_split/space_split_impl.hpp index 33709af2f1..ee0d9375f1 100644 --- a/src/mlpack/core/tree/space_split/space_split_impl.hpp +++ b/src/mlpack/core/tree/space_split/space_split_impl.hpp @@ -67,7 +67,7 @@ bool SpaceSplit::GetProjVector( size_t snd = points[0]; double max = metric.Evaluate(data.col(fst), data.col(snd)); - for (size_t i = 1; i < points.n_elem; i++) + for (size_t i = 1; i < points.n_elem; ++i) { double dist = metric.Evaluate(data.col(fst), data.col(points[i])); if (dist > max) @@ -79,7 +79,7 @@ bool SpaceSplit::GetProjVector( std::swap(fst, snd); - for (size_t i = 0; i < points.n_elem; i++) + for (size_t i = 0; i < points.n_elem; ++i) { double dist = metric.Evaluate(data.col(fst), data.col(points[i])); if (dist > max) diff --git a/src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp b/src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp index 73a313cde4..7637be0289 100644 --- a/src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp +++ b/src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp @@ -722,7 +722,7 @@ void SpillTree:: const double rho) { // We need to expand the bounds of this node properly. - for (size_t i = 0; i < points.n_elem; i++) + for (size_t i = 0; i < points.n_elem; ++i) bound |= dataset->col(points[i]); // Calculate the furthest descendant distance. @@ -795,7 +795,7 @@ bool SpillTree:: size_t left = 0, right = 0, leftFrontier = 0, rightFrontier = 0; // Count the number of points to the left/right of the splitting hyperplane. - for (size_t i = 0; i < points.n_elem; i++) + for (size_t i = 0; i < points.n_elem; ++i) { // Store projection value for future use. projections[i] = hyperplane.Project(dataset->col(points[i])); @@ -824,7 +824,7 @@ bool SpillTree:: // leftPoints and rightPoints. leftPoints.resize(left + rightFrontier); rightPoints.resize(right + leftFrontier); - for (size_t i = 0, rc = 0, lc = 0; i < points.n_elem; i++) + for (size_t i = 0, rc = 0, lc = 0; i < points.n_elem; ++i) { if (projections[i] < tau || projections[i] <= 0) leftPoints[lc++] = points[i]; @@ -841,7 +841,7 @@ bool SpillTree:: // rightPoints. leftPoints.resize(left); rightPoints.resize(right); - for (size_t i = 0, rc = 0, lc = 0; i < points.n_elem; i++) + for (size_t i = 0, rc = 0, lc = 0; i < points.n_elem; ++i) { if (projections[i] <= 0) leftPoints[lc++] = points[i]; diff --git a/src/mlpack/core/util/backtrace.cpp b/src/mlpack/core/util/backtrace.cpp index b17c4acef2..3bdf7c4f29 100644 --- a/src/mlpack/core/util/backtrace.cpp +++ b/src/mlpack/core/util/backtrace.cpp @@ -84,7 +84,7 @@ void Backtrace::GetAddress(int maxDepth) int stackDepth = backtrace(trace, maxDepth); // Skip first stack frame (points to Backtrace::Backtrace). - for (int i = 1; i < stackDepth; i++) + for (int i = 1; i < stackDepth; ++i) { Dl_info addressHandler; @@ -182,7 +182,7 @@ std::string Backtrace::ToString() return stackStr; } - for (size_t i = 0; i < stack.size(); i++) + for (size_t i = 0; i < stack.size(); ++i) { frame = stack[i]; diff --git a/src/mlpack/methods/adaboost/adaboost_impl.hpp b/src/mlpack/methods/adaboost/adaboost_impl.hpp index a08f507617..3f1b3fa6b4 100644 --- a/src/mlpack/methods/adaboost/adaboost_impl.hpp +++ b/src/mlpack/methods/adaboost/adaboost_impl.hpp @@ -106,7 +106,7 @@ double AdaBoost::Train( arma::Row finalH(predictedLabels.n_cols); // Now, start the boosting rounds. - for (size_t i = 0; i < iterations; i++) + for (size_t i = 0; i < iterations; ++i) { // Initialized to zero in every round. rt is used for calculation of // alphat; it is the weighted error. @@ -127,7 +127,7 @@ double AdaBoost::Train( // buildClassificationMatrix(ht, predictedLabels); // Now, calculate alpha(t) using ht. - for (size_t j = 0; j < D.n_cols; j++) // instead of D, ht + for (size_t j = 0; j < D.n_cols; ++j) // instead of D, ht { if (predictedLabels(j) == labels(j)) rt += arma::accu(D.col(j)); @@ -157,12 +157,12 @@ double AdaBoost::Train( wl.push_back(w); // Now start modifying the weights. - for (size_t j = 0; j < D.n_cols; j++) + for (size_t j = 0; j < D.n_cols; ++j) { const double expo = exp(alphat); if (predictedLabels(j) == labels(j)) { - for (size_t k = 0; k < D.n_rows; k++) + for (size_t k = 0; k < D.n_rows; ++k) { // We calculate zt, the normalization constant. D(k, j) /= expo; @@ -178,7 +178,7 @@ double AdaBoost::Train( } else { - for (size_t k = 0; k < D.n_rows; k++) + for (size_t k = 0; k < D.n_rows; ++k) { // We calculate zt, the normalization constant. D(k, j) *= expo; @@ -230,18 +230,18 @@ void AdaBoost::Classify( probabilities.zeros(numClasses, test.n_cols); predictedLabels.set_size(test.n_cols); - for (size_t i = 0; i < wl.size(); i++) + for (size_t i = 0; i < wl.size(); ++i) { wl[i].Classify(test, tempPredictedLabels); - for (size_t j = 0; j < tempPredictedLabels.n_cols; j++) + for (size_t j = 0; j < tempPredictedLabels.n_cols; ++j) probabilities(tempPredictedLabels(j), j) += alpha[i]; } arma::colvec pRow; arma::uword maxIndex = 0; - for (size_t i = 0; i < predictedLabels.n_cols; i++) + for (size_t i = 0; i < predictedLabels.n_cols; ++i) { probabilities.col(i) /= arma::accu(probabilities.col(i)); pRow = probabilities.unsafe_col(i); diff --git a/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp b/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp index becd1b70dd..72ec87561f 100644 --- a/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp +++ b/src/mlpack/methods/amf/termination_policies/simple_tolerance_termination.hpp @@ -78,9 +78,9 @@ class SimpleToleranceTermination size_t m = V->n_cols; double sum = 0; size_t count = 0; - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; ++i) { - for (size_t j = 0; j < m; j++) + for (size_t j = 0; j < m; ++j) { double temp = 0; if ((temp = (*V)(i, j)) != 0) diff --git a/src/mlpack/methods/amf/termination_policies/validation_rmse_termination.hpp b/src/mlpack/methods/amf/termination_policies/validation_rmse_termination.hpp index b7534bbc2e..13fb3b2f52 100644 --- a/src/mlpack/methods/amf/termination_policies/validation_rmse_termination.hpp +++ b/src/mlpack/methods/amf/termination_policies/validation_rmse_termination.hpp @@ -64,7 +64,7 @@ class ValidationRMSETermination test_points.zeros(num_test_points, 3); // fill validation set matrix with random chosen entries - for (size_t i = 0; i < num_test_points; i++) + for (size_t i = 0; i < num_test_points; ++i) { double t_val; size_t t_row; @@ -123,7 +123,7 @@ class ValidationRMSETermination { rmseOld = rmse; rmse = 0; - for (size_t i = 0; i < num_test_points; i++) + for (size_t i = 0; i < num_test_points; ++i) { size_t t_row = test_points(i, 0); size_t t_col = test_points(i, 1); diff --git a/src/mlpack/methods/amf/update_rules/nmf_als.hpp b/src/mlpack/methods/amf/update_rules/nmf_als.hpp index 3bbd28efe2..9970fb9b98 100644 --- a/src/mlpack/methods/amf/update_rules/nmf_als.hpp +++ b/src/mlpack/methods/amf/update_rules/nmf_als.hpp @@ -78,7 +78,7 @@ class NMFALSUpdate W = V * H.t() * pinv(H * H.t()); // Set all negative numbers to machine epsilon. - for (size_t i = 0; i < W.n_elem; i++) + for (size_t i = 0; i < W.n_elem; ++i) { if (W(i) < 0.0) { @@ -109,7 +109,7 @@ class NMFALSUpdate H = pinv(W.t() * W) * W.t() * V; // Set all negative numbers to 0. - for (size_t i = 0; i < H.n_elem; i++) + for (size_t i = 0; i < H.n_elem; ++i) { if (H(i) < 0.0) { diff --git a/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp b/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp index 66f4f3eacd..0692acee9a 100644 --- a/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp +++ b/src/mlpack/methods/amf/update_rules/nmf_mult_div.hpp @@ -130,9 +130,9 @@ class NMFMultiplicativeDivergenceUpdate arma::colvec t2; t1 = W * H; - for (size_t i = 0; i < H.n_rows; i++) + for (size_t i = 0; i < H.n_rows; ++i) { - for (size_t j = 0; j < H.n_cols; j++) + for (size_t j = 0; j < H.n_cols; ++j) { // Writing this as a single expression does not work as of Armadillo // 3.920. This should be fixed in a future release, and then the code diff --git a/src/mlpack/methods/amf/update_rules/svd_batch_learning.hpp b/src/mlpack/methods/amf/update_rules/svd_batch_learning.hpp index 26758da42b..b61bd0d928 100644 --- a/src/mlpack/methods/amf/update_rules/svd_batch_learning.hpp +++ b/src/mlpack/methods/amf/update_rules/svd_batch_learning.hpp @@ -100,9 +100,9 @@ class SVDBatchLearning // Compute the step. arma::mat deltaW; deltaW.zeros(n, r); - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; ++i) { - for (size_t j = 0; j < m; j++) + for (size_t j = 0; j < m; ++j) { const double val = V(i, j); if (val != 0) @@ -145,9 +145,9 @@ class SVDBatchLearning // Compute the step. arma::mat deltaH; deltaH.zeros(r, m); - for (size_t j = 0; j < m; j++) + for (size_t j = 0; j < m; ++j) { - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; ++i) { const double val = V(i, j); if (val != 0) diff --git a/src/mlpack/methods/ann/activation_functions/hard_sigmoid_function.hpp b/src/mlpack/methods/ann/activation_functions/hard_sigmoid_function.hpp index 362d4a3d30..a1f68dae2f 100644 --- a/src/mlpack/methods/ann/activation_functions/hard_sigmoid_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/hard_sigmoid_function.hpp @@ -56,7 +56,7 @@ class HardSigmoidFunction { y.set_size(size(x)); - for (size_t i = 0; i < x.n_elem; i++) + for (size_t i = 0; i < x.n_elem; ++i) y(i) = Fn(x(i)); } @@ -86,7 +86,7 @@ class HardSigmoidFunction { x.set_size(size(y)); - for (size_t i = 0; i < y.n_elem; i++) + for (size_t i = 0; i < y.n_elem; ++i) { x(i) = Deriv(y(i)); } diff --git a/src/mlpack/methods/ann/activation_functions/rectifier_function.hpp b/src/mlpack/methods/ann/activation_functions/rectifier_function.hpp index 806b792afc..58f7f15582 100644 --- a/src/mlpack/methods/ann/activation_functions/rectifier_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/rectifier_function.hpp @@ -104,7 +104,7 @@ class RectifierFunction { x.set_size(arma::size(y)); - for (size_t i = 0; i < y.n_elem; i++) + for (size_t i = 0; i < y.n_elem; ++i) x(i) = Deriv(y(i)); } }; // class RectifierFunction diff --git a/src/mlpack/methods/ann/activation_functions/softplus_function.hpp b/src/mlpack/methods/ann/activation_functions/softplus_function.hpp index 0afcab4613..470e11e7f0 100644 --- a/src/mlpack/methods/ann/activation_functions/softplus_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/softplus_function.hpp @@ -68,7 +68,7 @@ class SoftplusFunction { y.set_size(arma::size(x)); - for (size_t i = 0; i < x.n_elem; i++) + for (size_t i = 0; i < x.n_elem; ++i) y(i) = Fn(x(i)); } @@ -120,7 +120,7 @@ class SoftplusFunction { x.set_size(arma::size(y)); - for (size_t i = 0; i < y.n_elem; i++) + for (size_t i = 0; i < y.n_elem; ++i) x(i) = Inv(y(i)); } }; // class SoftplusFunction diff --git a/src/mlpack/methods/ann/activation_functions/softsign_function.hpp b/src/mlpack/methods/ann/activation_functions/softsign_function.hpp index df63c7dbd9..3e00c69d68 100644 --- a/src/mlpack/methods/ann/activation_functions/softsign_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/softsign_function.hpp @@ -71,7 +71,7 @@ class SoftsignFunction { y.set_size(arma::size(x)); - for (size_t i = 0; i < x.n_elem; i++) + for (size_t i = 0; i < x.n_elem; ++i) y(i) = Fn(x(i)); } @@ -123,7 +123,7 @@ class SoftsignFunction { x.set_size(arma::size(y)); - for (size_t i = 0; i < y.n_elem; i++) + for (size_t i = 0; i < y.n_elem; ++i) x(i) = Inv(y(i)); } }; // class SoftsignFunction diff --git a/src/mlpack/methods/ann/activation_functions/swish_function.hpp b/src/mlpack/methods/ann/activation_functions/swish_function.hpp index f250b23deb..aeeb5863e9 100644 --- a/src/mlpack/methods/ann/activation_functions/swish_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/swish_function.hpp @@ -64,7 +64,7 @@ class SwishFunction { y.set_size(arma::size(x)); - for (size_t i = 0; i < x.n_elem; i++) + for (size_t i = 0; i < x.n_elem; ++i) y(i) = Fn(x(i)); } diff --git a/src/mlpack/methods/ann/augmented/tasks/score_impl.hpp b/src/mlpack/methods/ann/augmented/tasks/score_impl.hpp index 40e1da7670..286e77c2a2 100644 --- a/src/mlpack/methods/ann/augmented/tasks/score_impl.hpp +++ b/src/mlpack/methods/ann/augmented/tasks/score_impl.hpp @@ -38,7 +38,7 @@ double SequencePrecision(arma::field trueOutputs, throw std::invalid_argument(oss.str()); } - for (size_t i = 0; i < testSize; i++) + for (size_t i = 0; i < testSize; ++i) { arma::vec delta = arma::vectorise(arma::abs( trueOutputs.at(i) - predOutputs.at(i))); diff --git a/src/mlpack/methods/ann/convolution_rules/fft_convolution.hpp b/src/mlpack/methods/ann/convolution_rules/fft_convolution.hpp index a51d0e747f..8497ff11d8 100644 --- a/src/mlpack/methods/ann/convolution_rules/fft_convolution.hpp +++ b/src/mlpack/methods/ann/convolution_rules/fft_convolution.hpp @@ -144,7 +144,7 @@ class FFTConvolution input.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < input.n_slices; i++) + for (size_t i = 1; i < input.n_slices; ++i) { FFTConvolution::Convolution(input.slice(i), filter.slice(i), output.slice(i)); @@ -175,7 +175,7 @@ class FFTConvolution filter.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < filter.n_slices; i++) + for (size_t i = 1; i < filter.n_slices; ++i) { FFTConvolution::Convolution(input, filter.slice(i), output.slice(i)); @@ -203,7 +203,7 @@ class FFTConvolution input.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < input.n_slices; i++) + for (size_t i = 1; i < input.n_slices; ++i) { FFTConvolution::Convolution(input.slice(i), filter, output.slice(i)); diff --git a/src/mlpack/methods/ann/convolution_rules/naive_convolution.hpp b/src/mlpack/methods/ann/convolution_rules/naive_convolution.hpp index db7a68f1a1..d0bf1cadfd 100644 --- a/src/mlpack/methods/ann/convolution_rules/naive_convolution.hpp +++ b/src/mlpack/methods/ann/convolution_rules/naive_convolution.hpp @@ -108,7 +108,7 @@ class NaiveConvolution size_t outputCols = (input.n_cols - 1) * dH + 2 * (filter.n_cols - 1) * dilationH + 1; - for (size_t i = 0; i < dW; i++) + for (size_t i = 0; i < dW; ++i) { if (((((i + outputRows - 2 * (filter.n_rows - 1) * dilationW - 1) % dW) + dW) % dW) == i){ @@ -116,7 +116,7 @@ class NaiveConvolution break; } } - for (size_t i = 0; i < dH; i++) + for (size_t i = 0; i < dH; ++i) { if (((((i + outputCols - 2 * (filter.n_cols - 1) * dilationH - 1) % dH) + dH) % dH) == i){ @@ -164,7 +164,7 @@ class NaiveConvolution input.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < input.n_slices; i++) + for (size_t i = 1; i < input.n_slices; ++i) { NaiveConvolution::Convolution(input.slice(i), filter.slice(i), output.slice(i), dW, dH, dilationW, dilationH); @@ -200,7 +200,7 @@ class NaiveConvolution filter.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < filter.n_slices; i++) + for (size_t i = 1; i < filter.n_slices; ++i) { NaiveConvolution::Convolution(input, filter.slice(i), output.slice(i), dW, dH, dilationW, dilationH); @@ -236,7 +236,7 @@ class NaiveConvolution input.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < input.n_slices; i++) + for (size_t i = 1; i < input.n_slices; ++i) { NaiveConvolution::Convolution(input.slice(i), filter, output.slice(i), dW, dH, dilationW, dilationH); diff --git a/src/mlpack/methods/ann/convolution_rules/svd_convolution.hpp b/src/mlpack/methods/ann/convolution_rules/svd_convolution.hpp index e94ed35228..ce9a021127 100644 --- a/src/mlpack/methods/ann/convolution_rules/svd_convolution.hpp +++ b/src/mlpack/methods/ann/convolution_rules/svd_convolution.hpp @@ -131,7 +131,7 @@ class SVDConvolution input.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < input.n_slices; i++) + for (size_t i = 1; i < input.n_slices; ++i) { SVDConvolution::Convolution(input.slice(i), filter.slice(i), output.slice(i)); @@ -160,7 +160,7 @@ class SVDConvolution filter.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < filter.n_slices; i++) + for (size_t i = 1; i < filter.n_slices; ++i) { SVDConvolution::Convolution(input, filter.slice(i), output.slice(i)); @@ -189,7 +189,7 @@ class SVDConvolution input.n_slices); output.slice(0) = convOutput; - for (size_t i = 1; i < input.n_slices; i++) + for (size_t i = 1; i < input.n_slices; ++i) { SVDConvolution::Convolution(input.slice(i), filter, output.slice(i)); diff --git a/src/mlpack/methods/ann/dists/bernoulli_distribution_impl.hpp b/src/mlpack/methods/ann/dists/bernoulli_distribution_impl.hpp index 8923de2b61..a9c54c1a4a 100644 --- a/src/mlpack/methods/ann/dists/bernoulli_distribution_impl.hpp +++ b/src/mlpack/methods/ann/dists/bernoulli_distribution_impl.hpp @@ -52,7 +52,7 @@ DataType BernoulliDistribution::Sample() const DataType sample = arma::randu (probability.n_rows, probability.n_cols); - for (size_t i = 0; i < sample.n_elem; i++) + for (size_t i = 0; i < sample.n_elem; ++i) sample(i) = sample(i) < probability(i); return sample; diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp index 247c0db4ee..12194ec9c0 100644 --- a/src/mlpack/methods/ann/ffn_impl.hpp +++ b/src/mlpack/methods/ann/ffn_impl.hpp @@ -242,7 +242,7 @@ void FFN::Predict( results = arma::mat(resultsTemp.n_elem, predictors.n_cols); results.col(0) = resultsTemp.col(0); - for (size_t i = 1; i < predictors.n_cols; i++) + for (size_t i = 1; i < predictors.n_cols; ++i) { Forward(arma::mat(predictors.colptr(i), predictors.n_rows, 1, false, true)); diff --git a/src/mlpack/methods/ann/gan/metrics/inception_score_impl.hpp b/src/mlpack/methods/ann/gan/metrics/inception_score_impl.hpp index 69a08fa413..bb3ab845a1 100644 --- a/src/mlpack/methods/ann/gan/metrics/inception_score_impl.hpp +++ b/src/mlpack/methods/ann/gan/metrics/inception_score_impl.hpp @@ -32,7 +32,7 @@ double InceptionScore(ModelType model, size_t index = 0; arma::vec scores = arma::vec(splits); - for (int i = 0; i < splits; i++) + for (int i = 0; i < splits; ++i) { size_t curSize = splitSize; if (remainder) diff --git a/src/mlpack/methods/ann/init_rules/gaussian_init.hpp b/src/mlpack/methods/ann/init_rules/gaussian_init.hpp index 95021624e4..7a9f82dc86 100644 --- a/src/mlpack/methods/ann/init_rules/gaussian_init.hpp +++ b/src/mlpack/methods/ann/init_rules/gaussian_init.hpp @@ -75,7 +75,7 @@ class GaussianInitialization { W = arma::Cube(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/init_rules/glorot_init.hpp b/src/mlpack/methods/ann/init_rules/glorot_init.hpp index fb1ff7e5a6..b528b14327 100644 --- a/src/mlpack/methods/ann/init_rules/glorot_init.hpp +++ b/src/mlpack/methods/ann/init_rules/glorot_init.hpp @@ -131,7 +131,7 @@ inline void GlorotInitializationType::Initialize(arma::Cube& W, { W = arma::cube(rows, cols, slices); } - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/init_rules/he_init.hpp b/src/mlpack/methods/ann/init_rules/he_init.hpp index adb6c87bb5..3ee43a0f85 100644 --- a/src/mlpack/methods/ann/init_rules/he_init.hpp +++ b/src/mlpack/methods/ann/init_rules/he_init.hpp @@ -95,7 +95,7 @@ class HeInitialization if (W.is_empty()) W.set_size(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } }; // class HeInitialization diff --git a/src/mlpack/methods/ann/init_rules/kathirvalavakumar_subavathi_init.hpp b/src/mlpack/methods/ann/init_rules/kathirvalavakumar_subavathi_init.hpp index ec1a361e03..1c011b4e49 100644 --- a/src/mlpack/methods/ann/init_rules/kathirvalavakumar_subavathi_init.hpp +++ b/src/mlpack/methods/ann/init_rules/kathirvalavakumar_subavathi_init.hpp @@ -107,7 +107,7 @@ class KathirvalavakumarSubavathiInitialization { W = arma::Cube(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/init_rules/lecun_normal_init.hpp b/src/mlpack/methods/ann/init_rules/lecun_normal_init.hpp index 30ffa8065d..846b4cd46a 100644 --- a/src/mlpack/methods/ann/init_rules/lecun_normal_init.hpp +++ b/src/mlpack/methods/ann/init_rules/lecun_normal_init.hpp @@ -101,7 +101,7 @@ class LecunNormalInitialization if (W.is_empty()) W.set_size(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } }; // class LecunNormalInitialization diff --git a/src/mlpack/methods/ann/init_rules/nguyen_widrow_init.hpp b/src/mlpack/methods/ann/init_rules/nguyen_widrow_init.hpp index 93d949e699..8e229fdda7 100644 --- a/src/mlpack/methods/ann/init_rules/nguyen_widrow_init.hpp +++ b/src/mlpack/methods/ann/init_rules/nguyen_widrow_init.hpp @@ -99,7 +99,7 @@ class NguyenWidrowInitialization { W = arma::Cube(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/init_rules/oivs_init.hpp b/src/mlpack/methods/ann/init_rules/oivs_init.hpp index 9f9ac368d2..d8c7c7ad33 100644 --- a/src/mlpack/methods/ann/init_rules/oivs_init.hpp +++ b/src/mlpack/methods/ann/init_rules/oivs_init.hpp @@ -108,7 +108,7 @@ class OivsInitialization { W = arma::Cube(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/init_rules/orthogonal_init.hpp b/src/mlpack/methods/ann/init_rules/orthogonal_init.hpp index 75090f3d13..8714e2436a 100644 --- a/src/mlpack/methods/ann/init_rules/orthogonal_init.hpp +++ b/src/mlpack/methods/ann/init_rules/orthogonal_init.hpp @@ -66,7 +66,7 @@ class OrthogonalInitialization { W = arma::Cube(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/init_rules/random_init.hpp b/src/mlpack/methods/ann/init_rules/random_init.hpp index c336a5cb8d..16e4556574 100644 --- a/src/mlpack/methods/ann/init_rules/random_init.hpp +++ b/src/mlpack/methods/ann/init_rules/random_init.hpp @@ -75,7 +75,7 @@ class RandomInitialization { W = arma::Cube(rows, cols, slices); - for (size_t i = 0; i < slices; i++) + for (size_t i = 0; i < slices; ++i) Initialize(W.slice(i), rows, cols); } diff --git a/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp b/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp index 0d2f240cdb..3536690037 100644 --- a/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp +++ b/src/mlpack/methods/ann/layer/atrous_convolution_impl.hpp @@ -368,13 +368,13 @@ void AtrousConvolution< if (dilationHeight > 1) { - for (size_t i = 1; i < output.n_cols; i++){ + for (size_t i = 1; i < output.n_cols; ++i){ output.shed_cols(i, i + dilationHeight - 2); } } if (dilationWidth > 1) { - for (size_t i = 1; i < output.n_rows; i++){ + for (size_t i = 1; i < output.n_rows; ++i){ output.shed_rows(i, i + dilationWidth - 2); } } diff --git a/src/mlpack/methods/ann/layer/batch_norm_impl.hpp b/src/mlpack/methods/ann/layer/batch_norm_impl.hpp index cbb78a26a4..11559a65df 100644 --- a/src/mlpack/methods/ann/layer/batch_norm_impl.hpp +++ b/src/mlpack/methods/ann/layer/batch_norm_impl.hpp @@ -85,7 +85,7 @@ void BatchNorm::Forward( output.each_col() /= arma::sqrt(variance + eps); // Use Welford method to compute the sample variance and mean. - for (size_t i = 0; i < input.n_cols; i++) + for (size_t i = 0; i < input.n_cols; ++i) { count += 1; diff --git a/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp b/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp index 5c958e6156..ff7c566a2c 100644 --- a/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp +++ b/src/mlpack/methods/ann/layer/bilinear_interpolation_impl.hpp @@ -77,7 +77,7 @@ void BilinearInterpolation::Forward( double scaleCol = (double) inColSize / (double) outColSize; arma::mat22 coeffs; - for (size_t i = 0; i < outRowSize; i++) + for (size_t i = 0; i < outRowSize; ++i) { size_t rOrigin = (size_t) std::floor(i * scaleRow); if (rOrigin > inRowSize - 2) @@ -87,7 +87,7 @@ void BilinearInterpolation::Forward( double deltaR = i * scaleRow - rOrigin; if (deltaR > 1) deltaR = 1.0; - for (size_t j = 0; j < outColSize; j++) + for (size_t j = 0; j < outColSize; ++j) { // Scaled distance of the interpolated point from the leftmost column. size_t cOrigin = (size_t) std::floor(j * scaleCol); @@ -102,7 +102,7 @@ void BilinearInterpolation::Forward( coeffs[2] = (1 - deltaR) * deltaC; coeffs[3] = deltaR * deltaC; - for (size_t k = 0; k < depth * batchSize; k++) + for (size_t k = 0; k < depth * batchSize; ++k) { outputAsCube(i, j, k) = arma::accu(inputAsCube.slice(k).submat( rOrigin, cOrigin, rOrigin + 1, cOrigin + 1) % coeffs); @@ -144,13 +144,13 @@ void BilinearInterpolation::Backward( double scaleCol = (double)(outColSize) / inColSize; arma::mat22 coeffs; - for (size_t i = 0; i < inRowSize; i++) + for (size_t i = 0; i < inRowSize; ++i) { size_t rOrigin = (size_t) std::floor(i * scaleRow); if (rOrigin > outRowSize - 2) rOrigin = outRowSize - 2; double deltaR = i * scaleRow - rOrigin; - for (size_t j = 0; j < inColSize; j++) + for (size_t j = 0; j < inColSize; ++j) { size_t cOrigin = (size_t) std::floor(j * scaleCol); @@ -163,7 +163,7 @@ void BilinearInterpolation::Backward( coeffs[2] = (1 - deltaR) * deltaC; coeffs[3] = deltaR * deltaC; - for (size_t k = 0; k < depth * batchSize; k++) + for (size_t k = 0; k < depth * batchSize; ++k) { outputAsCube(i, j, k) = arma::accu(gradientAsCube.slice(k).submat( rOrigin, cOrigin, rOrigin + 1, cOrigin + 1) % coeffs); diff --git a/src/mlpack/methods/ann/layer/celu_impl.hpp b/src/mlpack/methods/ann/layer/celu_impl.hpp index 09a2cc76f5..b3b396f91e 100644 --- a/src/mlpack/methods/ann/layer/celu_impl.hpp +++ b/src/mlpack/methods/ann/layer/celu_impl.hpp @@ -36,7 +36,7 @@ void CELU::Forward( const InputType& input, OutputType& output) { output = arma::ones(arma::size(input)); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { output(i) = (input(i) >= 0) ? input(i) : alpha * (std::exp(input(i) / alpha) - 1); @@ -45,7 +45,7 @@ void CELU::Forward( if (!deterministic) { derivative.set_size(arma::size(input)); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { derivative(i) = (input(i) >= 0) ? 1 : (output(i) / alpha) + 1; diff --git a/src/mlpack/methods/ann/layer/concat_performance_impl.hpp b/src/mlpack/methods/ann/layer/concat_performance_impl.hpp index 65a37ded79..40dfeb0a5b 100644 --- a/src/mlpack/methods/ann/layer/concat_performance_impl.hpp +++ b/src/mlpack/methods/ann/layer/concat_performance_impl.hpp @@ -83,7 +83,7 @@ void ConcatPerformance< output = arma::zeros(subOutput.n_elem, inSize); output.col(0) = subOutput; - for (size_t i = elements, j = 0; i < input.n_elem; i+= elements, j++) + for (size_t i = elements, j = 0; i < input.n_elem; i+= elements, ++j) { subInput = input.submat(i, 0, i + elements - 1, 0); outputLayer.Backward(subInput, target, subOutput); diff --git a/src/mlpack/methods/ann/layer/elu_impl.hpp b/src/mlpack/methods/ann/layer/elu_impl.hpp index c19f404570..3ccc76d054 100644 --- a/src/mlpack/methods/ann/layer/elu_impl.hpp +++ b/src/mlpack/methods/ann/layer/elu_impl.hpp @@ -52,7 +52,7 @@ void ELU::Forward( const InputType& input, OutputType& output) { output = arma::ones(arma::size(input)); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { if (input(i) < DBL_MAX) { @@ -64,7 +64,7 @@ void ELU::Forward( if (!deterministic) { derivative.set_size(arma::size(input)); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { derivative(i) = (input(i) > 0) ? lambda : output(i) + lambda * alpha; diff --git a/src/mlpack/methods/ann/layer/glimpse.hpp b/src/mlpack/methods/ann/layer/glimpse.hpp index b77c8f42de..1017fd4fe2 100644 --- a/src/mlpack/methods/ann/layer/glimpse.hpp +++ b/src/mlpack/methods/ann/layer/glimpse.hpp @@ -198,9 +198,9 @@ class Glimpse { arma::mat t = w; - for (size_t i = 0, k = 0; i < w.n_elem; k++) + for (size_t i = 0, k = 0; i < w.n_elem; ++k) { - for (size_t j = 0; j < w.n_cols; j++, i++) + for (size_t j = 0; j < w.n_cols; ++j, ++i) { w(k, j) = t(i); } @@ -214,7 +214,7 @@ class Glimpse */ void Transform(arma::cube& w) { - for (size_t i = 0; i < w.n_slices; i++) + for (size_t i = 0; i < w.n_slices; ++i) { arma::mat t = w.slice(i); Transform(t); diff --git a/src/mlpack/methods/ann/layer/glimpse_impl.hpp b/src/mlpack/methods/ann/layer/glimpse_impl.hpp index 187f3c0d37..a49bee475d 100644 --- a/src/mlpack/methods/ann/layer/glimpse_impl.hpp +++ b/src/mlpack/methods/ann/layer/glimpse_impl.hpp @@ -138,9 +138,9 @@ void Glimpse::Backward( location = locationParameter.back(); locationParameter.pop_back(); - for (size_t s = 0, j = 0; s < mappedError.n_slices; s+= gy.n_cols, j++) + for (size_t s = 0, j = 0; s < mappedError.n_slices; s+= gy.n_cols, ++j) { - for (size_t i = 0; i < gy.n_cols; i++) + for (size_t i = 0; i < gy.n_cols; ++i) { mappedError.slice(s + i) = arma::Mat(gy.memptr(), outputWidth, outputHeight); diff --git a/src/mlpack/methods/ann/layer/hard_tanh_impl.hpp b/src/mlpack/methods/ann/layer/hard_tanh_impl.hpp index a318a369c0..16f361a6a1 100644 --- a/src/mlpack/methods/ann/layer/hard_tanh_impl.hpp +++ b/src/mlpack/methods/ann/layer/hard_tanh_impl.hpp @@ -34,7 +34,7 @@ void HardTanH::Forward( const InputType& input, OutputType& output) { output = input; - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { output(i) = (output(i) > maxValue ? maxValue : (output(i) < minValue ? minValue : output(i))); @@ -47,7 +47,7 @@ void HardTanH::Backward( const DataType& input, const DataType& gy, DataType& g) { g = gy; - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { if (input(i) < minValue || input(i) > maxValue) { diff --git a/src/mlpack/methods/ann/layer/leaky_relu_impl.hpp b/src/mlpack/methods/ann/layer/leaky_relu_impl.hpp index 75605a0197..9469fa9374 100644 --- a/src/mlpack/methods/ann/layer/leaky_relu_impl.hpp +++ b/src/mlpack/methods/ann/layer/leaky_relu_impl.hpp @@ -42,7 +42,7 @@ void LeakyReLU::Backward( { DataType derivative; derivative.set_size(arma::size(input)); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) derivative(i) = (input(i) >= 0) ? 1 : alpha; g = gy % derivative; diff --git a/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp b/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp index aa337afbb5..5e3e283406 100644 --- a/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp +++ b/src/mlpack/methods/ann/layer/minibatch_discrimination_impl.hpp @@ -60,10 +60,10 @@ void MiniBatchDiscrimination::Forward( distances.set_size(B, batchSize, batchSize); output.set_size(B, batchSize); - for (size_t i = 0; i < M.n_slices; i++) + for (size_t i = 0; i < M.n_slices; ++i) { output.col(i).ones(); - for (size_t j = 0; j < M.n_slices; j++) + for (size_t j = 0; j < M.n_slices; ++j) { if (j < i) { @@ -94,9 +94,9 @@ void MiniBatchDiscrimination::Backward( arma::Mat gM = gy.tail_rows(B); deltaM.zeros(B, C, batchSize); - for (size_t i = 0; i < M.n_slices; i++) + for (size_t i = 0; i < M.n_slices; ++i) { - for (size_t j = 0; j < M.n_slices; j++) + for (size_t j = 0; j < M.n_slices; ++j) { if (i == j) { diff --git a/src/mlpack/methods/ann/layer/parametric_relu_impl.hpp b/src/mlpack/methods/ann/layer/parametric_relu_impl.hpp index 662f38415b..8732c1e0a0 100644 --- a/src/mlpack/methods/ann/layer/parametric_relu_impl.hpp +++ b/src/mlpack/methods/ann/layer/parametric_relu_impl.hpp @@ -53,7 +53,7 @@ void PReLU::Backward( { DataType derivative; derivative.set_size(arma::size(input)); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { derivative(i) = (input(i) >= 0) ? 1 : alpha(0); } diff --git a/src/mlpack/methods/ann/layer/subview.hpp b/src/mlpack/methods/ann/layer/subview.hpp index 7315fc3127..b8d2f27d8b 100644 --- a/src/mlpack/methods/ann/layer/subview.hpp +++ b/src/mlpack/methods/ann/layer/subview.hpp @@ -86,7 +86,7 @@ class Subview if ((input.n_rows != ((endRow - beginRow + 1) * (endCol - beginCol + 1))) || (input.n_cols != batchSize)) { - for (size_t i = 0; i < batchSize; i++) + for (size_t i = 0; i < batchSize; ++i) { output.col(i) = arma::vectorise( input.submat(beginRow, batchBegin, endRow, batchEnd)); diff --git a/src/mlpack/methods/ann/layer/vr_class_reward_impl.hpp b/src/mlpack/methods/ann/layer/vr_class_reward_impl.hpp index 1224b8c006..1b6cf203d3 100644 --- a/src/mlpack/methods/ann/layer/vr_class_reward_impl.hpp +++ b/src/mlpack/methods/ann/layer/vr_class_reward_impl.hpp @@ -49,7 +49,7 @@ double VRClassReward::Forward( reward = 0; arma::uword index = 0; - for (size_t i = 0; i < input.n_cols - 1; i++) + for (size_t i = 0; i < input.n_cols - 1; ++i) { input.unsafe_col(i).max(index); reward = ((index + 1) == target(i)) * scale; diff --git a/src/mlpack/methods/ann/rbm/rbm_impl.hpp b/src/mlpack/methods/ann/rbm/rbm_impl.hpp index 306a6c4954..79122b12d0 100644 --- a/src/mlpack/methods/ann/rbm/rbm_impl.hpp +++ b/src/mlpack/methods/ann/rbm/rbm_impl.hpp @@ -169,7 +169,7 @@ RBM::SampleHidden( { HiddenMean(std::move(input), std::move(output)); - for (size_t i = 0; i < output.n_elem; i++) + for (size_t i = 0; i < output.n_elem; ++i) { output(i) = math::RandBernoulli(output(i)); } @@ -188,7 +188,7 @@ RBM::SampleVisible( { VisibleMean(std::move(input), std::move(output)); - for (size_t i = 0; i < output.n_elem; i++) + for (size_t i = 0; i < output.n_elem; ++i) { output(i) = math::RandBernoulli(output(i)); } @@ -247,7 +247,7 @@ void RBM::Gibbs( SampleVisible(std::move(gibbsTemporary), std::move(output)); } - for (size_t j = 1; j < this->steps; j++) + for (size_t j = 1; j < this->steps; ++j) { SampleHidden(std::move(output), std::move(gibbsTemporary)); SampleVisible(std::move(gibbsTemporary), std::move(output)); @@ -275,7 +275,7 @@ void RBM::Gradient( Phase(std::move(predictors.cols(i, i + batchSize - 1)), std::move(positiveGradient)); - for (size_t i = 0; i < negSteps; i++) + for (size_t i = 0; i < negSteps; ++i) { Gibbs(std::move(predictors.cols(i, i + batchSize - 1)), std::move(negativeSamples)); diff --git a/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp b/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp index f3353c7b61..a116e813fc 100644 --- a/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp +++ b/src/mlpack/methods/ann/rbm/spike_slab_rbm_impl.hpp @@ -75,7 +75,7 @@ RBM::FreeEnergy( freeEnergy -= 0.5 * hiddenSize * poolSize * std::log((2.0 * M_PI) / slabPenalty); - for (size_t i = 0; i < hiddenSize; i++) + for (size_t i = 0; i < hiddenSize; ++i) { ElemType sum = arma::accu(arma::square(input.t() * weight.slice(i))) / (2.0 * slabPenalty); @@ -109,7 +109,7 @@ RBM::Phase( SampleSpike(std::move(spikeMean), std::move(spikeSamples)); SlabMean(std::move(input), std::move(spikeSamples), std::move(slabMean)); - for (size_t i = 0 ; i < hiddenSize; i++) + for (size_t i = 0 ; i < hiddenSize; ++i) { weightGrad.slice(i) = input * arma::repmat(slabMean.col(i).t(), input.n_cols, 1) * spikeMean(i); @@ -161,9 +161,9 @@ RBM::SampleVisible( VisibleMean(std::move(input), std::move(visibleMean)); output.set_size(visibleSize, 1); - for (k = 0; k < numMaxTrials; k++) + for (k = 0; k < numMaxTrials; ++k) { - for (size_t i = 0; i < visibleSize; i++) + for (size_t i = 0; i < visibleSize; ++i) { output(i) = math::RandNormal(visibleMean(i), 1.0 / visiblePenalty(0)); } @@ -199,7 +199,7 @@ RBM::VisibleMean( DataType slab(input.memptr() + hiddenSize, poolSize, hiddenSize, false, false); - for (size_t i = 0; i < hiddenSize; i++) + for (size_t i = 0; i < hiddenSize; ++i) { output += weight.slice(i) * slab.col(i) * spike(i); } @@ -240,7 +240,7 @@ RBM::SpikeMean( DataType&& visible, DataType&& spikeMean) { - for (size_t i = 0; i < hiddenSize; i++) + for (size_t i = 0; i < hiddenSize; ++i) { spikeMean(i) = LogisticFunction::Fn(0.5 * (1.0 / slabPenalty) * arma::accu( visible.t() * (weight.slice(i) * weight.slice(i).t()) * visible) @@ -259,7 +259,7 @@ RBM::SampleSpike( DataType&& spikeMean, DataType&& spike) { - for (size_t i = 0; i < hiddenSize; i++) + for (size_t i = 0; i < hiddenSize; ++i) { spike(i) = math::RandBernoulli(spikeMean(i)); } @@ -277,7 +277,7 @@ RBM::SlabMean( DataType&& spike, DataType&& slabMean) { - for (size_t i = 0; i < hiddenSize; i++) + for (size_t i = 0; i < hiddenSize; ++i) { slabMean.col(i) = arma::mean((1.0 / slabPenalty) * spike(i) * weight.slice(i).t() * visible, 1); @@ -295,9 +295,9 @@ RBM::SampleSlab( DataType&& slabMean, DataType&& slab) { - for (size_t i = 0; i < hiddenSize; i++) + for (size_t i = 0; i < hiddenSize; ++i) { - for (size_t j = 0; j < poolSize; j++) + for (size_t j = 0; j < poolSize; ++j) { slab(j, i) = math::RandNormal(slabMean(j, i), 1.0 / slabPenalty); } diff --git a/src/mlpack/methods/ann/regularizer/orthogonal_regularizer_impl.hpp b/src/mlpack/methods/ann/regularizer/orthogonal_regularizer_impl.hpp index c1f640ff71..415ec71624 100644 --- a/src/mlpack/methods/ann/regularizer/orthogonal_regularizer_impl.hpp +++ b/src/mlpack/methods/ann/regularizer/orthogonal_regularizer_impl.hpp @@ -29,9 +29,9 @@ void OrthogonalRegularizer::Evaluate(const MatType& weight, MatType& gradient) { arma::mat grad = arma::zeros(arma::size(weight)); - for (size_t i = 0; i < weight.n_rows; i++) + for (size_t i = 0; i < weight.n_rows; ++i) { - for (size_t j = 0; j < weight.n_rows; j++) + for (size_t j = 0; j < weight.n_rows; ++j) { if (i == j) { diff --git a/src/mlpack/methods/bias_svd/bias_svd_function_impl.hpp b/src/mlpack/methods/bias_svd/bias_svd_function_impl.hpp index 4024729750..e18e7393ad 100644 --- a/src/mlpack/methods/bias_svd/bias_svd_function_impl.hpp +++ b/src/mlpack/methods/bias_svd/bias_svd_function_impl.hpp @@ -108,7 +108,7 @@ void BiasSVDFunction::Gradient(const arma::mat& parameters, gradient.zeros(rank + 1, numUsers + numItems); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { // Indices for accessing the the correct parameter columns. const size_t user = data(0, i); @@ -198,7 +198,7 @@ double StandardSGD::Optimize( double overallObjective = 0; // Calculate the first objective function. - for (size_t i = 0; i < numFunctions; i++) + for (size_t i = 0; i < numFunctions; ++i) overallObjective += function.Evaluate(parameters, i); const arma::mat data = function.Dataset(); @@ -207,7 +207,7 @@ double StandardSGD::Optimize( const size_t rank = function.Rank(); // Now iterate! - for (size_t i = 1; i != maxIterations; i++, currentFunction++) + for (size_t i = 1; i != maxIterations; ++i, currentFunction++) { // Is this iteration the start of a sequence? if ((currentFunction % numFunctions) == 0) diff --git a/src/mlpack/methods/cf/cf_impl.hpp b/src/mlpack/methods/cf/cf_impl.hpp index 82ad7e06c0..89059d56bd 100644 --- a/src/mlpack/methods/cf/cf_impl.hpp +++ b/src/mlpack/methods/cf/cf_impl.hpp @@ -210,7 +210,7 @@ GetRecommendations(const size_t numRecs, // time and we don't want to repeat the initialization process in each loop. InterpolationPolicy interpolation(cleanedData); - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) { // First, calculate the weighted sum of neighborhood values. arma::vec ratings; @@ -355,7 +355,7 @@ Predict(const arma::Mat& combinations, // Calculate interpolation weights. InterpolationPolicy interpolation(cleanedData); - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) { interpolation.GetWeights(weights.col(i), decomposition, users[i], neighborhood.col(i), similarities.col(i), cleanedData); diff --git a/src/mlpack/methods/cf/decomposition_policies/batch_svd_method.hpp b/src/mlpack/methods/cf/decomposition_policies/batch_svd_method.hpp index 4acf3679e4..00f32084b8 100644 --- a/src/mlpack/methods/cf/decomposition_policies/batch_svd_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/batch_svd_method.hpp @@ -138,7 +138,7 @@ class BatchSVDPolicy // Temporarily store feature vector of queried users. arma::mat query(stretchedH.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = stretchedH.col(users(i)); NeighborSearchPolicy neighborSearch(stretchedH); diff --git a/src/mlpack/methods/cf/decomposition_policies/bias_svd_method.hpp b/src/mlpack/methods/cf/decomposition_policies/bias_svd_method.hpp index ae90639103..9ca80aebfc 100644 --- a/src/mlpack/methods/cf/decomposition_policies/bias_svd_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/bias_svd_method.hpp @@ -128,7 +128,7 @@ class BiasSVDPolicy // Temporarily store feature vector of queried users. arma::mat query(h.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = h.col(users(i)); NeighborSearchPolicy neighborSearch(h); diff --git a/src/mlpack/methods/cf/decomposition_policies/nmf_method.hpp b/src/mlpack/methods/cf/decomposition_policies/nmf_method.hpp index a2489e62b6..5f8a601357 100644 --- a/src/mlpack/methods/cf/decomposition_policies/nmf_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/nmf_method.hpp @@ -135,7 +135,7 @@ class NMFPolicy // Temporarily store feature vector of queried users. arma::mat query(stretchedH.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = stretchedH.col(users(i)); NeighborSearchPolicy neighborSearch(stretchedH); diff --git a/src/mlpack/methods/cf/decomposition_policies/randomized_svd_method.hpp b/src/mlpack/methods/cf/decomposition_policies/randomized_svd_method.hpp index 88fa96ed1f..6fbd966e9e 100644 --- a/src/mlpack/methods/cf/decomposition_policies/randomized_svd_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/randomized_svd_method.hpp @@ -144,7 +144,7 @@ class RandomizedSVDPolicy // Temporarily store feature vector of queried users. arma::mat query(stretchedH.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = stretchedH.col(users(i)); NeighborSearchPolicy neighborSearch(stretchedH); diff --git a/src/mlpack/methods/cf/decomposition_policies/regularized_svd_method.hpp b/src/mlpack/methods/cf/decomposition_policies/regularized_svd_method.hpp index d189fc0740..b39769dd07 100644 --- a/src/mlpack/methods/cf/decomposition_policies/regularized_svd_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/regularized_svd_method.hpp @@ -131,7 +131,7 @@ class RegSVDPolicy // Temporarily store feature vector of queried users. arma::mat query(stretchedH.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = stretchedH.col(users(i)); NeighborSearchPolicy neighborSearch(stretchedH); diff --git a/src/mlpack/methods/cf/decomposition_policies/svd_complete_method.hpp b/src/mlpack/methods/cf/decomposition_policies/svd_complete_method.hpp index acdf84c4c9..6f36383d5d 100644 --- a/src/mlpack/methods/cf/decomposition_policies/svd_complete_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/svd_complete_method.hpp @@ -141,7 +141,7 @@ class SVDCompletePolicy // Temporarily store feature vector of queried users. arma::mat query(stretchedH.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = stretchedH.col(users(i)); NeighborSearchPolicy neighborSearch(stretchedH); diff --git a/src/mlpack/methods/cf/decomposition_policies/svd_incomplete_method.hpp b/src/mlpack/methods/cf/decomposition_policies/svd_incomplete_method.hpp index ef644fed89..5ad4a00071 100644 --- a/src/mlpack/methods/cf/decomposition_policies/svd_incomplete_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/svd_incomplete_method.hpp @@ -140,7 +140,7 @@ class SVDIncompletePolicy // Temporarily store feature vector of queried users. arma::mat query(stretchedH.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = stretchedH.col(users(i)); NeighborSearchPolicy neighborSearch(stretchedH); diff --git a/src/mlpack/methods/cf/decomposition_policies/svdplusplus_method.hpp b/src/mlpack/methods/cf/decomposition_policies/svdplusplus_method.hpp index 0718398101..881f2a98ac 100644 --- a/src/mlpack/methods/cf/decomposition_policies/svdplusplus_method.hpp +++ b/src/mlpack/methods/cf/decomposition_policies/svdplusplus_method.hpp @@ -163,7 +163,7 @@ class SVDPlusPlusPolicy // Temporarily store feature vector of queried users. arma::mat query(h.n_rows, users.n_elem); // Select feature vectors of queried users. - for (size_t i = 0; i < users.n_elem; i++) + for (size_t i = 0; i < users.n_elem; ++i) query.col(i) = h.col(users(i)); NeighborSearchPolicy neighborSearch(h); diff --git a/src/mlpack/methods/cf/interpolation_policies/regression_interpolation.hpp b/src/mlpack/methods/cf/interpolation_policies/regression_interpolation.hpp index 6c9cdebb96..cfd181ca82 100644 --- a/src/mlpack/methods/cf/interpolation_policies/regression_interpolation.hpp +++ b/src/mlpack/methods/cf/interpolation_policies/regression_interpolation.hpp @@ -126,11 +126,11 @@ class RegressionInterpolation return; } - for (size_t i = 0; i < neighborNum; i++) + for (size_t i = 0; i < neighborNum; ++i) { // Calculate coefficient. arma::vec iPrediction; - for (size_t j = i; j < neighborNum; j++) + for (size_t j = i; j < neighborNum; ++j) { if (a(neighbors(i), neighbors(j)) != 0) { diff --git a/src/mlpack/methods/cf/normalization/item_mean_normalization.hpp b/src/mlpack/methods/cf/normalization/item_mean_normalization.hpp index c47202b135..5933a260c8 100644 --- a/src/mlpack/methods/cf/normalization/item_mean_normalization.hpp +++ b/src/mlpack/methods/cf/normalization/item_mean_normalization.hpp @@ -65,7 +65,7 @@ class ItemMeanNormalization // Calculate item mean and subtract item mean from ratings. // Set item mean to 0 if the item has no rating. - for (size_t i = 0; i < itemNum; i++) + for (size_t i = 0; i < itemNum; ++i) { if (ratingNum(i) != 0) itemMean(i) /= ratingNum(i); @@ -99,7 +99,7 @@ class ItemMeanNormalization itemMean(it.row()) += *it; ratingNum(it.row()) += 1; } - for (size_t i = 0; i < itemMean.n_elem; i++) + for (size_t i = 0; i < itemMean.n_elem; ++i) { if (ratingNum(i) != 0) itemMean(i) /= ratingNum(i); @@ -143,7 +143,7 @@ class ItemMeanNormalization void Denormalize(const arma::Mat& combinations, arma::vec& predictions) const { - for (size_t i = 0; i < predictions.n_elem; i++) + for (size_t i = 0; i < predictions.n_elem; ++i) { const size_t item = combinations(1, i); predictions(i) += itemMean(item); diff --git a/src/mlpack/methods/cf/normalization/user_mean_normalization.hpp b/src/mlpack/methods/cf/normalization/user_mean_normalization.hpp index 28ff309d74..423d624aaf 100644 --- a/src/mlpack/methods/cf/normalization/user_mean_normalization.hpp +++ b/src/mlpack/methods/cf/normalization/user_mean_normalization.hpp @@ -65,7 +65,7 @@ class UserMeanNormalization // Calculate user mean and subtract user mean from ratings. // Set user mean to 0 if the user has no rating. - for (size_t i = 0; i < userNum; i++) + for (size_t i = 0; i < userNum; ++i) { if (ratingNum(i) != 0) userMean(i) /= ratingNum(i); @@ -99,7 +99,7 @@ class UserMeanNormalization userMean(it.col()) += *it; ratingNum(it.col()) += 1; } - for (size_t i = 0; i < userMean.n_elem; i++) + for (size_t i = 0; i < userMean.n_elem; ++i) { if (ratingNum(i) != 0) userMean(i) /= ratingNum(i); @@ -143,7 +143,7 @@ class UserMeanNormalization void Denormalize(const arma::Mat& combinations, arma::vec& predictions) const { - for (size_t i = 0; i < predictions.n_elem; i++) + for (size_t i = 0; i < predictions.n_elem; ++i) { const size_t user = combinations(0, i); predictions(i) += userMean(user); diff --git a/src/mlpack/methods/cf/svd_wrapper_impl.hpp b/src/mlpack/methods/cf/svd_wrapper_impl.hpp index 22794505c1..6f0ef600a5 100644 --- a/src/mlpack/methods/cf/svd_wrapper_impl.hpp +++ b/src/mlpack/methods/cf/svd_wrapper_impl.hpp @@ -32,7 +32,7 @@ double SVDWrapper::Apply(const arma::mat& V, // construct sigma matrix sigma.zeros(V.n_rows, V.n_cols); - for (size_t i = 0; i < sigma.n_rows && i < sigma.n_cols; i++) + for (size_t i = 0; i < sigma.n_rows && i < sigma.n_cols; ++i) sigma(i, i) = E(i, 0); arma::mat V_rec = W * sigma * arma::trans(H); @@ -54,7 +54,7 @@ double SVDWrapper::Apply(const arma::mat& V, // construct sigma matrix sigma.zeros(V.n_rows, V.n_cols); - for (size_t i = 0; i < sigma.n_rows && i < sigma.n_cols; i++) + for (size_t i = 0; i < sigma.n_rows && i < sigma.n_cols; ++i) sigma(i, i) = E(i, 0); arma::mat V_rec = W * sigma * arma::trans(H); diff --git a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp index b99bdc44c8..bed56cdaa4 100644 --- a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp +++ b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp @@ -108,7 +108,7 @@ double DecisionStump::Train(const MatType& data, const double rootEntropy = CalculateEntropy(labels, weights); double gain, bestGain = 0.0; - for (size_t i = 0; i < data.n_rows; i++) + for (size_t i = 0; i < data.n_rows; ++i) { // Go through each dimension of the data. if (IsDistinct(data.row(i))) @@ -150,7 +150,7 @@ void DecisionStump::Classify(const MatType& test, arma::Row& predictedLabels) { predictedLabels.set_size(test.n_cols); - for (size_t i = 0; i < test.n_cols; i++) + for (size_t i = 0; i < test.n_cols; ++i) { // Determine which bin the test point falls into. // Assume first that it falls into the first bin, then proceed through the @@ -236,7 +236,7 @@ double DecisionStump::SetupSplitDimension( arma::Row sortedLabels(dimension.n_elem); arma::rowvec sortedWeights(dimension.n_elem); - for (i = 0; i < dimension.n_elem; i++) + for (i = 0; i < dimension.n_elem; ++i) { sortedLabels(i) = labels(sortedIndexDim(i)); @@ -265,7 +265,7 @@ double DecisionStump::SetupSplitDimension( entropy += ratioEl * CalculateEntropy( sortedLabels.subvec(begin, end), sortedWeights.subvec(begin, end)); - i++; + ++i; } else if (sortedLabels(i) != sortedLabels(i + 1)) { @@ -297,7 +297,7 @@ double DecisionStump::SetupSplitDimension( count = 0; } else - i++; + ++i; } return entropy; } @@ -321,7 +321,7 @@ void DecisionStump::TrainOnDim(const VecType& dimension, arma::Row sortedLabels(dimension.n_elem); sortedLabels.fill(0); - for (i = 0; i < dimension.n_elem; i++) + for (i = 0; i < dimension.n_elem; ++i) sortedLabels(i) = labels(sortedSplitIndexDim(i)); arma::rowvec subCols; @@ -343,7 +343,7 @@ void DecisionStump::TrainOnDim(const VecType& dimension, binLabels.resize(binLabels.n_elem + 1); binLabels(binLabels.n_elem - 1) = mostFreq; - i++; + ++i; } else if (sortedLabels(i) != sortedLabels(i + 1)) { @@ -375,7 +375,7 @@ void DecisionStump::TrainOnDim(const VecType& dimension, count = 0; } else - i++; + ++i; } // Now trim the split matrix so that buckets one after the after which point @@ -390,7 +390,7 @@ void DecisionStump::TrainOnDim(const VecType& dimension, template void DecisionStump::MergeRanges() { - for (size_t i = 1; i < split.n_rows; i++) + for (size_t i = 1; i < split.n_rows; ++i) { if (binLabels(i) == binLabels(i - 1)) { @@ -477,13 +477,13 @@ double DecisionStump::CalculateEntropy( if (UseWeights) { - for (j = 0; j < labels.n_elem; j++) + for (j = 0; j < labels.n_elem; ++j) { numElem(labels(j)) += weights(j); accWeight += weights(j); } - for (j = 0; j < numClasses; j++) + for (j = 0; j < numClasses; ++j) { const double p1 = ((double) numElem(j) / accWeight); @@ -495,10 +495,10 @@ double DecisionStump::CalculateEntropy( } else { - for (j = 0; j < labels.n_elem; j++) + for (j = 0; j < labels.n_elem; ++j) numElem(labels(j))++; - for (j = 0; j < numClasses; j++) + for (j = 0; j < numClasses; ++j) { const double p1 = ((double) numElem(j) / labels.n_elem); diff --git a/src/mlpack/methods/det/det_main.cpp b/src/mlpack/methods/det/det_main.cpp index cf893f2f9c..afb26d2f03 100644 --- a/src/mlpack/methods/det/det_main.cpp +++ b/src/mlpack/methods/det/det_main.cpp @@ -173,7 +173,7 @@ static void mlpackMain() // Compute density estimates for each point in the training set. arma::rowvec trainingDensities(trainingData.n_cols); Timer::Start("det_estimation_time"); - for (size_t i = 0; i < trainingData.n_cols; i++) + for (size_t i = 0; i < trainingData.n_cols; ++i) trainingDensities[i] = tree->ComputeValue(trainingData.unsafe_col(i)); Timer::Stop("det_estimation_time"); @@ -197,7 +197,7 @@ static void mlpackMain() Timer::Start("det_test_set_estimation"); arma::rowvec testDensities(testData.n_cols); - for (size_t i = 0; i < testData.n_cols; i++) + for (size_t i = 0; i < testData.n_cols; ++i) testDensities[i] = tree->ComputeValue(testData.unsafe_col(i)); Timer::Stop("det_test_set_estimation"); @@ -252,7 +252,7 @@ static void mlpackMain() PathCacher path(theFormat, tree); counters.zeros(path.NumNodes()); - for (size_t i = 0; i < estimationData.n_cols; i++) + for (size_t i = 0; i < estimationData.n_cols; ++i) { int tag = tree->FindBucket(estimationData.unsafe_col(i)); @@ -281,7 +281,7 @@ static void mlpackMain() int numLeaves = tree->TagTree(); counters.zeros(numLeaves); - for (size_t i = 0; i < estimationData.n_cols; i++) + for (size_t i = 0; i < estimationData.n_cols; ++i) { const int tag = tree->FindBucket(estimationData.unsafe_col(i)); diff --git a/src/mlpack/methods/det/dt_utils_impl.hpp b/src/mlpack/methods/det/dt_utils_impl.hpp index 3ccc046a57..95542346c0 100644 --- a/src/mlpack/methods/det/dt_utils_impl.hpp +++ b/src/mlpack/methods/det/dt_utils_impl.hpp @@ -32,7 +32,7 @@ void PrintLeafMembership(DTree* dtree, arma::Mat table(numLeaves, (numClasses + 1)); table.zeros(); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { const typename MatType::vec_type testPoint = data.unsafe_col(i); const int leafTag = dtree->FindBucket(testPoint); @@ -120,7 +120,7 @@ DTree* Trainer(MatType& dataset, Timer::Start("tree_growing"); // Prepare to grow the tree... arma::Col oldFromNew(dataset.n_cols); - for (size_t i = 0; i < oldFromNew.n_elem; i++) + for (size_t i = 0; i < oldFromNew.n_elem; ++i) oldFromNew[i] = i; // Save the dataset since it would be modified while growing the tree. @@ -214,7 +214,7 @@ DTree* Trainer(MatType& dataset, // Getting ready to grow the tree... arma::Col cvOldFromNew(train.n_cols); - for (size_t i = 0; i < cvOldFromNew.n_elem; i++) + for (size_t i = 0; i < cvOldFromNew.n_elem; ++i) cvOldFromNew[i] = i; // Grow the tree. @@ -231,7 +231,7 @@ DTree* Trainer(MatType& dataset, { // Compute test values for this state of the tree. double cvVal = 0.0; - for (size_t j = 0; j < test.n_cols; j++) + for (size_t j = 0; j < test.n_cols; ++j) { arma::vec testPoint = test.unsafe_col(j); cvVal += cvDTree.ComputeValue(testPoint); @@ -287,7 +287,7 @@ DTree* Trainer(MatType& dataset, dtree = new DTree(dataset); // Getting ready to grow the tree... - for (size_t i = 0; i < oldFromNew.n_elem; i++) + for (size_t i = 0; i < oldFromNew.n_elem; ++i) oldFromNew[i] = i; // Save the dataset since it would be modified while growing the tree. diff --git a/src/mlpack/methods/emst/dtb_impl.hpp b/src/mlpack/methods/emst/dtb_impl.hpp index ff108e9a93..e48b97cdf4 100644 --- a/src/mlpack/methods/emst/dtb_impl.hpp +++ b/src/mlpack/methods/emst/dtb_impl.hpp @@ -195,7 +195,7 @@ template< typename TreeMatType> class TreeType> void DualTreeBoruvka::AddAllEdges() { - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { size_t component = connections.Find(i); size_t inEdge = neighborsInComponent[component]; @@ -232,7 +232,7 @@ void DualTreeBoruvka::EmitResults( // Need to unpermute the point labels. if (!naive && ownTree && tree::TreeTraits::RearrangesDataset) { - for (size_t i = 0; i < (data.n_cols - 1); i++) + for (size_t i = 0; i < (data.n_cols - 1); ++i) { // Make sure the edge list stores the smaller index first to // make checking correctness easier @@ -257,7 +257,7 @@ void DualTreeBoruvka::EmitResults( } else { - for (size_t i = 0; i < edges.size(); i++) + for (size_t i = 0; i < edges.size(); ++i) { results(0, i) = edges[i].Lesser(); results(1, i) = edges[i].Greater(); @@ -318,7 +318,7 @@ template< typename TreeMatType> class TreeType> void DualTreeBoruvka::Cleanup() { - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) neighborsDistances[i] = DBL_MAX; if (!naive) diff --git a/src/mlpack/methods/fastmks/fastmks_impl.hpp b/src/mlpack/methods/fastmks/fastmks_impl.hpp index 5c4dcbd81f..e36568859d 100644 --- a/src/mlpack/methods/fastmks/fastmks_impl.hpp +++ b/src/mlpack/methods/fastmks/fastmks_impl.hpp @@ -446,7 +446,7 @@ void FastMKS::Search( } } - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { indices(k - j, q) = pqueue.top().second; kernels(k - j, q) = pqueue.top().first; @@ -586,7 +586,7 @@ void FastMKS::Search( } } - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { indices(k - j, q) = pqueue.top().second; kernels(k - j, q) = pqueue.top().first; diff --git a/src/mlpack/methods/fastmks/fastmks_rules_impl.hpp b/src/mlpack/methods/fastmks/fastmks_rules_impl.hpp index be1c5958c4..92f249cf2f 100644 --- a/src/mlpack/methods/fastmks/fastmks_rules_impl.hpp +++ b/src/mlpack/methods/fastmks/fastmks_rules_impl.hpp @@ -58,7 +58,7 @@ FastMKSRules::FastMKSRules( CandidateList pqueue; pqueue.reserve(k); - for (size_t i = 0; i < k; i++) + for (size_t i = 0; i < k; ++i) pqueue.push(def); std::vector tmp(querySet.n_cols, pqueue); candidates.swap(tmp); @@ -72,10 +72,10 @@ void FastMKSRules::GetResults( indices.set_size(k, querySet.n_cols); products.set_size(k, querySet.n_cols); - for (size_t i = 0; i < querySet.n_cols; i++) + for (size_t i = 0; i < querySet.n_cols; ++i) { CandidateList& pqueue = candidates[i]; - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { indices(k - j, i) = pqueue.top().second; products(k - j, i) = pqueue.top().first; diff --git a/src/mlpack/methods/gmm/diagonal_gmm.cpp b/src/mlpack/methods/gmm/diagonal_gmm.cpp index ad305ac4d3..e50d2ca7ea 100644 --- a/src/mlpack/methods/gmm/diagonal_gmm.cpp +++ b/src/mlpack/methods/gmm/diagonal_gmm.cpp @@ -59,7 +59,7 @@ double DiagonalGMM::LogProbability(const arma::vec& observation) const // Sum the probability for each Gaussian in our mixture (and we have to // multiply by the prior for each Gaussian too). double sum = -std::numeric_limits::infinity(); - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) { sum = math::LogAdd(sum, log(weights[i]) + dists[i].LogProbability(observation)); @@ -163,14 +163,14 @@ double DiagonalGMM::LogLikelihood( arma::vec phis; arma::mat likelihoods(gaussians, observations.n_cols); - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) { dists[i].Probability(observations, phis); likelihoods.row(i) = weights(i) * trans(phis); } // Now sum over every point. - for (size_t j = 0; j < observations.n_cols; j++) + for (size_t j = 0; j < observations.n_cols; ++j) { if (accu(likelihoods.col(j)) == 0) Log::Info << "Likelihood of point " << j << " is 0! It is probably an " diff --git a/src/mlpack/methods/gmm/em_fit_impl.hpp b/src/mlpack/methods/gmm/em_fit_impl.hpp index d92a8a1fa0..1372310c72 100644 --- a/src/mlpack/methods/gmm/em_fit_impl.hpp +++ b/src/mlpack/methods/gmm/em_fit_impl.hpp @@ -88,7 +88,7 @@ Estimate(const arma::mat& observations, // Calculate the conditional probabilities of choosing a particular // Gaussian given the observations and the present theta value. - for (size_t i = 0; i < dists.size(); i++) + for (size_t i = 0; i < dists.size(); ++i) { // Store conditional log probabilities into condLogProb vector for each // Gaussian. First we make an alias of the condLogProb vector. @@ -98,7 +98,7 @@ Estimate(const arma::mat& observations, } // Normalize row-wise. - for (size_t i = 0; i < condLogProb.n_rows; i++) + for (size_t i = 0; i < condLogProb.n_rows; ++i) { // Avoid dividing by zero; if the probability for everything is 0, we // don't want to make it NaN. @@ -116,7 +116,7 @@ Estimate(const arma::mat& observations, // Calculate the new value of the means using the updated conditional // probabilities. - for (size_t i = 0; i < dists.size(); i++) + for (size_t i = 0; i < dists.size(); ++i) { // Don't update if there's no probability of the Gaussian having points. if (probRowSums[i] != -std::numeric_limits::infinity()) @@ -193,7 +193,7 @@ Estimate(const arma::mat& observations, { // Calculate the conditional probabilities of choosing a particular // Gaussian given the observations and the present theta value. - for (size_t i = 0; i < dists.size(); i++) + for (size_t i = 0; i < dists.size(); ++i) { // Store conditional log probabilities into condLogProb vector for each // Gaussian. First we make an alias of the condLogProb vector. @@ -203,7 +203,7 @@ Estimate(const arma::mat& observations, } // Normalize row-wise. - for (size_t i = 0; i < condLogProb.n_rows; i++) + for (size_t i = 0; i < condLogProb.n_rows; ++i) { // Avoid dividing by zero; if the probability for everything is 0, we // don't want to make it NaN. @@ -219,7 +219,7 @@ Estimate(const arma::mat& observations, // Calculate the new value of the means using the updated conditional // probabilities. arma::vec logProbabilities = arma::log(probabilities); - for (size_t i = 0; i < dists.size(); i++) + for (size_t i = 0; i < dists.size(); ++i) { // Calculate the sum of probabilities of points, which is the // conditional probability of each point being from Gaussian i diff --git a/src/mlpack/methods/gmm/gmm.cpp b/src/mlpack/methods/gmm/gmm.cpp index 46186f2e1a..83b8beeecf 100644 --- a/src/mlpack/methods/gmm/gmm.cpp +++ b/src/mlpack/methods/gmm/gmm.cpp @@ -59,7 +59,7 @@ double GMM::LogProbability(const arma::vec& observation) const // Sum the probability for each Gaussian in our mixture (and we have to // multiply by the prior for each Gaussian too). double sum = -std::numeric_limits::infinity(); - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) sum = math::LogAdd(sum, log(weights[i]) + dists[i].LogProbability(observation)); @@ -169,14 +169,14 @@ double GMM::LogLikelihood( arma::mat logLikelihoods(gaussians, data.n_cols); // It has to be LogProbability() otherwise Probability() would overflow easily - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) { distsL[i].LogProbability(data, logPhis); logLikelihoods.row(i) = log(weightsL(i)) + trans(logPhis); } // Now sum over every point. - for (size_t j = 0; j < data.n_cols; j++) + for (size_t j = 0; j < data.n_cols; ++j) loglikelihood += mlpack::math::AccuLog(logLikelihoods.col(j)); return loglikelihood; } diff --git a/src/mlpack/methods/gmm/gmm_train_main.cpp b/src/mlpack/methods/gmm/gmm_train_main.cpp index 17714a8b9a..333621ac40 100644 --- a/src/mlpack/methods/gmm/gmm_train_main.cpp +++ b/src/mlpack/methods/gmm/gmm_train_main.cpp @@ -227,7 +227,7 @@ static void mlpackMain() { // Convert GMMs into DiagonalGMMs. DiagonalGMM dgmm(gmm->Gaussians(), gmm->Dimensionality()); - for (size_t i = 0; i < size_t(gaussians); i++) + for (size_t i = 0; i < size_t(gaussians); ++i) { dgmm.Component(i).Mean() = gmm->Component(i).Mean(); dgmm.Component(i).Covariance( @@ -246,7 +246,7 @@ static void mlpackMain() Timer::Stop("em"); // Convert DiagonalGMMs into GMMs. - for (size_t i = 0; i < size_t(gaussians); i++) + for (size_t i = 0; i < size_t(gaussians); ++i) { gmm->Component(i).Mean() = dgmm.Component(i).Mean(); gmm->Component(i).Covariance( @@ -285,7 +285,7 @@ static void mlpackMain() { // Convert GMMs into DiagonalGMMs. DiagonalGMM dgmm(gmm->Gaussians(), gmm->Dimensionality()); - for (size_t i = 0; i < size_t(gaussians); i++) + for (size_t i = 0; i < size_t(gaussians); ++i) { dgmm.Component(i).Mean() = gmm->Component(i).Mean(); dgmm.Component(i).Covariance( @@ -304,7 +304,7 @@ static void mlpackMain() Timer::Stop("em"); // Convert DiagonalGMMs into GMMs. - for (size_t i = 0; i < size_t(gaussians); i++) + for (size_t i = 0; i < size_t(gaussians); ++i) { gmm->Component(i).Mean() = dgmm.Component(i).Mean(); gmm->Component(i).Covariance( diff --git a/src/mlpack/methods/hmm/hmm_impl.hpp b/src/mlpack/methods/hmm/hmm_impl.hpp index ea5830598d..626cd7383d 100644 --- a/src/mlpack/methods/hmm/hmm_impl.hpp +++ b/src/mlpack/methods/hmm/hmm_impl.hpp @@ -166,7 +166,7 @@ double HMM::Train(const std::vector& dataSeq) { // Estimate of T_ij (probability of transition from state j to state // i). We postpone multiplication of the old T_ij until later. - for (size_t i = 0; i < logTransition.n_rows; i++) + for (size_t i = 0; i < logTransition.n_rows; ++i) { newLogTransition(i, j) = math::LogAdd(newLogTransition(i, j), forwardLog(j, t) + backwardLog(i, t + 1) + @@ -204,7 +204,7 @@ double HMM::Train(const std::vector& dataSeq) logTransition += newLogTransition; // Now we normalize the transition matrix. - for (size_t i = 0; i < logTransition.n_cols; i++) + for (size_t i = 0; i < logTransition.n_cols; ++i) { const double sum = math::AccuLog(logTransition.col(i)); if (std::isfinite(sum)) @@ -309,7 +309,7 @@ void HMM::Train(const std::vector& dataSeq, if (emissionList[state].size() > 0) { arma::mat emissions(dimensionality, emissionList[state].size()); - for (size_t i = 0; i < emissions.n_cols; i++) + for (size_t i = 0; i < emissions.n_cols; ++i) { emissions.col(i) = dataSeq[emissionList[state][i].first].col( emissionList[state][i].second); @@ -486,7 +486,7 @@ double HMM::Predict(const arma::mat& dataSeq, // Assemble the state probability for this element. // Given that we are in state j, we use state with the highest probability // of being the previous state. - for (size_t j = 0; j < logTransition.n_rows; j++) + for (size_t j = 0; j < logTransition.n_rows; ++j) { arma::vec prob = logStateProb.col(t - 1) + logTransition.row(j).t(); logStateProb(j, t) = prob.max(index) + @@ -544,7 +544,7 @@ void HMM::Filter(const arma::mat& dataSeq, // Compute expected emissions. // Will not work for distributions without a Mean() function. filterSeq.zeros(dimensionality, dataSeq.n_cols); - for (size_t i = 0; i < emission.size(); i++) + for (size_t i = 0; i < emission.size(); ++i) filterSeq += emission[i].Mean() * forwardProb.row(i); } @@ -566,7 +566,7 @@ void HMM::Smooth(const arma::mat& dataSeq, // Compute expected emissions. // Will not work for distributions without a Mean() function. smoothSeq.zeros(dimensionality, dataSeq.n_cols); - for (size_t i = 0; i < emission.size(); i++) + for (size_t i = 0; i < emission.size(); ++i) smoothSeq += emission[i].Mean() * exp(stateLogProb.row(i)); } @@ -606,7 +606,7 @@ void HMM::Forward(const arma::mat& dataSeq, // Now compute the probabilities for each successive observation. for (size_t t = 1; t < dataSeq.n_cols; t++) { - for (size_t j = 0; j < logTransition.n_rows; j++) + for (size_t j = 0; j < logTransition.n_rows; ++j) { // The forward probability of state j at time t is the sum over all states // of the probability of the previous state transitioning to the current @@ -639,7 +639,7 @@ void HMM::Backward(const arma::mat& dataSeq, // Now step backwards through all other observations. for (size_t t = dataSeq.n_cols - 2; t + 1 > 0; t--) { - for (size_t j = 0; j < logTransition.n_rows; j++) + for (size_t j = 0; j < logTransition.n_rows; ++j) { // The backward probability of state j at time t is the sum over all state // of the probability of the next state having been a transition from the diff --git a/src/mlpack/methods/hmm/hmm_regression_impl.hpp b/src/mlpack/methods/hmm/hmm_regression_impl.hpp index fff2204e89..9224fc6822 100644 --- a/src/mlpack/methods/hmm/hmm_regression_impl.hpp +++ b/src/mlpack/methods/hmm/hmm_regression_impl.hpp @@ -116,7 +116,7 @@ void HMMRegression::Filter(const arma::mat& predictors, filterSeq.resize(responses.n_elem - ahead); filterSeq.zeros(); arma::vec nextSeq; - for (size_t i = 0; i < emission.size(); i++) + for (size_t i = 0; i < emission.size(); ++i) { emission[i].Predict(predictors.cols(ahead, predictors.n_cols-1), nextSeq); filterSeq = filterSeq + nextSeq%(forwardProb.row(i).t()); @@ -138,7 +138,7 @@ void HMMRegression::Smooth(const arma::mat& predictors, smoothSeq.resize(responses.n_elem); smoothSeq.zeros(); arma::vec nextSeq; - for (size_t i = 0; i < emission.size(); i++) + for (size_t i = 0; i < emission.size(); ++i) { emission[i].Predict(predictors, nextSeq); smoothSeq = smoothSeq + nextSeq%(stateProb.row(i).t()); @@ -174,7 +174,7 @@ void HMMRegression::StackData(const std::vector& predictors, std::vector& dataSeq) const { arma::mat nextSeq; - for (size_t i = 0; i < predictors.size(); i++) + for (size_t i = 0; i < predictors.size(); ++i) { nextSeq = predictors[i]; nextSeq.insert_rows(0, responses[i].t()); diff --git a/src/mlpack/methods/kmeans/kmeans_impl.hpp b/src/mlpack/methods/kmeans/kmeans_impl.hpp index a8df067ae1..a5a62203c5 100644 --- a/src/mlpack/methods/kmeans/kmeans_impl.hpp +++ b/src/mlpack/methods/kmeans/kmeans_impl.hpp @@ -222,7 +222,7 @@ Cluster(const MatType& data, // If we are not allowing empty clusters, then check that all of our // clusters have points. - for (size_t i = 0; i < counts.n_elem; i++) + for (size_t i = 0; i < counts.n_elem; ++i) { if (counts[i] == 0) { @@ -321,7 +321,7 @@ Cluster(const MatType& data, double minDistance = std::numeric_limits::infinity(); size_t closestCluster = centroids.n_cols; // Invalid value. - for (size_t j = 0; j < centroids.n_cols; j++) + for (size_t j = 0; j < centroids.n_cols; ++j) { const double distance = metric.Evaluate(data.col(i), centroids.col(j)); diff --git a/src/mlpack/methods/kmeans/kmeans_main.cpp b/src/mlpack/methods/kmeans/kmeans_main.cpp index 35f1fcd13d..fc350e0878 100644 --- a/src/mlpack/methods/kmeans/kmeans_main.cpp +++ b/src/mlpack/methods/kmeans/kmeans_main.cpp @@ -303,7 +303,7 @@ void RunKMeans(const InitialPartitionPolicy& ipp) // Add the column of assignments to the dataset; but we have to convert // them to type double first. arma::rowvec converted(assignments.n_elem); - for (size_t i = 0; i < assignments.n_elem; i++) + for (size_t i = 0; i < assignments.n_elem; ++i) converted(i) = (double) assignments(i); dataset.insert_rows(dataset.n_rows, converted); @@ -325,7 +325,7 @@ void RunKMeans(const InitialPartitionPolicy& ipp) { // Convert the assignments to doubles. arma::rowvec converted(assignments.n_elem); - for (size_t i = 0; i < assignments.n_elem; i++) + for (size_t i = 0; i < assignments.n_elem; ++i) converted(i) = (double) assignments(i); dataset.insert_rows(dataset.n_rows, converted); diff --git a/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp b/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp index 1394705d6c..9524e36c6e 100644 --- a/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp +++ b/src/mlpack/methods/kmeans/max_variance_new_cluster_impl.hpp @@ -131,7 +131,7 @@ void MaxVarianceNewCluster::Precalculate(const MatType& data, double minDistance = std::numeric_limits::infinity(); size_t closestCluster = oldCentroids.n_cols; // Invalid value. - for (size_t j = 0; j < oldCentroids.n_cols; j++) + for (size_t j = 0; j < oldCentroids.n_cols; ++j) { const double distance = metric.Evaluate(data.col(i), oldCentroids.col(j)); diff --git a/src/mlpack/methods/kmeans/naive_kmeans_impl.hpp b/src/mlpack/methods/kmeans/naive_kmeans_impl.hpp index 427957a877..d829adfbbb 100644 --- a/src/mlpack/methods/kmeans/naive_kmeans_impl.hpp +++ b/src/mlpack/methods/kmeans/naive_kmeans_impl.hpp @@ -55,7 +55,7 @@ double NaiveKMeans::Iterate(const arma::mat& centroids, double minDistance = std::numeric_limits::infinity(); size_t closestCluster = centroids.n_cols; // Invalid value. - for (size_t j = 0; j < centroids.n_cols; j++) + for (size_t j = 0; j < centroids.n_cols; ++j) { const double distance = metric.Evaluate(dataset.col(i), centroids.unsafe_col(j)); diff --git a/src/mlpack/methods/lars/lars.cpp b/src/mlpack/methods/lars/lars.cpp index 7a50a0a87c..b86c361a3f 100644 --- a/src/mlpack/methods/lars/lars.cpp +++ b/src/mlpack/methods/lars/lars.cpp @@ -243,7 +243,7 @@ double LARS::Train(const arma::mat& matX, { // Compute the maximum correlation among inactive dimensions. maxCorr = 0; - for (size_t i = 0; i < dataRef.n_cols; i++) + for (size_t i = 0; i < dataRef.n_cols; ++i) { if ((!isActive[i]) && (!isIgnored[i]) && (fabs(corr(i)) > maxCorr)) { @@ -257,7 +257,7 @@ double LARS::Train(const arma::mat& matX, if (useCholesky) { // vec newGramCol = vec(activeSet.size()); - // for (size_t i = 0; i < activeSet.size(); i++) + // for (size_t i = 0; i < activeSet.size(); ++i) // { // newGramCol[i] = dot(matX.col(activeSet[i]), matX.col(changeInd)); // } @@ -274,7 +274,7 @@ double LARS::Train(const arma::mat& matX, // Compute signs of correlations. arma::vec s = arma::vec(activeSet.size()); - for (size_t i = 0; i < activeSet.size(); i++) + for (size_t i = 0; i < activeSet.size(); ++i) s(i) = corr(activeSet[i]) / fabs(corr(activeSet[i])); // Compute the "equiangular" direction in parameter space (betaDirection). @@ -324,8 +324,8 @@ double LARS::Train(const arma::mat& matX, else { arma::mat matGramActive = arma::mat(activeSet.size(), activeSet.size()); - for (size_t i = 0; i < activeSet.size(); i++) - for (size_t j = 0; j < activeSet.size(); j++) + for (size_t i = 0; i < activeSet.size(); ++i) + for (size_t j = 0; j < activeSet.size(); ++j) matGramActive(i, j) = (*matGram)(activeSet[i], activeSet[j]); // Check for singularity. @@ -383,7 +383,7 @@ double LARS::Train(const arma::mat& matX, double lassoboundOnGamma = DBL_MAX; size_t activeIndToKickOut = -1; - for (size_t i = 0; i < activeSet.size(); i++) + for (size_t i = 0; i < activeSet.size(); ++i) { double val = -beta(activeSet[i]) / betaDirection(i); if ((val > 0) && (val < lassoboundOnGamma)) @@ -405,7 +405,7 @@ double LARS::Train(const arma::mat& matX, yHat += gamma * yHatDirection; // Update the estimator. - for (size_t i = 0; i < activeSet.size(); i++) + for (size_t i = 0; i < activeSet.size(); ++i) { beta(activeSet[i]) += gamma * betaDirection(i); } @@ -433,7 +433,7 @@ double LARS::Train(const arma::mat& matX, corr -= lambda2 * beta; double curLambda = 0; - for (size_t i = 0; i < activeSet.size(); i++) + for (size_t i = 0; i < activeSet.size(); ++i) curLambda += fabs(corr(activeSet[i])); curLambda /= ((double) activeSet.size()); @@ -501,7 +501,7 @@ void LARS::ComputeYHatDirection(const arma::mat& matX, arma::vec& yHatDirection) { yHatDirection.fill(0); - for (size_t i = 0; i < activeSet.size(); i++) + for (size_t i = 0; i < activeSet.size(); ++i) yHatDirection += betaDirection(i) * matX.col(activeSet[i]); } @@ -614,7 +614,7 @@ void LARS::CholeskyDelete(const size_t colToKill) matUtriCholFactor.shed_col(colToKill); // remove column colToKill n--; - for (size_t k = colToKill; k < n; k++) + for (size_t k = colToKill; k < n; ++k) { arma::mat matG; arma::vec::fixed<2> rotatedVec; diff --git a/src/mlpack/methods/linear_svm/linear_svm_function_impl.hpp b/src/mlpack/methods/linear_svm/linear_svm_function_impl.hpp index cfe4e888ef..268b4e85e5 100644 --- a/src/mlpack/methods/linear_svm/linear_svm_function_impl.hpp +++ b/src/mlpack/methods/linear_svm/linear_svm_function_impl.hpp @@ -89,7 +89,7 @@ void LinearSVMFunction::GetGroundTruthMatrix( // Row pointers are the labels of the examples, and column pointers are the // number of cumulative entries made uptil that column. - for (size_t i = 0; i < labels.n_elem; i++) + for (size_t i = 0; i < labels.n_elem; ++i) { rowPointers(i) = labels(i); colPointers(i + 1) = i + 1; diff --git a/src/mlpack/methods/linear_svm/linear_svm_impl.hpp b/src/mlpack/methods/linear_svm/linear_svm_impl.hpp index e4f3699eef..243ba772ce 100644 --- a/src/mlpack/methods/linear_svm/linear_svm_impl.hpp +++ b/src/mlpack/methods/linear_svm/linear_svm_impl.hpp @@ -214,7 +214,7 @@ double LinearSVM::ComputeAccuracy( // Increment count for every correctly predicted label. size_t count = 0; - for (size_t i = 0; i < labels.n_elem ; i++) + for (size_t i = 0; i < labels.n_elem ; ++i) if (testLabels(i) == labels(i)) count++; diff --git a/src/mlpack/methods/lmnn/constraints_impl.hpp b/src/mlpack/methods/lmnn/constraints_impl.hpp index 13e9d51953..531e31800e 100644 --- a/src/mlpack/methods/lmnn/constraints_impl.hpp +++ b/src/mlpack/methods/lmnn/constraints_impl.hpp @@ -49,7 +49,7 @@ inline void Constraints::ReorderResults( // Just a simple loop over the results---we want to make sure that the // largest-norm point with identical distance has the last location. - for (size_t i = 0; i < neighbors.n_cols; i++) + for (size_t i = 0; i < neighbors.n_cols; ++i) { for (size_t start = 0; start < neighbors.n_rows - 1; start++) { @@ -93,7 +93,7 @@ void Constraints::TargetNeighbors(arma::Mat& outputMatrix, arma::Mat neighbors; arma::mat distances; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Perform KNN search with same class points as both reference // set and query set. @@ -105,7 +105,7 @@ void Constraints::TargetNeighbors(arma::Mat& outputMatrix, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexSame[i].at(neighbors(j)); // Store target neihbors. @@ -138,7 +138,7 @@ void Constraints::TargetNeighbors(arma::Mat& outputMatrix, // Vectors to store indices. arma::uvec subIndexSame; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Calculate Target Neighbors. subIndexSame = arma::find(sublabels == uniqueLabels[i]); @@ -153,7 +153,7 @@ void Constraints::TargetNeighbors(arma::Mat& outputMatrix, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexSame[i].at(neighbors(j)); // Store target neighbors. @@ -177,7 +177,7 @@ void Constraints::Impostors(arma::Mat& outputMatrix, arma::Mat neighbors; arma::mat distances; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Perform KNN search with differently labeled points as reference // set and same class points as query set. @@ -189,7 +189,7 @@ void Constraints::Impostors(arma::Mat& outputMatrix, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexDiff[i].at(neighbors(j)); // Store impostors. @@ -215,7 +215,7 @@ void Constraints::Impostors(arma::Mat& outputNeighbors, arma::Mat neighbors; arma::mat distances; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Perform KNN search with differently labeled points as reference // set and same class points as query set. @@ -227,7 +227,7 @@ void Constraints::Impostors(arma::Mat& outputNeighbors, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexDiff[i].at(neighbors(j)); // Store impostors. @@ -261,7 +261,7 @@ void Constraints::Impostors(arma::Mat& outputMatrix, // Vectors to store indices. arma::uvec subIndexSame; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Calculate impostors. subIndexSame = arma::find(sublabels == uniqueLabels[i]); @@ -276,7 +276,7 @@ void Constraints::Impostors(arma::Mat& outputMatrix, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexDiff[i].at(neighbors(j)); // Store impostors. @@ -310,7 +310,7 @@ void Constraints::Impostors(arma::Mat& outputNeighbors, // Vectors to store indices. arma::uvec subIndexSame; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Calculate impostors. subIndexSame = arma::find(sublabels == uniqueLabels[i]); @@ -325,7 +325,7 @@ void Constraints::Impostors(arma::Mat& outputNeighbors, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexDiff[i].at(neighbors(j)); // Store impostors. @@ -357,7 +357,7 @@ void Constraints::Impostors(arma::Mat& outputNeighbors, // Vectors to store indices. arma::uvec subIndexSame; - for (size_t i = 0; i < uniqueLabels.n_cols; i++) + for (size_t i = 0; i < uniqueLabels.n_cols; ++i) { // Calculate impostors. subIndexSame = arma::find(labels.cols(points.head(numPoints)) == @@ -374,7 +374,7 @@ void Constraints::Impostors(arma::Mat& outputNeighbors, ReorderResults(distances, neighbors, norms); // Re-map neighbors to their index. - for (size_t j = 0; j < neighbors.n_elem; j++) + for (size_t j = 0; j < neighbors.n_elem; ++j) neighbors(j) = indexDiff[i].at(neighbors(j)); // Store impostors. @@ -404,9 +404,9 @@ void Constraints::Triplets(arma::Mat& outputMatrix, outputMatrix = arma::Mat(3, k * k * N , arma::fill::zeros); - for (size_t i = 0, r = 0; i < N; i++) + for (size_t i = 0, r = 0; i < N; ++i) { - for (size_t j = 0; j < k; j++) + for (size_t j = 0; j < k; ++j) { for (size_t l = 0; l < k; l++, r++) { @@ -432,7 +432,7 @@ inline void Constraints::Precalculate( indexSame.resize(uniqueLabels.n_elem); indexDiff.resize(uniqueLabels.n_elem); - for (size_t i = 0; i < uniqueLabels.n_elem; i++) + for (size_t i = 0; i < uniqueLabels.n_elem; ++i) { // Store same and diff indices. indexSame[i] = arma::find(labels == uniqueLabels[i]); diff --git a/src/mlpack/methods/lmnn/lmnn_function_impl.hpp b/src/mlpack/methods/lmnn/lmnn_function_impl.hpp index 9009c32e2f..ae9cefd5c1 100644 --- a/src/mlpack/methods/lmnn/lmnn_function_impl.hpp +++ b/src/mlpack/methods/lmnn/lmnn_function_impl.hpp @@ -44,7 +44,7 @@ LMNNFunction::LMNNFunction(const arma::mat& dataset, // Calculate and store norm of datapoints. norm.set_size(dataset.n_cols); - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { norm(i) = arma::norm(dataset.col(i)); } @@ -115,7 +115,7 @@ void LMNNFunction::Shuffle() lastTransformationIndices = newlastTransformationIndices.elem(ordering); norm = newNorm.elem(ordering); - for (size_t i = 0; i < ordering.n_elem; i++) + for (size_t i = 0; i < ordering.n_elem; ++i) { evalOld.slice(i) = newEvalOld.slice(ordering(i)); } @@ -231,7 +231,7 @@ double LMNNFunction::Evaluate(const arma::mat& transformation) // Track number of data points to use for impostors calculatiom. size_t numPoints = 0; - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { if (transformationDiff * (2 * norm(i) + norm(impostors(k - 1, i)) + norm(impostors(k, i))) > distance(k, i) - distance(k - 1, i)) @@ -257,9 +257,9 @@ double LMNNFunction::Evaluate(const arma::mat& transformation) constraint.Impostors(impostors, distance, transformedDataset, labels, norm); } - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { - for (size_t j = 0; j < k ; j++) + for (size_t j = 0; j < k ; ++j) { // Calculate cost due to distance between target neighbors & data point. double eval = metric.Evaluate(transformedDataset.col(i), @@ -356,7 +356,7 @@ double LMNNFunction::Evaluate(const arma::mat& transformation, // Track number of data points to use for impostors calculatiom. size_t numPoints = 0; - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { if (lastTransformationIndices(i)) { @@ -384,9 +384,9 @@ double LMNNFunction::Evaluate(const arma::mat& transformation, norm, begin, batchSize); } - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { - for (size_t j = 0; j < k ; j++) + for (size_t j = 0; j < k ; ++j) { // Calculate cost due to distance between target neighbors & data point. double eval = metric.Evaluate(transformedDataset.col(i), @@ -485,7 +485,7 @@ void LMNNFunction::Gradient(const arma::mat& transformation, // Track number of data points to use for impostors calculatiom. size_t numPoints = 0; - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { if (transformationDiff * (2 * norm(i) + norm(impostors(k - 1, i)) + norm(impostors(k, i))) > distance(k, i) - distance(k - 1, i)) @@ -520,7 +520,7 @@ void LMNNFunction::Gradient(const arma::mat& transformation, // Calculate gradient due to impostors. arma::mat cil = arma::zeros(dataset.n_rows, dataset.n_rows); - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { for (int j = k - 1; j >= 0; j--) { @@ -616,7 +616,7 @@ void LMNNFunction::Gradient(const arma::mat& transformation, // Track number of data points to use for impostors calculatiom. size_t numPoints = 0; - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { if (lastTransformationIndices(i)) { @@ -649,9 +649,9 @@ void LMNNFunction::Gradient(const arma::mat& transformation, arma::mat cij = arma::zeros(dataset.n_rows, dataset.n_rows); arma::mat cil = arma::zeros(dataset.n_rows, dataset.n_rows); - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { - for (size_t j = 0; j < k ; j++) + for (size_t j = 0; j < k ; ++j) { // Calculate gradient due to target neighbors. arma::vec diff = dataset.col(i) - dataset.col(targetNeighbors(j, i)); @@ -760,7 +760,7 @@ double LMNNFunction::EvaluateWithGradient( // Track number of data points to use for impostors calculatiom. size_t numPoints = 0; - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { if (transformationDiff * (2 * norm(i) + norm(impostors(k - 1, i)) + norm(impostors(k, i))) > distance(k, i) - distance(k - 1, i)) @@ -795,9 +795,9 @@ double LMNNFunction::EvaluateWithGradient( // Calculate gradient due to impostors. arma::mat cil = arma::zeros(dataset.n_rows, dataset.n_rows); - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { - for (size_t j = 0; j < k ; j++) + for (size_t j = 0; j < k ; ++j) { // Calculate cost due to distance between target neighbors & data point. double eval = metric.Evaluate(transformedDataset.col(i), @@ -898,7 +898,7 @@ double LMNNFunction::EvaluateWithGradient( // Track number of data points to use for impostors calculatiom. size_t numPoints = 0; - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { if (lastTransformationIndices(i)) { @@ -931,9 +931,9 @@ double LMNNFunction::EvaluateWithGradient( arma::mat cij = arma::zeros(dataset.n_rows, dataset.n_rows); arma::mat cil = arma::zeros(dataset.n_rows, dataset.n_rows); - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { - for (size_t j = 0; j < k ; j++) + for (size_t j = 0; j < k ; ++j) { // Calculate cost due to distance between target neighbors & data point. double eval = metric.Evaluate(transformedDataset.col(i), @@ -1020,9 +1020,9 @@ inline void LMNNFunction::Precalculate() { pCij.zeros(dataset.n_rows, dataset.n_rows); - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { - for (size_t j = 0; j < k ; j++) + for (size_t j = 0; j < k ; ++j) { // Calculate gradient due to target neighbors. arma::vec diff = dataset.col(i) - dataset.col(targetNeighbors(j, i)); diff --git a/src/mlpack/methods/lmnn/lmnn_main.cpp b/src/mlpack/methods/lmnn/lmnn_main.cpp index 264f02f427..d7e6f058d4 100644 --- a/src/mlpack/methods/lmnn/lmnn_main.cpp +++ b/src/mlpack/methods/lmnn/lmnn_main.cpp @@ -198,12 +198,12 @@ double KNNAccuracy(const arma::mat& dataset, // Keep count. size_t count = 0; - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { arma::vec Map; Map.zeros(uniqueLabels.n_cols); - for (size_t j = 0; j < k; j++) + for (size_t j = 0; j < k; ++j) { Map(labels(neighbors(j, i))) += 1 / std::pow(distances(j, i) + 1, 2); @@ -295,7 +295,7 @@ static void mlpackMain() // Carry out mean-centering on the dataset, if necessary. if (center) { - for (size_t i = 0; i < data.n_rows; i++) + for (size_t i = 0; i < data.n_rows; ++i) { data.row(i) -= arma::mean(data.row(i)); } @@ -310,7 +310,7 @@ static void mlpackMain() else { Log::Info << "Using last column of input dataset as labels." << endl; - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) rawLabels[i] = (size_t) data(data.n_rows - 1, i); data.shed_row(data.n_rows - 1); diff --git a/src/mlpack/methods/local_coordinate_coding/lcc.cpp b/src/mlpack/methods/local_coordinate_coding/lcc.cpp index 61911eda1c..c97aca4ed1 100644 --- a/src/mlpack/methods/local_coordinate_coding/lcc.cpp +++ b/src/mlpack/methods/local_coordinate_coding/lcc.cpp @@ -38,7 +38,7 @@ void LocalCoordinateCoding::Encode(const arma::mat& data, arma::mat& codes) arma::mat dictGramTD(dictGram.n_rows, dictGram.n_cols); codes.set_size(atoms, data.n_cols); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { // Report progress. if ((i % 100) == 0) @@ -98,7 +98,7 @@ void LocalCoordinateCoding::OptimizeDictionary(const arma::mat& data, dataPrime(arma::span::all, arma::span(0, data.n_cols - 1)) = data; size_t curCol = data.n_cols; - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { if (neighborCounts(i) > 0) { diff --git a/src/mlpack/methods/logistic_regression/logistic_regression_impl.hpp b/src/mlpack/methods/logistic_regression/logistic_regression_impl.hpp index cdc71edb08..cdbad518fb 100644 --- a/src/mlpack/methods/logistic_regression/logistic_regression_impl.hpp +++ b/src/mlpack/methods/logistic_regression/logistic_regression_impl.hpp @@ -161,7 +161,7 @@ double LogisticRegression::ComputeAccuracy( // Count the number of responses that were correct. size_t count = 0; - for (size_t i = 0; i < responses.n_elem; i++) + for (size_t i = 0; i < responses.n_elem; ++i) { if (responses(i) == tempResponses(i)) count++; diff --git a/src/mlpack/methods/lsh/lsh_search_impl.hpp b/src/mlpack/methods/lsh/lsh_search_impl.hpp index 1dfbc5cac6..aad1fd48c7 100644 --- a/src/mlpack/methods/lsh/lsh_search_impl.hpp +++ b/src/mlpack/methods/lsh/lsh_search_impl.hpp @@ -193,7 +193,7 @@ void LSHSearch::Train(MatType referenceSet, { const size_t numSamples = 25; // Compute a heuristic hash width from the data. - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { size_t p1 = (size_t) math::RandInt(this->referenceSet.n_cols); size_t p2 = (size_t) math::RandInt(this->referenceSet.n_cols); @@ -258,7 +258,7 @@ void LSHSearch::Train(MatType referenceSet, // size_t, otherwise negative numbers are cast to 0. arma::Mat secondHashVectors(numTables, this->referenceSet.n_cols); - for (size_t i = 0; i < numTables; i++) + for (size_t i = 0; i < numTables; ++i) { // Step IV: create the 'numProj'-dimensional key for each point in each // table. @@ -320,7 +320,7 @@ void LSHSearch::Train(MatType referenceSet, { // Insert the point in the corresponding row to its bucket in the // 'secondHashTable'. - for (size_t j = 0; j < secondHashVectors.n_cols; j++) + for (size_t j = 0; j < secondHashVectors.n_cols; ++j) { // This is the bucket number. size_t hashInd = (size_t) secondHashVectors(i, j); @@ -388,7 +388,7 @@ void LSHSearch::BaseCase( } } - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { neighbors(k - j, queryIndex) = pqueue.top().second; distances(k - j, queryIndex) = pqueue.top().first; @@ -431,7 +431,7 @@ void LSHSearch::BaseCase( } } - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { neighbors(k - j, queryIndex) = pqueue.top().second; distances(k - j, queryIndex) = pqueue.top().first; @@ -727,7 +727,7 @@ void LSHSearch::ReturnIndicesFromTable( // Compute the projection of the query in each table. arma::mat allProjInTables(numProj, numTablesToSearch); arma::mat queryCodesNotFloored(numProj, numTablesToSearch); - for (size_t i = 0; i < numTablesToSearch; i++) + for (size_t i = 0; i < numTablesToSearch; ++i) queryCodesNotFloored.unsafe_col(i) = projections.slice(i).t() * queryPoint; queryCodesNotFloored += offsets.cols(0, numTablesToSearch - 1); @@ -743,7 +743,7 @@ void LSHSearch::ReturnIndicesFromTable( hashMat.row(0) = arma::conv_to> // Floor by typecasting ::from(secondHashWeights.t() * allProjInTables); // Mod to compute 2nd-level codes. - for (size_t i = 0; i < numTablesToSearch; i++) + for (size_t i = 0; i < numTablesToSearch; ++i) hashMat(0, i) = (hashMat(0, i) % secondHashSize); // Compute hash codes of additional probing bins. diff --git a/src/mlpack/methods/matrix_completion/matrix_completion.cpp b/src/mlpack/methods/matrix_completion/matrix_completion.cpp index fa80394eea..6210b69453 100644 --- a/src/mlpack/methods/matrix_completion/matrix_completion.cpp +++ b/src/mlpack/methods/matrix_completion/matrix_completion.cpp @@ -67,7 +67,7 @@ void MatrixCompletion::CheckValues() << std::endl; } - for (size_t i = 0; i < values.n_elem; i++) + for (size_t i = 0; i < values.n_elem; ++i) { if (indices(0, i) >= m || indices(1, i) >= n) Log::Fatal << "MatrixCompletion::CheckValues(): indices (" @@ -82,7 +82,7 @@ void MatrixCompletion::InitSDP() sdp.SDP().C().eye(m + n, m + n); sdp.SDP().SparseB() = 2. * values; const size_t p = indices.n_cols; - for (size_t i = 0; i < p; i++) + for (size_t i = 0; i < p; ++i) { sdp.SDP().SparseA()[i].zeros(m + n, m + n); sdp.SDP().SparseA()[i](indices(0, i), m + indices(1, i)) = 1.; diff --git a/src/mlpack/methods/mean_shift/mean_shift_main.cpp b/src/mlpack/methods/mean_shift/mean_shift_main.cpp index a3389eae80..0725f82443 100644 --- a/src/mlpack/methods/mean_shift/mean_shift_main.cpp +++ b/src/mlpack/methods/mean_shift/mean_shift_main.cpp @@ -120,7 +120,7 @@ static void mlpackMain() // Add the column of assignments to the dataset; but we have to convert them // to type double first. arma::vec converted(assignments.n_elem); - for (size_t i = 0; i < assignments.n_elem; i++) + for (size_t i = 0; i < assignments.n_elem; ++i) converted(i) = (double) assignments(i); dataset.insert_rows(dataset.n_rows, trans(converted)); @@ -135,7 +135,7 @@ static void mlpackMain() { // Convert the assignments to doubles. arma::vec converted(assignments.n_elem); - for (size_t i = 0; i < assignments.n_elem; i++) + for (size_t i = 0; i < assignments.n_elem; ++i) converted(i) = (double) assignments(i); dataset.insert_rows(dataset.n_rows, trans(converted)); diff --git a/src/mlpack/methods/naive_bayes/naive_bayes_classifier_impl.hpp b/src/mlpack/methods/naive_bayes/naive_bayes_classifier_impl.hpp index 6dfd1e5f1e..f116a76b12 100644 --- a/src/mlpack/methods/naive_bayes/naive_bayes_classifier_impl.hpp +++ b/src/mlpack/methods/naive_bayes/naive_bayes_classifier_impl.hpp @@ -217,7 +217,7 @@ void NaiveBayesClassifier::LogLikelihood( // means.n_cols. // Loop over every class. - for (size_t i = 0; i < means.n_cols; i++) + for (size_t i = 0; i < means.n_cols; ++i) { // This is an adaptation of gmm::phi() for the case where the covariance is // a diagonal matrix. diff --git a/src/mlpack/methods/nca/nca_main.cpp b/src/mlpack/methods/nca/nca_main.cpp index 942fcb9363..5c467df89a 100644 --- a/src/mlpack/methods/nca/nca_main.cpp +++ b/src/mlpack/methods/nca/nca_main.cpp @@ -200,7 +200,7 @@ static void mlpackMain() else { Log::Info << "Using last column of input dataset as labels." << endl; - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) rawLabels[i] = (size_t) data(data.n_rows - 1, i); data.shed_row(data.n_rows - 1); diff --git a/src/mlpack/methods/nca/nca_softmax_error_function_impl.hpp b/src/mlpack/methods/nca/nca_softmax_error_function_impl.hpp index 4649faa087..f55d9e4a5a 100644 --- a/src/mlpack/methods/nca/nca_softmax_error_function_impl.hpp +++ b/src/mlpack/methods/nca/nca_softmax_error_function_impl.hpp @@ -74,7 +74,7 @@ double SoftmaxErrorFunction::Evaluate(const arma::mat& coordinates, // It's quicker to do this now than one point at a time later. stretchedDataset = coordinates * dataset; - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { for (size_t k = 0; k < dataset.n_cols; ++k) { @@ -129,9 +129,9 @@ void SoftmaxErrorFunction::Gradient(const arma::mat& coordinates, // (p_i p_ik + p_k p_ki) x_ik x_ik^T arma::mat sum; sum.zeros(stretchedDataset.n_rows, stretchedDataset.n_rows); - for (size_t i = 0; i < stretchedDataset.n_cols; i++) + for (size_t i = 0; i < stretchedDataset.n_cols; ++i) { - for (size_t k = (i + 1); k < stretchedDataset.n_cols; k++) + for (size_t k = (i + 1); k < stretchedDataset.n_cols; ++k) { // Calculate p_ik and p_ki first. double eval = exp(-metric.Evaluate(stretchedDataset.unsafe_col(i), @@ -174,7 +174,7 @@ void SoftmaxErrorFunction::Gradient(const arma::mat& coordinates, // Compute the stretched dataset. stretchedDataset = coordinates * dataset; - for (size_t i = begin; i < begin + batchSize; i++) + for (size_t i = begin; i < begin + batchSize; ++i) { numerator = 0; denominator = 0; @@ -265,9 +265,9 @@ void SoftmaxErrorFunction::Precalculate( // order of O((n * (n + 1)) / 2), which really isn't all that great. p.zeros(stretchedDataset.n_cols); denominators.zeros(stretchedDataset.n_cols); - for (size_t i = 0; i < stretchedDataset.n_cols; i++) + for (size_t i = 0; i < stretchedDataset.n_cols; ++i) { - for (size_t j = (i + 1); j < stretchedDataset.n_cols; j++) + for (size_t j = (i + 1); j < stretchedDataset.n_cols; ++j) { // Evaluate exp(-d(x_i, x_j)). double eval = exp(-metric.Evaluate(stretchedDataset.unsafe_col(i), @@ -290,7 +290,7 @@ void SoftmaxErrorFunction::Precalculate( p /= denominators; // Clean up any bad values. - for (size_t i = 0; i < stretchedDataset.n_cols; i++) + for (size_t i = 0; i < stretchedDataset.n_cols; ++i) { if (denominators[i] == 0.0) { diff --git a/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp b/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp index f3120bc85a..c5cc2dbd52 100644 --- a/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp +++ b/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp @@ -542,13 +542,13 @@ DualTreeTraversalType, SingleTreeTraversalType>::Search( neighbors.set_size(k, querySet.n_cols); distances.set_size(k, querySet.n_cols); - for (size_t i = 0; i < distances.n_cols; i++) + for (size_t i = 0; i < distances.n_cols; ++i) { // Map distances (copy a column). distances.col(oldFromNewQueries[i]) = distancePtr->col(i); // Map indices of neighbors. - for (size_t j = 0; j < distances.n_rows; j++) + for (size_t j = 0; j < distances.n_rows; ++j) { neighbors(j, oldFromNewQueries[i]) = oldFromNewReferences[(*neighborPtr)(j, i)]; @@ -583,8 +583,8 @@ DualTreeTraversalType, SingleTreeTraversalType>::Search( neighbors.set_size(k, querySet.n_cols); // Map indices of neighbors. - for (size_t i = 0; i < neighbors.n_cols; i++) - for (size_t j = 0; j < neighbors.n_rows; j++) + for (size_t i = 0; i < neighbors.n_cols; ++i) + for (size_t j = 0; j < neighbors.n_rows; ++j) neighbors(j, i) = oldFromNewReferences[(*neighborPtr)(j, i)]; // Finished with temporary matrix. @@ -669,8 +669,8 @@ DualTreeTraversalType, SingleTreeTraversalType>::Search( neighbors.set_size(k, querySet.n_cols); // Map indices of neighbors. - for (size_t i = 0; i < neighbors.n_cols; i++) - for (size_t j = 0; j < neighbors.n_rows; j++) + for (size_t i = 0; i < neighbors.n_cols; ++i) + for (size_t j = 0; j < neighbors.n_rows; ++j) neighbors(j, i) = oldFromNewReferences[(*neighborPtr)(j, i)]; // Finished with temporary matrix. @@ -886,7 +886,7 @@ DualTreeTraversalType, SingleTreeTraversalType>::EffectiveError( double effectiveError = 0; size_t numCases = 0; - for (size_t i = 0; i < foundDistances.n_elem; i++) + for (size_t i = 0; i < foundDistances.n_elem; ++i) { if (realDistances(i) != 0 && foundDistances(i) != SortPolicy::WorstDistance()) diff --git a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp index 42af963f8b..74d3c490cd 100644 --- a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp +++ b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp @@ -55,7 +55,7 @@ NeighborSearchRules::NeighborSearchRules( CandidateList pqueue(CandidateCmp(), std::move(vect)); candidates.reserve(querySet.n_cols); - for (size_t i = 0; i < querySet.n_cols; i++) + for (size_t i = 0; i < querySet.n_cols; ++i) candidates.push_back(pqueue); } @@ -67,10 +67,10 @@ void NeighborSearchRules::GetResults( neighbors.set_size(k, querySet.n_cols); distances.set_size(k, querySet.n_cols); - for (size_t i = 0; i < querySet.n_cols; i++) + for (size_t i = 0; i < querySet.n_cols; ++i) { CandidateList& pqueue = candidates[i]; - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { neighbors(k - j, i) = pqueue.top().second; distances(k - j, i) = pqueue.top().first; diff --git a/src/mlpack/methods/perceptron/perceptron_impl.hpp b/src/mlpack/methods/perceptron/perceptron_impl.hpp index 13af01d626..7c690ff64f 100644 --- a/src/mlpack/methods/perceptron/perceptron_impl.hpp +++ b/src/mlpack/methods/perceptron/perceptron_impl.hpp @@ -110,7 +110,7 @@ void Perceptron::Classify( arma::uword maxIndex = 0; // Could probably be faster if done in batch. - for (size_t i = 0; i < test.n_cols; i++) + for (size_t i = 0; i < test.n_cols; ++i) { tempLabelMat = weights.t() * test.col(i) + biases; tempLabelMat.max(maxIndex); @@ -159,11 +159,11 @@ void Perceptron::Train( { // This outer loop is for each iteration, and we use the 'converged' // variable for noting whether or not convergence has been reached. - i++; + ++i; converged = true; // Now this inner loop is for going through the dataset in each iteration. - for (j = 0; j < data.n_cols; j++) + for (j = 0; j < data.n_cols; ++j) { // Multiply for each variable and check whether the current weight vector // correctly classifies this. diff --git a/src/mlpack/methods/radical/radical.cpp b/src/mlpack/methods/radical/radical.cpp index 7056f781a5..26e78befa4 100644 --- a/src/mlpack/methods/radical/radical.cpp +++ b/src/mlpack/methods/radical/radical.cpp @@ -57,7 +57,7 @@ double Radical::Vasicek(vec& z) const // Apparently faster. double sum = 0; uword range = z.n_elem - m; - for (uword i = 0; i < range; i++) + for (uword i = 0; i < range; ++i) { sum += log(max(z(i + m) - z(i), DBL_MIN)); } @@ -74,7 +74,7 @@ double Radical::DoRadical2D(const mat& matX) vec values(angles); - for (size_t i = 0; i < angles; i++) + for (size_t i = 0; i < angles; ++i) { const double theta = (i / (double) angles) * M_PI / 2.0; const double cosTheta = cos(theta); @@ -140,9 +140,9 @@ void Radical::DoRadical(const mat& matXT, mat& matY, mat& matW) { Log::Info << "RADICAL: sweep " << sweepNum << "." << std::endl; - for (size_t i = 0; i < nDims - 1; i++) + for (size_t i = 0; i < nDims - 1; ++i) { - for (size_t j = i + 1; j < nDims; j++) + for (size_t j = i + 1; j < nDims; ++j) { Log::Debug << "RADICAL 2D on dimensions " << i << " and " << j << "." << std::endl; diff --git a/src/mlpack/methods/radical/radical_main.cpp b/src/mlpack/methods/radical/radical_main.cpp index a9b4c1cfa9..78b3707a86 100644 --- a/src/mlpack/methods/radical/radical_main.cpp +++ b/src/mlpack/methods/radical/radical_main.cpp @@ -126,7 +126,7 @@ static void mlpackMain() // Compute and print objective. mat matYT = trans(matY); double valEst = 0; - for (size_t i = 0; i < matYT.n_cols; i++) + for (size_t i = 0; i < matYT.n_cols; ++i) { vec y = vec(matYT.col(i)); valEst += rad.Vasicek(y); diff --git a/src/mlpack/methods/range_search/range_search_impl.hpp b/src/mlpack/methods/range_search/range_search_impl.hpp index 4c19cf9880..eb714c809d 100644 --- a/src/mlpack/methods/range_search/range_search_impl.hpp +++ b/src/mlpack/methods/range_search/range_search_impl.hpp @@ -390,7 +390,7 @@ void RangeSearch::Search( distances.clear(); distances.resize(querySet.n_cols); - for (size_t i = 0; i < distances.size(); i++) + for (size_t i = 0; i < distances.size(); ++i) { // Map distances (copy a column). const size_t queryMapping = oldFromNewQueries[i]; @@ -398,7 +398,7 @@ void RangeSearch::Search( // Copy each neighbor individually, because we need to map it. neighbors[queryMapping].resize(distances[queryMapping].size()); - for (size_t j = 0; j < distances[queryMapping].size(); j++) + for (size_t j = 0; j < distances[queryMapping].size(); ++j) neighbors[queryMapping][j] = oldFromNewReferences[(*neighborPtr)[i][j]]; } @@ -433,10 +433,10 @@ void RangeSearch::Search( neighbors.clear(); neighbors.resize(querySet.n_cols); - for (size_t i = 0; i < neighbors.size(); i++) + for (size_t i = 0; i < neighbors.size(); ++i) { neighbors[i].resize((*neighborPtr)[i].size()); - for (size_t j = 0; j < neighbors[i].size(); j++) + for (size_t j = 0; j < neighbors[i].size(); ++j) neighbors[i][j] = oldFromNewReferences[(*neighborPtr)[i][j]]; } @@ -505,10 +505,10 @@ void RangeSearch::Search( neighbors.clear(); neighbors.resize(querySet.n_cols); - for (size_t i = 0; i < neighbors.size(); i++) + for (size_t i = 0; i < neighbors.size(); ++i) { neighbors[i].resize((*neighborPtr)[i].size()); - for (size_t j = 0; j < neighbors[i].size(); j++) + for (size_t j = 0; j < neighbors[i].size(); ++j) neighbors[i][j] = oldFromNewReferences[(*neighborPtr)[i][j]]; } @@ -598,7 +598,7 @@ void RangeSearch::Search( distances.clear(); distances.resize(referenceSet->n_cols); - for (size_t i = 0; i < distances.size(); i++) + for (size_t i = 0; i < distances.size(); ++i) { // Map distances (copy a column). const size_t refMapping = oldFromNewReferences[i]; @@ -606,7 +606,7 @@ void RangeSearch::Search( // Copy each neighbor individually, because we need to map it. neighbors[refMapping].resize(distances[refMapping].size()); - for (size_t j = 0; j < distances[refMapping].size(); j++) + for (size_t j = 0; j < distances[refMapping].size(); ++j) { neighbors[refMapping][j] = oldFromNewReferences[(*neighborPtr)[i][j]]; } diff --git a/src/mlpack/methods/rann/ra_search_impl.hpp b/src/mlpack/methods/rann/ra_search_impl.hpp index eb40a3cf50..fce0d28626 100644 --- a/src/mlpack/methods/rann/ra_search_impl.hpp +++ b/src/mlpack/methods/rann/ra_search_impl.hpp @@ -379,13 +379,13 @@ Search(const MatType& querySet, neighbors.set_size(k, querySet.n_cols); distances.set_size(k, querySet.n_cols); - for (size_t i = 0; i < distances.n_cols; i++) + for (size_t i = 0; i < distances.n_cols; ++i) { // Map distances (copy a column). distances.col(oldFromNewQueries[i]) = distancePtr->col(i); // Map indices of neighbors. - for (size_t j = 0; j < distances.n_rows; j++) + for (size_t j = 0; j < distances.n_rows; ++j) { neighbors(j, oldFromNewQueries[i]) = oldFromNewReferences[(*neighborPtr)(j, i)]; @@ -420,8 +420,8 @@ Search(const MatType& querySet, neighbors.set_size(k, querySet.n_cols); // Map indices of neighbors. - for (size_t i = 0; i < neighbors.n_cols; i++) - for (size_t j = 0; j < neighbors.n_rows; j++) + for (size_t i = 0; i < neighbors.n_cols; ++i) + for (size_t j = 0; j < neighbors.n_rows; ++j) neighbors(j, i) = oldFromNewReferences[(*neighborPtr)(j, i)]; // Finished with temporary matrix. @@ -481,8 +481,8 @@ void RASearch::Search( neighbors.set_size(k, querySet.n_cols); // Map indices of neighbors. - for (size_t i = 0; i < neighbors.n_cols; i++) - for (size_t j = 0; j < neighbors.n_rows; j++) + for (size_t i = 0; i < neighbors.n_cols; ++i) + for (size_t j = 0; j < neighbors.n_rows; ++j) neighbors(j, i) = oldFromNewReferences[(*neighborPtr)(j, i)]; // Finished with temporary matrix. @@ -593,7 +593,7 @@ void RASearch::ResetQueryTree( queryNode->Stat().Bound() = SortPolicy::WorstDistance(); queryNode->Stat().NumSamplesMade() = 0; - for (size_t i = 0; i < queryNode->NumChildren(); i++) + for (size_t i = 0; i < queryNode->NumChildren(); ++i) ResetQueryTree(&queryNode->Child(i)); } diff --git a/src/mlpack/methods/rann/ra_search_rules_impl.hpp b/src/mlpack/methods/rann/ra_search_rules_impl.hpp index 5b4bf5398c..3ed2cff8b2 100644 --- a/src/mlpack/methods/rann/ra_search_rules_impl.hpp +++ b/src/mlpack/methods/rann/ra_search_rules_impl.hpp @@ -81,7 +81,7 @@ RASearchRules(const arma::mat& referenceSet, CandidateList pqueue(CandidateCmp(), std::move(vect)); candidates.reserve(querySet.n_cols); - for (size_t i = 0; i < querySet.n_cols; i++) + for (size_t i = 0; i < querySet.n_cols; ++i) candidates.push_back(pqueue); if (naive) // No tree traversal; just do naive sampling here. @@ -91,7 +91,7 @@ RASearchRules(const arma::mat& referenceSet, for (size_t i = 0; i < querySet.n_cols; ++i) { math::ObtainDistinctSamples(0, n, numSamplesReqd, distinctSamples); - for (size_t j = 0; j < distinctSamples.n_elem; j++) + for (size_t j = 0; j < distinctSamples.n_elem; ++j) BaseCase(i, (size_t) distinctSamples[j]); } } @@ -105,10 +105,10 @@ void RASearchRules::GetResults( neighbors.set_size(k, querySet.n_cols); distances.set_size(k, querySet.n_cols); - for (size_t i = 0; i < querySet.n_cols; i++) + for (size_t i = 0; i < querySet.n_cols; ++i) { CandidateList& pqueue = candidates[i]; - for (size_t j = 1; j <= k; j++) + for (size_t j = 1; j <= k; ++j) { neighbors(k - j, i) = pqueue.top().second; distances(k - j, i) = pqueue.top().first; @@ -206,7 +206,7 @@ inline double RASearchRules::Score( arma::uvec distinctSamples; math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t i = 0; i < distinctSamples.n_elem; i++) + for (size_t i = 0; i < distinctSamples.n_elem; ++i) // The counting of the samples are done in the 'BaseCase' function // so no book-keeping is required here. BaseCase(queryIndex, referenceNode.Descendant(distinctSamples[i])); @@ -222,7 +222,7 @@ inline double RASearchRules::Score( arma::uvec distinctSamples; math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t i = 0; i < distinctSamples.n_elem; i++) + for (size_t i = 0; i < distinctSamples.n_elem; ++i) // The counting of the samples are done in the 'BaseCase' function // so no book-keeping is required here. BaseCase(queryIndex, @@ -310,7 +310,7 @@ Rescore(const size_t queryIndex, arma::uvec distinctSamples; math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t i = 0; i < distinctSamples.n_elem; i++) + for (size_t i = 0; i < distinctSamples.n_elem; ++i) // The counting of the samples are done in the 'BaseCase' function so // no book-keeping is required here. BaseCase(queryIndex, referenceNode.Descendant(distinctSamples[i])); @@ -326,7 +326,7 @@ Rescore(const size_t queryIndex, arma::uvec distinctSamples; math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t i = 0; i < distinctSamples.n_elem; i++) + for (size_t i = 0; i < distinctSamples.n_elem; ++i) // The counting of the samples are done in the 'BaseCase' function // so no book-keeping is required here. BaseCase(queryIndex, referenceNode.Descendant(distinctSamples[i])); @@ -372,7 +372,7 @@ inline double RASearchRules::Score( double childBound = DBL_MAX; const double maxDescendantDistance = queryNode.FurthestDescendantDistance(); - for (size_t i = 0; i < queryNode.NumPoints(); i++) + for (size_t i = 0; i < queryNode.NumPoints(); ++i) { const double bound = candidates[queryNode.Point(i)].top().first + maxDescendantDistance; @@ -380,7 +380,7 @@ inline double RASearchRules::Score( pointBound = bound; } - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) { const double bound = queryNode.Child(i).Stat().Bound(); if (bound < childBound) @@ -411,7 +411,7 @@ inline double RASearchRules::Score( double childBound = DBL_MAX; const double maxDescendantDistance = queryNode.FurthestDescendantDistance(); - for (size_t i = 0; i < queryNode.NumPoints(); i++) + for (size_t i = 0; i < queryNode.NumPoints(); ++i) { const double bound = candidates[queryNode.Point(i)].top().first + maxDescendantDistance; @@ -419,7 +419,7 @@ inline double RASearchRules::Score( pointBound = bound; } - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) { const double bound = queryNode.Child(i).Stat().Bound(); if (bound < childBound) @@ -451,7 +451,7 @@ inline double RASearchRules::Score( size_t numSamplesMadeInChildNodes = std::numeric_limits::max(); // Find the minimum number of samples made among all children. - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) { const size_t numSamples = queryNode.Child(i).Stat().NumSamplesMade(); if (numSamples < numSamplesMadeInChildNodes) @@ -494,7 +494,7 @@ inline double RASearchRules::Score( // Iterate through all children and propagate the number of samples made // to the children. Only update if the parent node has made samples the // children have not seen. - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) queryNode.Child(i).Stat().NumSamplesMade() = std::max( queryNode.Stat().NumSamplesMade(), queryNode.Child(i).Stat().NumSamplesMade()); @@ -513,7 +513,7 @@ inline double RASearchRules::Score( const size_t queryIndex = queryNode.Descendant(i); math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t j = 0; j < distinctSamples.n_elem; j++) + for (size_t j = 0; j < distinctSamples.n_elem; ++j) // The counting of the samples are done in the 'BaseCase' function // so no book-keeping is required here. BaseCase(queryIndex, @@ -543,7 +543,7 @@ inline double RASearchRules::Score( const size_t queryIndex = queryNode.Descendant(i); math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t j = 0; j < distinctSamples.n_elem; j++) + for (size_t j = 0; j < distinctSamples.n_elem; ++j) // The counting of the samples are done in the 'BaseCase' // function so no book-keeping is required here. BaseCase(queryIndex, @@ -568,7 +568,7 @@ inline double RASearchRules::Score( // Go through all children and propagate the number of // samples made to the children. - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) queryNode.Child(i).Stat().NumSamplesMade() = std::max( queryNode.Stat().NumSamplesMade(), queryNode.Child(i).Stat().NumSamplesMade()); @@ -583,7 +583,7 @@ inline double RASearchRules::Score( // We must first visit the first leaf to boost accuracy. // Go through all children and propagate the number of // samples made to the children. - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) queryNode.Child(i).Stat().NumSamplesMade() = std::max( queryNode.Stat().NumSamplesMade(), queryNode.Child(i).Stat().NumSamplesMade()); @@ -625,7 +625,7 @@ Rescore(TreeType& queryNode, double childBound = DBL_MAX; const double maxDescendantDistance = queryNode.FurthestDescendantDistance(); - for (size_t i = 0; i < queryNode.NumPoints(); i++) + for (size_t i = 0; i < queryNode.NumPoints(); ++i) { const double bound = candidates[queryNode.Point(i)].top().first + maxDescendantDistance; @@ -633,7 +633,7 @@ Rescore(TreeType& queryNode, pointBound = bound; } - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) { const double bound = queryNode.Child(i).Stat().Bound(); if (bound < childBound) @@ -656,7 +656,7 @@ Rescore(TreeType& queryNode, size_t numSamplesMadeInChildNodes = std::numeric_limits::max(); // Find the minimum number of samples made among all children - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) { const size_t numSamples = queryNode.Child(i).Stat().NumSamplesMade(); if (numSamples < numSamplesMadeInChildNodes) @@ -699,7 +699,7 @@ Rescore(TreeType& queryNode, // Go through all children and propagate the number of samples made to the // children. Only update if the parent node has made samples the children // have not seen. - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) queryNode.Child(i).Stat().NumSamplesMade() = std::max( queryNode.Stat().NumSamplesMade(), queryNode.Child(i).Stat().NumSamplesMade()); @@ -718,7 +718,7 @@ Rescore(TreeType& queryNode, const size_t queryIndex = queryNode.Descendant(i); math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t j = 0; j < distinctSamples.n_elem; j++) + for (size_t j = 0; j < distinctSamples.n_elem; ++j) // The counting of the samples are done in the 'BaseCase' // function so no book-keeping is required here. BaseCase(queryIndex, referenceNode.Descendant(distinctSamples[j])); @@ -747,7 +747,7 @@ Rescore(TreeType& queryNode, const size_t queryIndex = queryNode.Descendant(i); math::ObtainDistinctSamples(0, referenceNode.NumDescendants(), samplesReqd, distinctSamples); - for (size_t j = 0; j < distinctSamples.n_elem; j++) + for (size_t j = 0; j < distinctSamples.n_elem; ++j) // The counting of the samples are done in BaseCase() so no // book-keeping is required here. BaseCase(queryIndex, @@ -769,7 +769,7 @@ Rescore(TreeType& queryNode, { // We cannot sample from leaves, so we cannot prune. // Propagate the number of samples made down to the children. - for (size_t i = 0; i < queryNode.NumChildren(); i++) + for (size_t i = 0; i < queryNode.NumChildren(); ++i) queryNode.Child(i).Stat().NumSamplesMade() = std::max( queryNode.Stat().NumSamplesMade(), queryNode.Child(i).Stat().NumSamplesMade()); diff --git a/src/mlpack/methods/rann/ra_util.cpp b/src/mlpack/methods/rann/ra_util.cpp index fb8a6bb49a..50aceed04e 100644 --- a/src/mlpack/methods/rann/ra_util.cpp +++ b/src/mlpack/methods/rann/ra_util.cpp @@ -132,7 +132,7 @@ double mlpack::neighbor::RAUtil::SuccessProbability(const size_t n, sum = std::pow(eps, (double) m); } - for (size_t j = lb; j < ub; j++) + for (size_t j = lb; j < ub; ++j) { // Compute Choose(m, j). double mCj = (double) m; @@ -145,7 +145,7 @@ double mlpack::neighbor::RAUtil::SuccessProbability(const size_t n, else jTrans = m - j; - for (size_t i = 2; i <= jTrans; i++) + for (size_t i = 2; i <= jTrans; ++i) { mCj *= (double) (m - (i - 1)); mCj /= (double) i; diff --git a/src/mlpack/methods/regularized_svd/regularized_svd_function_impl.hpp b/src/mlpack/methods/regularized_svd/regularized_svd_function_impl.hpp index 571bccd9cc..6dc2510e27 100644 --- a/src/mlpack/methods/regularized_svd/regularized_svd_function_impl.hpp +++ b/src/mlpack/methods/regularized_svd/regularized_svd_function_impl.hpp @@ -101,7 +101,7 @@ void RegularizedSVDFunction::Gradient(const arma::mat& parameters, gradient.zeros(rank, numUsers + numItems); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { // Indices for accessing the the correct parameter columns. const size_t user = data(0, i); @@ -170,13 +170,13 @@ double StandardSGD::Optimize( double overallObjective = 0; // Calculate the first objective function. - for (size_t i = 0; i < numFunctions; i++) + for (size_t i = 0; i < numFunctions; ++i) overallObjective += function.Evaluate(parameters, i); const arma::mat data = function.Dataset(); // Now iterate! - for (size_t i = 1; i != maxIterations; i++, currentFunction++) + for (size_t i = 1; i != maxIterations; ++i, currentFunction++) { // Is this iteration the start of a sequence? if ((currentFunction % numFunctions) == 0) diff --git a/src/mlpack/methods/reinforcement_learning/replay/prioritized_replay.hpp b/src/mlpack/methods/reinforcement_learning/replay/prioritized_replay.hpp index 290d771977..9194f71291 100644 --- a/src/mlpack/methods/reinforcement_learning/replay/prioritized_replay.hpp +++ b/src/mlpack/methods/reinforcement_learning/replay/prioritized_replay.hpp @@ -238,7 +238,7 @@ class PrioritizedReplay size_t numSample = full ? capacity : position; weights = arma::rowvec(sampledIndices.n_rows); - for (size_t i = 0; i < sampledIndices.n_rows; i++) + for (size_t i = 0; i < sampledIndices.n_rows; ++i) { double p_sample = idxSum.Get(sampledIndices(i)) / idxSum.Sum(); weights(i) = pow(numSample * p_sample, -beta); diff --git a/src/mlpack/methods/reinforcement_learning/replay/sumtree.hpp b/src/mlpack/methods/reinforcement_learning/replay/sumtree.hpp index c2c3000c75..5ed0312304 100644 --- a/src/mlpack/methods/reinforcement_learning/replay/sumtree.hpp +++ b/src/mlpack/methods/reinforcement_learning/replay/sumtree.hpp @@ -74,7 +74,7 @@ class SumTree */ void BatchUpdate(const arma::ucolvec& indices, const arma::Col& data) { - for (size_t i = 0; i < indices.n_rows; i++) + for (size_t i = 0; i < indices.n_rows; ++i) { element[indices[i] + capacity] = data[i]; } diff --git a/src/mlpack/methods/softmax_regression/softmax_regression.cpp b/src/mlpack/methods/softmax_regression/softmax_regression.cpp index d3b6fe4aaf..ae39513df6 100644 --- a/src/mlpack/methods/softmax_regression/softmax_regression.cpp +++ b/src/mlpack/methods/softmax_regression/softmax_regression.cpp @@ -39,10 +39,10 @@ void SoftmaxRegression::Classify(const arma::mat& dataset, double maxProbability = 0; // For each test input. - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { // For each class. - for (size_t j = 0; j < numClasses; j++) + for (size_t j = 0; j < numClasses; ++j) { // If a higher class probability is encountered, change prediction. if (probabilities(j, i) > maxProbability) @@ -69,10 +69,10 @@ void SoftmaxRegression::Classify(const arma::mat& dataset, double maxProbability = 0; // For each test input. - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { // For each class. - for (size_t j = 0; j < numClasses; j++) + for (size_t j = 0; j < numClasses; ++j) { // If a higher class probability is encountered, change prediction. if (probabilities(j, i) > maxProbability) @@ -133,7 +133,7 @@ double SoftmaxRegression::ComputeAccuracy( // Increment count for every correctly predicted label. size_t count = 0; - for (size_t i = 0; i < predictions.n_elem; i++) + for (size_t i = 0; i < predictions.n_elem; ++i) if (predictions(i) == labels(i)) count++; diff --git a/src/mlpack/methods/softmax_regression/softmax_regression_function.cpp b/src/mlpack/methods/softmax_regression/softmax_regression_function.cpp index ded396e85b..2e8a93b79c 100644 --- a/src/mlpack/methods/softmax_regression/softmax_regression_function.cpp +++ b/src/mlpack/methods/softmax_regression/softmax_regression_function.cpp @@ -128,7 +128,7 @@ void SoftmaxRegressionFunction::GetGroundTruthMatrix( // Row pointers are the labels of the examples, and column pointers are the // number of cumulative entries made uptil that column. - for (size_t i = 0; i < labels.n_elem; i++) + for (size_t i = 0; i < labels.n_elem; ++i) { rowPointers(i) = labels(i); colPointers(i + 1) = i + 1; diff --git a/src/mlpack/methods/sparse_coding/sparse_coding.cpp b/src/mlpack/methods/sparse_coding/sparse_coding.cpp index 397c1ac195..c0b69082fe 100644 --- a/src/mlpack/methods/sparse_coding/sparse_coding.cpp +++ b/src/mlpack/methods/sparse_coding/sparse_coding.cpp @@ -127,7 +127,7 @@ double SparseCoding::OptimizeDictionary(const arma::mat& data, // vec dualVars = diagvec(solve(dictionary, data * trans(codes)) // - codes * trans(codes)); - // for (size_t i = 0; i < dualVars.n_elem; i++) + // for (size_t i = 0; i < dualVars.n_elem; ++i) // if (dualVars(i) < 0) // dualVars(i) = 0; @@ -242,7 +242,7 @@ double SparseCoding::OptimizeDictionary(const arma::mat& data, // Project each atom of the dictionary back into the unit ball (if necessary). void SparseCoding::ProjectDictionary() { - for (size_t j = 0; j < atoms; j++) + for (size_t j = 0; j < atoms; ++j) { double atomNorm = arma::norm(dictionary.col(j), 2); if (atomNorm > 1) diff --git a/src/mlpack/methods/svdplusplus/svdplusplus_function_impl.hpp b/src/mlpack/methods/svdplusplus/svdplusplus_function_impl.hpp index b3123f5f27..e5e0a3ce10 100644 --- a/src/mlpack/methods/svdplusplus/svdplusplus_function_impl.hpp +++ b/src/mlpack/methods/svdplusplus/svdplusplus_function_impl.hpp @@ -155,7 +155,7 @@ void SVDPlusPlusFunction::Gradient(const arma::mat& parameters, gradient.zeros(rank + 1, numUsers + 2 * numItems); - for (size_t i = 0; i < data.n_cols; i++) + for (size_t i = 0; i < data.n_cols; ++i) { // Indices for accessing the the correct parameter columns. const size_t user = data(0, i); @@ -305,7 +305,7 @@ double StandardSGD::Optimize( double overallObjective = 0; // Calculate the first objective function. - for (size_t i = 0; i < numFunctions; i++) + for (size_t i = 0; i < numFunctions; ++i) overallObjective += function.Evaluate(parameters, i); const arma::mat data = function.Dataset(); @@ -318,7 +318,7 @@ double StandardSGD::Optimize( const size_t rank = function.Rank(); // Now iterate! - for (size_t i = 1; i != maxIterations; i++, currentFunction++) + for (size_t i = 1; i != maxIterations; ++i, currentFunction++) { // Is this iteration the start of a sequence? if ((currentFunction % numFunctions) == 0) diff --git a/src/mlpack/tests/activation_functions_test.cpp b/src/mlpack/tests/activation_functions_test.cpp index 406dda4d7b..4325fb569b 100644 --- a/src/mlpack/tests/activation_functions_test.cpp +++ b/src/mlpack/tests/activation_functions_test.cpp @@ -57,7 +57,7 @@ void CheckActivationCorrect(const arma::colvec input, const arma::colvec target) { // Test the activation function using a single value as input. - for (size_t i = 0; i < target.n_elem; i++) + for (size_t i = 0; i < target.n_elem; ++i) { BOOST_REQUIRE_CLOSE(ActivationFunction::Fn(input.at(i)), target.at(i), 1e-3); @@ -66,7 +66,7 @@ void CheckActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; ActivationFunction::Fn(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -85,7 +85,7 @@ void CheckDerivativeCorrect(const arma::colvec input, const arma::colvec target) { // Test the calculation of the derivatives using a single value as input. - for (size_t i = 0; i < target.n_elem; i++) + for (size_t i = 0; i < target.n_elem; ++i) { BOOST_REQUIRE_CLOSE(ActivationFunction::Deriv(input.at(i)), target.at(i), 1e-3); @@ -94,7 +94,7 @@ void CheckDerivativeCorrect(const arma::colvec input, // Test the calculation of the derivatives using the entire vector as input. arma::colvec derivatives; ActivationFunction::Deriv(input, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -112,7 +112,7 @@ template void CheckInverseCorrect(const arma::colvec input) { // Test the calculation of the inverse using a single value as input. - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { BOOST_REQUIRE_CLOSE(ActivationFunction::Inv(ActivationFunction::Fn( input.at(i))), input.at(i), 1e-3); @@ -123,7 +123,7 @@ void CheckInverseCorrect(const arma::colvec input) ActivationFunction::Fn(input, activations); ActivationFunction::Inv(activations, activations); - for (size_t i = 0; i < input.n_elem; i++) + for (size_t i = 0; i < input.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), input.at(i), 1e-3); } @@ -144,7 +144,7 @@ void CheckHardTanHActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; htf.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -170,7 +170,7 @@ void CheckHardTanHDerivativeCorrect(const arma::colvec input, arma::colvec error = arma::ones(input.n_elem); htf.Backward(input, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -192,7 +192,7 @@ void CheckLeakyReLUActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; lrf.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -218,7 +218,7 @@ void CheckLeakyReLUDerivativeCorrect(const arma::colvec input, // This error vector will be set to 1 to get the derivatives. arma::colvec error = arma::ones(input.n_elem); lrf.Backward(input, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -240,7 +240,7 @@ void CheckELUActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; lrf.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -266,7 +266,7 @@ void CheckELUDerivativeCorrect(const arma::colvec input, arma::colvec error = arma::ones(input.n_elem); lrf.Forward(input, activations); lrf.Backward(activations, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -288,7 +288,7 @@ void CheckPReLUActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; prelu.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -314,7 +314,7 @@ void CheckPReLUDerivativeCorrect(const arma::colvec input, // This error vector will be set to 1 to get the derivatives. arma::colvec error = arma::ones(input.n_elem); prelu.Backward(input, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -360,7 +360,7 @@ void CheckHardShrinkActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; hardshrink.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -386,7 +386,7 @@ void CheckHardShrinkDerivativeCorrect(const arma::colvec input, // This error vector will be set to 1 to get the derivatives. arma::colvec error = arma::ones(input.n_elem); hardshrink.Backward(input, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -408,7 +408,7 @@ void CheckSoftShrinkActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; softshrink.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -434,7 +434,7 @@ void CheckSoftShrinkDerivativeCorrect(const arma::colvec input, // This error vector will be set to 1 to get the derivatives. arma::colvec error = arma::ones(input.n_elem); softshrink.Backward(input, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -529,7 +529,7 @@ void CheckCELUActivationCorrect(const arma::colvec input, // Test the activation function using the entire vector as input. arma::colvec activations; lrf.Forward(input, activations); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3); } @@ -555,7 +555,7 @@ void CheckCELUDerivativeCorrect(const arma::colvec input, arma::colvec error = arma::ones(input.n_elem); lrf.Forward(input, activations); lrf.Backward(activations, error, derivatives); - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3); } @@ -742,11 +742,11 @@ BOOST_AUTO_TEST_CASE(CReLUFunctionTest) // This error vector will be set to 1 to get the derivatives. arma::colvec error = arma::ones(desiredActivations.n_elem); crelu.Backward(desiredActivations, error, derivatives); - for (size_t i = 0; i < activations.n_elem; i++) + for (size_t i = 0; i < activations.n_elem; ++i) { BOOST_REQUIRE_CLOSE(activations.at(i), desiredActivations.at(i), 1e-3); } - for (size_t i = 0; i < derivatives.n_elem; i++) + for (size_t i = 0; i < derivatives.n_elem; ++i) { BOOST_REQUIRE_CLOSE(derivatives.at(i), desiredDerivatives.at(i), 1e-3); } diff --git a/src/mlpack/tests/adaboost_test.cpp b/src/mlpack/tests/adaboost_test.cpp index 4a8ccadc2d..4bba3dadef 100644 --- a/src/mlpack/tests/adaboost_test.cpp +++ b/src/mlpack/tests/adaboost_test.cpp @@ -587,7 +587,7 @@ BOOST_AUTO_TEST_CASE(ClassifyTest_VERTEBRALCOL) arma::colvec pRow; arma::uword maxIndex = 0; - for (size_t i = 0; i < predictedLabels1.n_cols; i++) + for (size_t i = 0; i < predictedLabels1.n_cols; ++i) { pRow = probabilities.unsafe_col(i); pRow.max(maxIndex); @@ -655,7 +655,7 @@ BOOST_AUTO_TEST_CASE(ClassifyTest_NONLINSEP) arma::colvec pRow; arma::uword maxIndex = 0; - for (size_t i = 0; i < predictedLabels1.n_cols; i++) + for (size_t i = 0; i < predictedLabels1.n_cols; ++i) { pRow = probabilities.unsafe_col(i); pRow.max(maxIndex); @@ -722,7 +722,7 @@ BOOST_AUTO_TEST_CASE(ClassifyTest_IRIS) arma::colvec pRow; arma::uword maxIndex = 0; - for (size_t i = 0; i < predictedLabels1.n_cols; i++) + for (size_t i = 0; i < predictedLabels1.n_cols; ++i) { pRow = probabilities.unsafe_col(i); pRow.max(maxIndex); diff --git a/src/mlpack/tests/akfn_test.cpp b/src/mlpack/tests/akfn_test.cpp index 0676842381..48d3022939 100644 --- a/src/mlpack/tests/akfn_test.cpp +++ b/src/mlpack/tests/akfn_test.cpp @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(ApproxVsExact1) arma::mat distancesApprox; akfn->Search(dataset, 15, neighborsApprox, distancesApprox); - for (size_t i = 0; i < neighborsApprox.n_elem; i++) + for (size_t i = 0; i < neighborsApprox.n_elem; ++i) REQUIRE_RELATIVE_ERR(distancesApprox(i), distancesExact(i), epsilon); // Clean the memory. @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(ApproxVsExact2) arma::mat distancesApprox; akfn.Search(15, neighborsApprox, distancesApprox); - for (size_t i = 0; i < neighborsApprox.n_elem; i++) + for (size_t i = 0; i < neighborsApprox.n_elem; ++i) REQUIRE_RELATIVE_ERR(distancesApprox[i], distancesExact[i], 0.05); } @@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsExact) arma::mat distancesApprox; akfn.Search(15, neighborsApprox, distancesApprox); - for (size_t i = 0; i < neighborsApprox.n_elem; i++) + for (size_t i = 0; i < neighborsApprox.n_elem; ++i) REQUIRE_RELATIVE_ERR(distancesApprox[i], distancesExact[i], 0.05); } diff --git a/src/mlpack/tests/aknn_test.cpp b/src/mlpack/tests/aknn_test.cpp index 3326abfe31..c9a584883e 100644 --- a/src/mlpack/tests/aknn_test.cpp +++ b/src/mlpack/tests/aknn_test.cpp @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(ApproxVsExact1) arma::mat distancesApprox; aknn->Search(dataset, 15, neighborsApprox, distancesApprox); - for (size_t i = 0; i < neighborsApprox.n_elem; i++) + for (size_t i = 0; i < neighborsApprox.n_elem; ++i) REQUIRE_RELATIVE_ERR(distancesApprox(i), distancesExact(i), epsilon); // Clean the memory. @@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(ApproxVsExact2) arma::mat distancesApprox; aknn.Search(15, neighborsApprox, distancesApprox); - for (size_t i = 0; i < neighborsApprox.n_elem; i++) + for (size_t i = 0; i < neighborsApprox.n_elem; ++i) REQUIRE_RELATIVE_ERR(distancesApprox(i), distancesExact(i), 0.05); } @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeApproxVsExact) arma::mat distancesApprox; aknn.Search(15, neighborsApprox, distancesApprox); - for (size_t i = 0; i < neighborsApprox.n_elem; i++) + for (size_t i = 0; i < neighborsApprox.n_elem; ++i) REQUIRE_RELATIVE_ERR(distancesApprox[i], distancesExact[i], 0.05); } diff --git a/src/mlpack/tests/ann_dist_test.cpp b/src/mlpack/tests/ann_dist_test.cpp index 31760d1d07..702414759a 100644 --- a/src/mlpack/tests/ann_dist_test.cpp +++ b/src/mlpack/tests/ann_dist_test.cpp @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(SimpleBernoulliDistributionTest) */ BOOST_AUTO_TEST_CASE(JacobianBernoulliDistributionTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t targetElements = math::RandInt(2, 1000); @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(JacobianBernoulliDistributionTest) */ BOOST_AUTO_TEST_CASE(JacobianBernoulliDistributionLogisticTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t targetElements = math::RandInt(2, 1000); diff --git a/src/mlpack/tests/ann_layer_test.cpp b/src/mlpack/tests/ann_layer_test.cpp index d75a92b6a7..6ab8036984 100644 --- a/src/mlpack/tests/ann_layer_test.cpp +++ b/src/mlpack/tests/ann_layer_test.cpp @@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(SimpleAddLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianAddLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t elements = math::RandInt(2, 1000); arma::mat input; @@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(SimpleConstantLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianConstantLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t elements = math::RandInt(2, 1000); arma::mat input; @@ -395,7 +395,7 @@ BOOST_AUTO_TEST_CASE(SimpleLinearLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianLinearLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElements = math::RandInt(2, 1000); const size_t outputElements = math::RandInt(2, 1000); @@ -575,7 +575,7 @@ BOOST_AUTO_TEST_CASE(SimplePaddingLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianLinearNoBiasLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElements = math::RandInt(2, 1000); const size_t outputElements = math::RandInt(2, 1000); @@ -639,7 +639,7 @@ BOOST_AUTO_TEST_CASE(GradientLinearNoBiasLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianNegativeLogLikelihoodLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { NegativeLogLikelihood<> module; const size_t inputElements = math::RandInt(5, 100); @@ -660,7 +660,7 @@ BOOST_AUTO_TEST_CASE(JacobianNegativeLogLikelihoodLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianLeakyReLULayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElements = math::RandInt(2, 1000); @@ -679,7 +679,7 @@ BOOST_AUTO_TEST_CASE(JacobianLeakyReLULayerTest) */ BOOST_AUTO_TEST_CASE(JacobianFlexibleReLULayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElements = math::RandInt(2, 1000); @@ -743,7 +743,7 @@ BOOST_AUTO_TEST_CASE(GradientFlexibleReLULayerTest) */ BOOST_AUTO_TEST_CASE(JacobianMultiplyConstantLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElements = math::RandInt(2, 1000); @@ -762,7 +762,7 @@ BOOST_AUTO_TEST_CASE(JacobianMultiplyConstantLayerTest) */ BOOST_AUTO_TEST_CASE(JacobianHardTanHLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElements = math::RandInt(2, 1000); @@ -2816,7 +2816,7 @@ BOOST_AUTO_TEST_CASE(ReparametrizationLayerIncludeKlTest) */ BOOST_AUTO_TEST_CASE(JacobianReparametrizationLayerTest) { - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { const size_t inputElementsHalf = math::RandInt(2, 1000); diff --git a/src/mlpack/tests/bias_svd_test.cpp b/src/mlpack/tests/bias_svd_test.cpp index e63b863a0d..9164b64bdf 100644 --- a/src/mlpack/tests/bias_svd_test.cpp +++ b/src/mlpack/tests/bias_svd_test.cpp @@ -46,13 +46,13 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionRandomEvaluate) // Make a BiasSVDFunction with zero regularization. BiasSVDFunction biasSVDFunc(data, rank, 0); - for (size_t i = 0; i < numTrials; i++) + for (size_t i = 0; i < numTrials; ++i) { arma::mat parameters = arma::randu(rank + 1, numUsers + numItems); // Calculate cost by summing up cost of each example. double cost = 0; - for (size_t j = 0; j < numRatings; j++) + for (size_t j = 0; j < numRatings; ++j) { const size_t user = data(0, j); const size_t item = data(1, j) + numUsers; @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionRegularizationEvaluate) BiasSVDFunction biasSVDFuncSmallReg(data, rank, 0.5); BiasSVDFunction biasSVDFuncBigReg(data, rank, 20); - for (size_t i = 0; i < numTrials; i++) + for (size_t i = 0; i < numTrials; ++i) { arma::mat parameters = arma::randu(rank + 1, numUsers + numItems); @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionRegularizationEvaluate) // each rating and sum them up. double smallRegTerm = 0; double bigRegTerm = 0; - for (size_t j = 0; j < numRatings; j++) + for (size_t j = 0; j < numRatings; ++j) { const size_t user = data(0, j); const size_t item = data(1, j) + numUsers; @@ -166,9 +166,9 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionGradient) double costPlus1, costMinus1, numGradient1; double costPlus2, costMinus2, numGradient2; - for (size_t i = 0; i < rank; i++) + for (size_t i = 0; i < rank; ++i) { - for (size_t j = 0; j < numUsers + numItems; j++) + for (size_t j = 0; j < numUsers + numItems; ++j) { // Perturb parameter with a positive constant and get costs. parameters(i, j) += epsilon; @@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionOptimize) data(1, numRatings - 1) = numItems - 1; // Make rating entries based on the parameters. - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; @@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionOptimize) // Get predicted ratings from optimized parameters. arma::mat predictedData(1, numRatings); - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; @@ -330,7 +330,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionParallelOptimize) data(1, numRatings - 1) = numItems - 1; // Make rating entries based on the parameters. - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; @@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(BiasSVDFunctionParallelOptimize) // Get predicted ratings from optimized parameters. arma::mat predictedData(1, numRatings); - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; diff --git a/src/mlpack/tests/callback_test.cpp b/src/mlpack/tests/callback_test.cpp index 5785d8ea34..a62ede95a8 100644 --- a/src/mlpack/tests/callback_test.cpp +++ b/src/mlpack/tests/callback_test.cpp @@ -211,12 +211,12 @@ BOOST_AUTO_TEST_CASE(SRWithOptimizerCallback) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; diff --git a/src/mlpack/tests/cf_test.cpp b/src/mlpack/tests/cf_test.cpp index d637f03752..c114268e75 100644 --- a/src/mlpack/tests/cf_test.cpp +++ b/src/mlpack/tests/cf_test.cpp @@ -132,7 +132,7 @@ void GetRecommendationsQueriedUser() // Create dummy query set. arma::Col users = arma::zeros >(numUsers, 1); - for (size_t i = 0; i < numUsers; i++) + for (size_t i = 0; i < numUsers; ++i) users(i) = i; // Matrix to save recommendations into. diff --git a/src/mlpack/tests/convolution_test.cpp b/src/mlpack/tests/convolution_test.cpp index 001f8bbc50..3640859177 100644 --- a/src/mlpack/tests/convolution_test.cpp +++ b/src/mlpack/tests/convolution_test.cpp @@ -51,7 +51,7 @@ void Convolution2DMethodTest(const arma::mat input, const double* outputPtr = output.memptr(); const double* convOutputPtr = convOutput.memptr(); - for (size_t i = 0; i < output.n_elem; i++, outputPtr++, convOutputPtr++) + for (size_t i = 0; i < output.n_elem; ++i, outputPtr++, convOutputPtr++) BOOST_REQUIRE_CLOSE(*outputPtr, *convOutputPtr, 1e-3); } @@ -82,7 +82,7 @@ void Convolution3DMethodTest(const arma::cube input, const double* outputPtr = output.memptr(); const double* convOutputPtr = convOutput.memptr(); - for (size_t i = 0; i < output.n_elem; i++, outputPtr++, convOutputPtr++) + for (size_t i = 0; i < output.n_elem; ++i, outputPtr++, convOutputPtr++) BOOST_REQUIRE_CLOSE(*outputPtr, *convOutputPtr, 1e-3); } @@ -114,7 +114,7 @@ void ConvolutionMethodBatchTest(const arma::mat input, const double* outputPtr = output.memptr(); const double* convOutputPtr = convOutput.memptr(); - for (size_t i = 0; i < output.n_elem; i++, outputPtr++, convOutputPtr++) + for (size_t i = 0; i < output.n_elem; ++i, outputPtr++, convOutputPtr++) BOOST_REQUIRE_CLOSE(*outputPtr, *convOutputPtr, 1e-3); } diff --git a/src/mlpack/tests/convolutional_network_test.cpp b/src/mlpack/tests/convolutional_network_test.cpp index 1f2634d9e4..39a7e161c3 100644 --- a/src/mlpack/tests/convolutional_network_test.cpp +++ b/src/mlpack/tests/convolutional_network_test.cpp @@ -36,14 +36,14 @@ BOOST_AUTO_TEST_CASE(VanillaNetworkTest) // Normalize each point since these are images. arma::uword nPoints = X.n_cols; - for (arma::uword i = 0; i < nPoints; i++) + for (arma::uword i = 0; i < nPoints; ++i) { X.col(i) /= norm(X.col(i), 2); } // Build the target matrix. arma::mat Y = arma::zeros(1, nPoints); - for (size_t i = 0; i < nPoints; i++) + for (size_t i = 0; i < nPoints; ++i) { if (i < nPoints / 2) { diff --git a/src/mlpack/tests/cosine_tree_test.cpp b/src/mlpack/tests/cosine_tree_test.cpp index f5f0f8a9f7..a08ee7f254 100644 --- a/src/mlpack/tests/cosine_tree_test.cpp +++ b/src/mlpack/tests/cosine_tree_test.cpp @@ -104,10 +104,10 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) cosines.zeros(currentNode->NumColumns()); size_t i, j, k; - for (i = 0; i < leftIndices.size(); i++) + for (i = 0; i < leftIndices.size(); ++i) cosines(i) = arma::norm_dot(data.col(leftIndices[i]), splitPoint); - for (j = 0, k = i; j < rightIndices.size(); j++, k++) + for (j = 0, k = i; j < rightIndices.size(); ++j, ++k) cosines(k) = arma::norm_dot(data.col(rightIndices[j]), splitPoint); // Check if the columns assigned to the children agree with the splitting @@ -124,11 +124,11 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) if (std::fabs(cosineMax - cosineMax2) < precision) { // Check with some precision. - for (i = 0; i < leftIndices.size(); i++) + for (i = 0; i < leftIndices.size(); ++i) BOOST_REQUIRE_LT(cosineMax - cosines(i), cosines(i) - cosineMin + precision); - for (j = 0, k = i; j < rightIndices.size(); j++, k++) + for (j = 0, k = i; j < rightIndices.size(); ++j, ++k) BOOST_REQUIRE_GT(cosineMax - cosines(k), cosines(k) - cosineMin - precision); } @@ -138,20 +138,20 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit) size_t numMax2Errors = 0; // Find errors for cosineMax. - for (i = 0; i < leftIndices.size(); i++) + for (i = 0; i < leftIndices.size(); ++i) if (cosineMax - cosines(i) >= cosines(i) - cosineMin + precision) numMax1Errors++; - for (j = 0, k = i; j < rightIndices.size(); j++, k++) + for (j = 0, k = i; j < rightIndices.size(); ++j, ++k) if (cosineMax - cosines(k) <= cosines(k) - cosineMin - precision) numMax1Errors++; // Find errors for cosineMax2. - for (i = 0; i < leftIndices.size(); i++) + for (i = 0; i < leftIndices.size(); ++i) if (cosineMax2 - cosines(i) >= cosines(i) - cosineMin + precision) numMax2Errors++; - for (j = 0, k = i; j < rightIndices.size(); j++, k++) + for (j = 0, k = i; j < rightIndices.size(); ++j, ++k) if (cosineMax2 - cosines(k) <= cosines(k) - cosineMin - precision) numMax2Errors++; @@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(CosineTreeModifiedGramSchmidt) CosineNodeQueue basisQueue; CosineTree dummyTree(data, epsilon, delta); - for (size_t i = 0; i < numCols; i++) + for (size_t i = 0; i < numCols; ++i) { // Make a new CosineNode object. CosineTree* basisNode; @@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE(CosineTreeModifiedGramSchmidt) CosineNodeQueue::const_iterator j = basisQueue.begin(); CosineTree* currentNode; - for (; j != basisQueue.end(); j++) + for (; j != basisQueue.end(); ++j) { currentNode = *j; BOOST_REQUIRE_SMALL(arma::dot(currentNode->BasisVector(), newBasisVector), @@ -212,7 +212,7 @@ BOOST_AUTO_TEST_CASE(CosineTreeModifiedGramSchmidt) } // Deallocate memory given to the objects. - for (size_t i = 0; i < numCols; i++) + for (size_t i = 0; i < numCols; ++i) { CosineTree* currentNode; currentNode = basisQueue.top(); @@ -316,7 +316,7 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorCosineTreeTest) } } - for (size_t i = 0; i < v1.size(); i++) + for (size_t i = 0; i < v1.size(); ++i) { BOOST_REQUIRE_EQUAL(v1.at(i), v2.at(i)); BOOST_REQUIRE_EQUAL(v1.at(i), v3.at(i)); @@ -429,7 +429,7 @@ BOOST_AUTO_TEST_CASE(MoveConstructorAndOperatorCosineTreeTest) } } - for (size_t i = 0; i < v1.size(); i++) + for (size_t i = 0; i < v1.size(); ++i) { BOOST_REQUIRE_EQUAL(v1.at(i), v2.at(i)); BOOST_REQUIRE_EQUAL(v1.at(i), v3.at(i)); diff --git a/src/mlpack/tests/dcgan_test.cpp b/src/mlpack/tests/dcgan_test.cpp index a0721928c9..0f6e016600 100644 --- a/src/mlpack/tests/dcgan_test.cpp +++ b/src/mlpack/tests/dcgan_test.cpp @@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE(DCGANMNISTTest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); @@ -292,7 +292,7 @@ BOOST_AUTO_TEST_CASE(DCGANMNISTTest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); @@ -448,7 +448,7 @@ BOOST_AUTO_TEST_CASE(DCGANCelebATest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); diff --git a/src/mlpack/tests/decision_stump_test.cpp b/src/mlpack/tests/decision_stump_test.cpp index a3e39bf039..58418ff416 100644 --- a/src/mlpack/tests/decision_stump_test.cpp +++ b/src/mlpack/tests/decision_stump_test.cpp @@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(OneClass) Row predictedLabels; ds.Classify(testingData, predictedLabels); - for (size_t i = 0; i < predictedLabels.size(); i++) + for (size_t i = 0; i < predictedLabels.size(); ++i) BOOST_CHECK_EQUAL(predictedLabels(i), 1); } diff --git a/src/mlpack/tests/distribution_test.cpp b/src/mlpack/tests/distribution_test.cpp index 063d4a000e..35103130b9 100644 --- a/src/mlpack/tests/distribution_test.cpp +++ b/src/mlpack/tests/distribution_test.cpp @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(DiscreteDistributionRandomTest) actualProb.zeros(); - for (size_t i = 0; i < 50000; i++) + for (size_t i = 0; i < 50000; ++i) actualProb((size_t) (d.Random()[0] + 0.5))++; // Normalize. @@ -282,11 +282,11 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionDistributionConstructor) GaussianDistribution d(mean, covariance); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_CLOSE(d.Mean()[i], mean[i], 1e-5); - for (size_t i = 0; i < 3; i++) - for (size_t j = 0; j < 3; j++) + for (size_t i = 0; i < 3; ++i) + for (size_t j = 0; j < 3; ++j) BOOST_REQUIRE_CLOSE(d.Covariance()(i, j), covariance(i, j), 1e-5); } @@ -456,7 +456,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionRandomTest) arma::mat obs(2, 5000); - for (size_t i = 0; i < 5000; i++) + for (size_t i = 0; i < 5000; ++i) obs.col(i) = d.Random(); // Now make sure that reflects the actual distribution. @@ -488,7 +488,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) arma::mat observations(4, 10000); arma::mat transChol = trans(chol(cov)); - for (size_t i = 0; i < 10000; i++) + for (size_t i = 0; i < 10000; ++i) observations.col(i) = transChol * arma::randn(4) + mean; // Now estimate. @@ -501,11 +501,11 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainTest) d.Train(observations); // Check that everything is estimated right. - for (size_t i = 0; i < 4; i++) + for (size_t i = 0; i < 4; ++i) BOOST_REQUIRE_SMALL(d.Mean()[i] - actualMean[i], 1e-5); - for (size_t i = 0; i < 4; i++) - for (size_t j = 0; j < 4; j++) + for (size_t i = 0; i < 4; ++i) + for (size_t j = 0; j < 4; ++j) BOOST_REQUIRE_SMALL(d.Covariance()(i, j) - actualCov(i, j), 1e-5); } @@ -523,11 +523,11 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithProbabilitiesTest) size_t d = 1; arma::mat rdata(d, N); - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) rdata.col(i) = dist.Random(); arma::vec probabilities(N); - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) probabilities(i) = Random(); // Fit distribution with probabilities and data. @@ -560,7 +560,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionWithProbabilties1Test) arma::mat rdata(d, N); - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) rdata.col(i) = Random(); arma::vec probabilities(N, arma::fill::ones); @@ -605,7 +605,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) // Fill even numbered columns with random points from dist1 and odd numbered // columns with random points from dist2. - for (size_t j = 0; j < N; j++) + for (size_t j = 0; j < N; ++j) { if (j % 2 == 0) rdata.col(j) = dist1.Random(); @@ -615,7 +615,7 @@ BOOST_AUTO_TEST_CASE(GaussianDistributionTrainWithTwoDistProbabilitiesTest) // Assign high probabilities to points drawn from dist1 and low probabilities // to numbers drawn from dist2. - for (size_t i = 0 ; i < N ; i++) + for (size_t i = 0 ; i < N ; ++i) { if (i % 2 == 0) probabilities(i) = Random(0.98, 1); @@ -696,8 +696,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainWithProbabilitiesTest) size_t d = 2; arma::mat rdata(d, N); - for (size_t j = 0; j < d; j++) - for (size_t i = 0; i < N; i++) + for (size_t j = 0; j < d; ++j) + for (size_t i = 0; i < N; ++i) rdata(j, i) = dist(math::randGen); // Fill the probabilities randomly. @@ -740,8 +740,8 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainAllProbabilities1Test) size_t d = 2; arma::mat rdata(d, N); - for (size_t j = 0; j < d; j++) - for (size_t i = 0; i < N; i++) + for (size_t j = 0; j < d; ++j) + for (size_t i = 0; i < N; ++i) rdata(j, i) = dist(math::randGen); // Fit results with only data. @@ -785,9 +785,9 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) arma::vec probabilities(N); // Draw points alternately from the two different distributions. - for (size_t j = 0; j < d; j++) + for (size_t j = 0; j < d; ++j) { - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) { if (i % 2 == 0) rdata(j, i) = dist(math::randGen); @@ -796,7 +796,7 @@ BOOST_AUTO_TEST_CASE(GammaDistributionTrainTwoDistProbabilities1Test) } } - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) { if (i % 2 == 0) probabilities(i) = 0.02 * math::Random(); @@ -1282,7 +1282,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionConstructor) DiagonalGaussianDistribution d(mean, covariance); // Make sure the mean and covariance is correct. - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { BOOST_REQUIRE_CLOSE(d.Mean()(i), mean(i), 1e-5); BOOST_REQUIRE_CLOSE(d.Covariance()(i), covariance(i), 1e-5); @@ -1413,7 +1413,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionRandomTest) arma::mat obs(2, 5000); - for (size_t i = 0; i < 5000; i++) + for (size_t i = 0; i < 5000; ++i) obs.col(i) = d.Random(); // Make sure that reflects the actual distribution. @@ -1439,7 +1439,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) // Generate the observations. arma::mat observations(4, 10000); - for (size_t i = 0; i < 10000; i++) + for (size_t i = 0; i < 10000; ++i) observations.col(i) = (arma::sqrt(cov) % arma::randn(4)) + mean; DiagonalGaussianDistribution d; @@ -1452,7 +1452,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianDistributionTrainTest) d.Train(observations); // Check that the estimated parameters are right. - for (size_t i = 0; i < 4; i++) + for (size_t i = 0; i < 4; ++i) { BOOST_REQUIRE_SMALL(d.Mean()(i) - actualMean(i), 1e-5); BOOST_REQUIRE_SMALL(d.Covariance()(i) - actualCov(i, i), 1e-5); @@ -1503,7 +1503,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianWeightedParametersReductionTest) arma::mat obs(4, 5); arma::vec probs("0.2 0.2 0.2 0.2 0.2"); - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) obs.col(i) = (arma::sqrt(cov) % arma::randn(4)) + mean; DiagonalGaussianDistribution d1; @@ -1514,7 +1514,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGaussianWeightedParametersReductionTest) d2.Train(obs, probs); // Check if these are equal. - for (size_t i = 0; i < 4; i++) + for (size_t i = 0; i < 4; ++i) { BOOST_REQUIRE_CLOSE(d1.Mean()(i), d2.Mean()(i), 1e-5); BOOST_REQUIRE_CLOSE(d1.Covariance()(i), d2.Covariance()(i), 1e-5); diff --git a/src/mlpack/tests/emst_test.cpp b/src/mlpack/tests/emst_test.cpp index 3a17ebff67..608e0fd713 100644 --- a/src/mlpack/tests/emst_test.cpp +++ b/src/mlpack/tests/emst_test.cpp @@ -213,7 +213,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive) BOOST_REQUIRE_EQUAL(dualResults.n_cols, naiveResults.n_cols); BOOST_REQUIRE_EQUAL(dualResults.n_rows, naiveResults.n_rows); - for (size_t i = 0; i < dualResults.n_cols; i++) + for (size_t i = 0; i < dualResults.n_cols; ++i) { BOOST_REQUIRE_EQUAL(dualResults(0, i), naiveResults(0, i)); BOOST_REQUIRE_EQUAL(dualResults(1, i), naiveResults(1, i)); @@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE(CoverTreeTest) bst.ComputeMST(bstResults); ct.ComputeMST(coverResults); - for (size_t i = 0; i < bstResults.n_cols; i++) + for (size_t i = 0; i < bstResults.n_cols; ++i) { BOOST_REQUIRE_EQUAL(bstResults(0, i), coverResults(0, i)); BOOST_REQUIRE_EQUAL(bstResults(1, i), coverResults(1, i)); @@ -270,7 +270,7 @@ BOOST_AUTO_TEST_CASE(BallTreeTest) bst.ComputeMST(bstResults); ballt.ComputeMST(ballResults); - for (size_t i = 0; i < bstResults.n_cols; i++) + for (size_t i = 0; i < bstResults.n_cols; ++i) { BOOST_REQUIRE_EQUAL(bstResults(0, i), ballResults(0, i)); BOOST_REQUIRE_EQUAL(bstResults(1, i), ballResults(1, i)); diff --git a/src/mlpack/tests/gan_test.cpp b/src/mlpack/tests/gan_test.cpp index 3705e11570..c5ed9f7dff 100644 --- a/src/mlpack/tests/gan_test.cpp +++ b/src/mlpack/tests/gan_test.cpp @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE(GANTest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); @@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(GANMNISTTest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); diff --git a/src/mlpack/tests/gmm_test.cpp b/src/mlpack/tests/gmm_test.cpp index 16ce0a6b1b..5afbb8f38e 100644 --- a/src/mlpack/tests/gmm_test.cpp +++ b/src/mlpack/tests/gmm_test.cpp @@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussians) minDiff = std::abs(weights[i] - weights[j]); } while (minDiff < 0.02); - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) counts[i] = round(weights[i] * (data.n_cols - gaussians)); // Ensure one point minimum in each. counts += 1; @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussians) // Build each Gaussian individually. size_t point = 0; - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) { arma::mat gaussian; gaussian.randn(dims, counts[i]); @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussians) } // Calculate actual weights. - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) weights[i] = (double) counts[i] / data.n_cols; // Now train the model. @@ -228,7 +228,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussians) continue; // Check the model to see that it is correct. - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) { // Check the mean. BOOST_REQUIRE_LT( @@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMSingleGaussianWithProbability) // 10000 observations, each with random probability. arma::mat observations(2, 20000); - for (size_t i = 0; i < 20000; i++) + for (size_t i = 0; i < 20000; ++i) observations.col(i) = d.Random(); arma::vec probabilities; probabilities.randu(20000); // Random probabilities. @@ -310,7 +310,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussiansWithProbability) arma::mat points(3, 2000); arma::vec probabilities(2000); - for (size_t i = 0; i < 2000; i++) + for (size_t i = 0; i < 2000; ++i) { double randValue = math::Random(); @@ -354,7 +354,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussiansWithProbability) // First Gaussian (d1). BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[0]] - 0.2, 0.1); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_SMALL((g.Component(sortedIndices[0]).Mean()[i] - d1.Mean()[i]), 0.4); @@ -366,7 +366,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussiansWithProbability) // Second Gaussian (d2). BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[1]] - 0.3, 0.1); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_SMALL((g.Component(sortedIndices[1]).Mean()[i] - d2.Mean()[i]), 0.4); @@ -410,7 +410,7 @@ BOOST_AUTO_TEST_CASE(GMMRandomTest) // Now generate a bunch of observations. arma::mat observations(2, 4000); - for (size_t i = 0; i < 4000; i++) + for (size_t i = 0; i < 4000; ++i) observations.col(i) = gmm.Random(); // A new one which we'll train. @@ -664,7 +664,7 @@ BOOST_AUTO_TEST_CASE(UseExistingModelTest) weights /= accu(weights); } - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) counts[i] = round(weights[i] * (data.n_cols - gaussians)); // Ensure one point minimum in each. counts += 1; @@ -674,7 +674,7 @@ BOOST_AUTO_TEST_CASE(UseExistingModelTest) // Build each Gaussian individually. size_t point = 0; - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) { arma::mat gaussian; gaussian.randn(dims, counts[i]); @@ -703,7 +703,7 @@ BOOST_AUTO_TEST_CASE(UseExistingModelTest) } // Calculate actual weights. - for (size_t i = 0; i < gaussians; i++) + for (size_t i = 0; i < gaussians; ++i) weights[i] = (double) counts[i] / data.n_cols; // Now train the model. @@ -881,7 +881,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMOneGaussianWithProbability) // Generate 20000 observations, each with random probabilities. arma::mat observations(2, 20000); - for (size_t i = 0; i < 20000; i++) + for (size_t i = 0; i < 20000; ++i) observations.col(i) = d.Random(); // Random probabilities. @@ -925,7 +925,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussians) // Now we'll generate points and probabilities. arma::mat observations(3, 5000); - for (size_t i = 0; i < 5000; i++) + for (size_t i = 0; i < 5000; ++i) { double randValue = math::Random(); @@ -949,11 +949,11 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussians) // First Gaussian (d1). BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[0]] - 0.2, 0.1); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_SMALL((g.Component(sortedIndices[0]).Mean()[i] - d1.Mean()[i]), 0.4); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { const double v = g.Component(sortedIndices[0]).Covariance()(i); BOOST_REQUIRE_SMALL(v - d1.Covariance()(i), 0.5); @@ -962,11 +962,11 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussians) // Second Gaussian (d2). BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[1]] - 0.3, 0.1); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_SMALL((g.Component(sortedIndices[1]).Mean()[i] - d2.Mean()[i]), 0.4); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { const double v = g.Component(sortedIndices[1]).Covariance()(i); BOOST_REQUIRE_SMALL(v - d2.Covariance()(i), 0.5); @@ -979,7 +979,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussians) BOOST_REQUIRE_SMALL((g.Component(sortedIndices[2]).Mean()[i] - d3.Mean()[i]), 0.4); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { const double v = g.Component(sortedIndices[2]).Covariance()(i); BOOST_REQUIRE_SMALL(v - d3.Covariance()(i), 0.5); @@ -1005,7 +1005,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussiansWithProbability) // Now we'll generate observations and probabilities. arma::mat observations(3, 10000); - for (size_t i = 0; i < 10000; i++) + for (size_t i = 0; i < 10000; ++i) { double randValue = math::Random(); @@ -1032,11 +1032,11 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussiansWithProbability) // First Gaussian (d1). BOOST_REQUIRE_CLOSE(g.Weights()[sortedIndices[0]], 0.2, 10.0); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_CLOSE(g.Component(sortedIndices[0]).Mean()[i], d1.Mean()[i], 13.0); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { const double v = g.Component(sortedIndices[0]).Covariance()(i); BOOST_REQUIRE_CLOSE(v, d1.Covariance()(i), 17.0); @@ -1045,11 +1045,11 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussiansWithProbability) // Second Gaussian (d2). BOOST_REQUIRE_CLOSE(g.Weights()[sortedIndices[1]], 0.3, 10.0); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_CLOSE(g.Component(sortedIndices[1]).Mean()[i], d2.Mean()[i], 13.0); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { const double v = g.Component(sortedIndices[1]).Covariance()(i); BOOST_REQUIRE_CLOSE(v, d2.Covariance()(i), 17.0); @@ -1062,7 +1062,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMTrainEMMultipleGaussiansWithProbability) BOOST_REQUIRE_CLOSE(g.Component(sortedIndices[2]).Mean()[i], d3.Mean()[i], 13.0); - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) { const double v = g.Component(sortedIndices[2]).Covariance()(i); BOOST_REQUIRE_CLOSE(v, d3.Covariance()(i), 17.0); @@ -1088,7 +1088,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMRandomTest) // Now generate a bunch of observations. arma::mat observations(2, 4000); - for (size_t i = 0; i < 4000; i++) + for (size_t i = 0; i < 4000; ++i) observations.col(i) = gmm.Random(); // A new one which we'll train. @@ -1165,12 +1165,12 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMLoadSaveTest) BOOST_REQUIRE_EQUAL(gmm.Gaussians(), gmm2.Gaussians()); BOOST_REQUIRE_EQUAL(gmm.Dimensionality(), gmm2.Dimensionality()); - for (size_t i = 0; i < gmm.Dimensionality(); i++) + for (size_t i = 0; i < gmm.Dimensionality(); ++i) BOOST_REQUIRE_CLOSE(gmm.Weights()[i], gmm2.Weights()[i], 1e-3); - for (size_t i = 0; i < gmm.Gaussians(); i++) + for (size_t i = 0; i < gmm.Gaussians(); ++i) { - for (size_t j = 0; j < gmm.Dimensionality(); j++) + for (size_t j = 0; j < gmm.Dimensionality(); ++j) { BOOST_REQUIRE_CLOSE(gmm.Component(i).Mean()[j], gmm2.Component(i).Mean()[j], 1e-3); diff --git a/src/mlpack/tests/hmm_test.cpp b/src/mlpack/tests/hmm_test.cpp index 1365f4db16..8ec196d5f4 100644 --- a/src/mlpack/tests/hmm_test.cpp +++ b/src/mlpack/tests/hmm_test.cpp @@ -246,7 +246,7 @@ BOOST_AUTO_TEST_CASE(SimpleBaumWelchDiscreteHMM_2) size_t obsNum = 250; // Number of observations. size_t obsLen = 500; // Number of elements in each observation. size_t stateZeroStarts = 0; // Number of times we start in state 0. - for (size_t i = 0; i < obsNum; i++) + for (size_t i = 0; i < obsNum; ++i) { arma::mat observation(1, obsLen); @@ -428,7 +428,7 @@ BOOST_AUTO_TEST_CASE(DiscreteHMMSimpleGenerateTest) arma::vec stateProb(2); emissionProb.zeros(); stateProb.zeros(); - for (size_t i = 0; i < 100000; i++) + for (size_t i = 0; i < 100000; ++i) { emissionProb[(size_t) dataSeq.col(i)[0] + 0.5]++; stateProb[stateSeq[i]]++; @@ -480,7 +480,7 @@ BOOST_AUTO_TEST_CASE(DiscreteHMMGenerateTest) int numObs = 3000; std::vector sequences(numSeq); std::vector > states(numSeq); - for (int i = 0; i < numSeq; i++) + for (int i = 0; i < numSeq; ++i) { // Random starting state. size_t startState = math::RandInt(4); @@ -561,7 +561,7 @@ BOOST_AUTO_TEST_CASE(GaussianHMMSimpleTest) // 1000-observations sequence. classes[0] = 0; observations.col(0) = g1.Random(); - for (size_t i = 1; i < 1000; i++) + for (size_t i = 1; i < 1000; ++i) { double randValue = math::Random(); @@ -584,7 +584,7 @@ BOOST_AUTO_TEST_CASE(GaussianHMMSimpleTest) hmm.Estimate(observations, stateProb); // Check that each prediction is right. - for (size_t i = 0; i < 1000; i++) + for (size_t i = 0; i < 1000; ++i) { BOOST_REQUIRE_EQUAL(predictedClasses[i], classes[i]); @@ -906,7 +906,7 @@ BOOST_AUTO_TEST_CASE(GMMHMMPredictTest) states[0] = 0; observations.col(0) = gmms[0].Random(); - for (size_t i = 1; i < 1000; i++) + for (size_t i = 1; i < 1000; ++i) { double randValue = math::Random(); @@ -924,7 +924,7 @@ BOOST_AUTO_TEST_CASE(GMMHMMPredictTest) // Check that the predictions were correct. success = true; - for (size_t i = 0; i < 1000; i++) + for (size_t i = 0; i < 1000; ++i) { if (predictions[i] != states[i]) { @@ -978,7 +978,7 @@ BOOST_AUTO_TEST_CASE(GMMHMMLabeledTrainingTest) states[obs][0] = 0; observations[obs].col(0) = gmms[0].Random(); - for (size_t i = 1; i < 2500; i++) + for (size_t i = 1; i < 2500; ++i) { double randValue = (double) rand() / (double) RAND_MAX; @@ -1304,7 +1304,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMPredictTest) states[0] = 0; observations.col(0) = gmms[0].Random(); - for (size_t i = 1; i < 1000; i++) + for (size_t i = 1; i < 1000; ++i) { double randValue = math::Random(); @@ -1322,7 +1322,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMPredictTest) // Check them. success = true; - for (size_t i = 0; i < 1000; i++) + for (size_t i = 0; i < 1000; ++i) { if (predictions[i] != states[i]) { @@ -1395,7 +1395,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMOneGaussianOneStateTrainingTest) { observations[obs].col(0) = d.Random(); - for (size_t i = 1; i < 5000; i++) + for (size_t i = 1; i < 5000; ++i) { observations[obs].col(i) = d.Random(); } @@ -1446,7 +1446,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMOneGaussianUnlabeledTrainingTest) states[obs][0] = 0; observations[obs].col(0) = gmms[0].Random(); - for (size_t i = 1; i < 500; i++) + for (size_t i = 1; i < 500; ++i) { double randValue = math::Random(); @@ -1471,22 +1471,22 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMOneGaussianUnlabeledTrainingTest) BOOST_REQUIRE_SMALL(hmm.Initial()[1], 0.01); // Check the transition probability matrix. - for (size_t i = 0; i < 2; i++) - for (size_t j = 0; j < 2; j++) + for (size_t i = 0; i < 2; ++i) + for (size_t j = 0; j < 2; ++j) BOOST_REQUIRE_SMALL(hmm.Transition()(i, j) - transProbs(i, j), 0.08); // Check the estimated weights of the each emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) BOOST_REQUIRE_SMALL(hmm.Emission()[i].Weights()[0] - gmms[i].Weights()[0], 0.08); // Check the estimated means of the each emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) BOOST_REQUIRE_LT(arma::norm(hmm.Emission()[i].Component(0).Mean() - gmms[i].Component(0).Mean()), 0.2); // Check the estimated covariances of the each emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) BOOST_REQUIRE_LT(arma::norm(hmm.Emission()[i].Component(0).Covariance() - gmms[i].Component(0).Covariance()), 0.5); } @@ -1523,7 +1523,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMOneGaussianLabeledTrainingTest) states[obs][0] = 0; observations[obs].col(0) = gmms[0].Random(); - for (size_t i = 1; i < 5000; i++) + for (size_t i = 1; i < 5000; ++i) { double randValue = math::Random(); double probSum = 0; @@ -1553,22 +1553,22 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMOneGaussianLabeledTrainingTest) BOOST_REQUIRE_SMALL(hmm.Initial()[2], 0.01); // Check the transition probability matrix. - for (size_t i = 0; i < 3; i++) - for (size_t j = 0; j < 3; j++) + for (size_t i = 0; i < 3; ++i) + for (size_t j = 0; j < 3; ++j) BOOST_REQUIRE_SMALL(hmm.Transition()(i, j) - transProbs(i, j), 0.03); // Check the estimated weights of the each emission distribution. - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_SMALL(hmm.Emission()[i].Weights()[0] - gmms[i].Weights()[0], 0.08); // Check the estimated means of the each emission distribution. - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_LT(arma::norm(hmm.Emission()[i].Component(0).Mean() - gmms[i].Component(0).Mean()), 0.2); // Check the estimated covariances of the each emission distribution. - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_LT(arma::norm(hmm.Emission()[i].Component(0).Covariance() - gmms[i].Component(0).Covariance()), 0.5); } @@ -1607,7 +1607,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansUnlabeledTrainingTest) states[obs][0] = 0; observations[obs].col(0) = gmms[0].Random(); - for (size_t i = 1; i < 1000; i++) + for (size_t i = 1; i < 1000; ++i) { double randValue = math::Random(); @@ -1632,15 +1632,15 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansUnlabeledTrainingTest) BOOST_REQUIRE_SMALL(hmm.Initial()[1], 0.01); // Check the transition probability matrix. - for (size_t i = 0; i < 2; i++) - for (size_t j = 0; j < 2; j++) + for (size_t i = 0; i < 2; ++i) + for (size_t j = 0; j < 2; ++j) BOOST_REQUIRE_SMALL(hmm.Transition()(i, j) - transProbs(i, j), 0.08); // Sort by the estimated weights of the first emission distribution. arma::uvec sortedIndices = sort_index(hmm.Emission()[0].Weights()); // Check the first emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) { // Check the estimated weights using the first DiagonalGMM. BOOST_REQUIRE_SMALL(hmm.Emission()[0].Weights()[sortedIndices[i]] - @@ -1661,7 +1661,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansUnlabeledTrainingTest) sortedIndices = sort_index(hmm.Emission()[1].Weights()); // Check the second emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) { // Check the estimated weights using the second DiagonalGMM. BOOST_REQUIRE_SMALL(hmm.Emission()[1].Weights()[sortedIndices[i]] - @@ -1712,7 +1712,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansLabeledTrainingTest) states[obs][0] = 0; observations[obs].col(0) = gmms[0].Random(); - for (size_t i = 1; i < 2500; i++) + for (size_t i = 1; i < 2500; ++i) { double randValue = math::Random(); @@ -1736,15 +1736,15 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansLabeledTrainingTest) BOOST_REQUIRE_SMALL(hmm.Initial()[1], 0.01); // Check the transition probability matrix. - for (size_t i = 0; i < 2; i++) - for (size_t j = 0; j < 2; j++) + for (size_t i = 0; i < 2; ++i) + for (size_t j = 0; j < 2; ++j) BOOST_REQUIRE_SMALL(hmm.Transition()(i, j) - transProbs(i, j), 0.03); // Sort by the estimated weights of the first emission distribution. arma::uvec sortedIndices = sort_index(hmm.Emission()[0].Weights()); // Check the first emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) { // Check the estimated weights using the first DiagonalGMM. BOOST_REQUIRE_SMALL(hmm.Emission()[0].Weights()[sortedIndices[i]] - @@ -1765,7 +1765,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMMultipleGaussiansLabeledTrainingTest) sortedIndices = sort_index(hmm.Emission()[1].Weights()); // Check the second emission distribution. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) { // Check the estimated weights using the second DiagonalGMM. BOOST_REQUIRE_SMALL(hmm.Emission()[1].Weights()[sortedIndices[i]] - @@ -1792,10 +1792,10 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMLoadSaveTest) HMM hmm(3, DiagonalGMM(4, 3)); // Generate intial random values. - for (size_t j = 0; j < hmm.Emission().size(); j++) + for (size_t j = 0; j < hmm.Emission().size(); ++j) { hmm.Emission()[j].Weights().randu(); - for (size_t i = 0; i < hmm.Emission()[j].Gaussians(); i++) + for (size_t i = 0; i < hmm.Emission()[j].Gaussians(); ++i) { hmm.Emission()[j].Component(i).Mean().randu(); arma::vec covariance = arma::randu( @@ -1824,7 +1824,7 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMLoadSaveTest) // Remove clutter. remove("test-hmm-save.xml"); - for (size_t j = 0; j < hmm.Emission().size(); j++) + for (size_t j = 0; j < hmm.Emission().size(); ++j) { // Check the number of Gaussians. BOOST_REQUIRE_EQUAL(hmm.Emission()[j].Gaussians(), @@ -1834,12 +1834,12 @@ BOOST_AUTO_TEST_CASE(DiagonalGMMHMMLoadSaveTest) BOOST_REQUIRE_EQUAL(hmm.Emission()[j].Dimensionality(), hmm2.Emission()[j].Dimensionality()); - for (size_t i = 0; i < hmm.Emission()[j].Dimensionality(); i++) + for (size_t i = 0; i < hmm.Emission()[j].Dimensionality(); ++i) // Check the weights. BOOST_REQUIRE_CLOSE(hmm.Emission()[j].Weights()[i], hmm2.Emission()[j].Weights()[i], 1e-3); - for (size_t i = 0; i < hmm.Emission()[j].Gaussians(); i++) + for (size_t i = 0; i < hmm.Emission()[j].Gaussians(); ++i) { for (size_t l = 0; l < hmm.Emission()[j].Dimensionality(); l++) { diff --git a/src/mlpack/tests/hoeffding_tree_test.cpp b/src/mlpack/tests/hoeffding_tree_test.cpp index ea6783e4e0..c5b96e024a 100644 --- a/src/mlpack/tests/hoeffding_tree_test.cpp +++ b/src/mlpack/tests/hoeffding_tree_test.cpp @@ -1087,7 +1087,7 @@ BOOST_AUTO_TEST_CASE(ConfidenceChangeTest) while ((tree.NumChildren() == 0) && (i < 9000)) { tree.Train(dataset.col(i), labels[i]); - i++; + ++i; } BOOST_REQUIRE_LT(i, 9000); @@ -1102,7 +1102,7 @@ BOOST_AUTO_TEST_CASE(ConfidenceChangeTest) while ((tree.NumChildren() == 0) && (i < 90000)) { tree.Train(dataset.col(i % 9000), labels[i % 9000]); - i++; + ++i; } for (size_t c = 0; c < tree.NumChildren(); ++c) diff --git a/src/mlpack/tests/hyperplane_test.cpp b/src/mlpack/tests/hyperplane_test.cpp index 95ac43c368..748d9577ef 100644 --- a/src/mlpack/tests/hyperplane_test.cpp +++ b/src/mlpack/tests/hyperplane_test.cpp @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(HyperplaneEmptyConstructor) arma::mat dataset; dataset.randu(3, 20); // 20 points in 3 dimensions. - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { BOOST_REQUIRE(h1.Left(dataset.col(i))); BOOST_REQUIRE(h2.Left(dataset.col(i))); diff --git a/src/mlpack/tests/init_rules_test.cpp b/src/mlpack/tests/init_rules_test.cpp index 6776ba4071..5f7aba0231 100644 --- a/src/mlpack/tests/init_rules_test.cpp +++ b/src/mlpack/tests/init_rules_test.cpp @@ -61,15 +61,15 @@ BOOST_AUTO_TEST_CASE(OrthogonalInitTest) arma::mat orthogonalWeights = arma::eye(100, 100); weights *= weights.t(); - for (size_t i = 0; i < weights.n_rows; i++) - for (size_t j = 0; j < weights.n_cols; j++) + for (size_t i = 0; i < weights.n_rows; ++i) + for (size_t j = 0; j < weights.n_cols; ++j) BOOST_REQUIRE_SMALL(weights.at(i, j) - orthogonalWeights.at(i, j), 1e-3); orthogonalInit.Initialize(weights, 200, 100); weights = weights.t() * weights; - for (size_t i = 0; i < weights.n_rows; i++) - for (size_t j = 0; j < weights.n_cols; j++) + for (size_t i = 0; i < weights.n_rows; ++i) + for (size_t j = 0; j < weights.n_cols; ++j) BOOST_REQUIRE_SMALL(weights.at(i, j) - orthogonalWeights.at(i, j), 1e-3); } @@ -88,8 +88,8 @@ BOOST_AUTO_TEST_CASE(OrthogonalInitGainTest) orthogonalWeights *= (gain * gain); weights *= weights.t(); - for (size_t i = 0; i < weights.n_rows; i++) - for (size_t j = 0; j < weights.n_cols; j++) + for (size_t i = 0; i < weights.n_rows; ++i) + for (size_t j = 0; j < weights.n_cols; ++j) BOOST_REQUIRE_SMALL(weights.at(i, j) - orthogonalWeights.at(i, j), 1e-3); } diff --git a/src/mlpack/tests/kfn_test.cpp b/src/mlpack/tests/kfn_test.cpp index 63b3e38f18..a9a9654ff1 100644 --- a/src/mlpack/tests/kfn_test.cpp +++ b/src/mlpack/tests/kfn_test.cpp @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) TreeType tree(data, oldFromNew, newFromOld, 1); KFN kfn(std::move(tree)); - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; ++i) { switch (i) { @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) arma::mat distancesNaive; naive.Search(dataset, 15, neighborsNaive, distancesNaive); - for (size_t i = 0; i < neighborsTree.n_elem; i++) + for (size_t i = 0; i < neighborsTree.n_elem; ++i) { BOOST_REQUIRE(neighborsTree[i] == neighborsNaive[i]); BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5); @@ -385,7 +385,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) arma::mat distancesNaive; naive.Search(15, neighborsNaive, distancesNaive); - for (size_t i = 0; i < neighborsTree.n_elem; i++) + for (size_t i = 0; i < neighborsTree.n_elem; ++i) { BOOST_REQUIRE_EQUAL(neighborsTree[i], neighborsNaive[i]); BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5); @@ -419,7 +419,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) arma::mat distancesNaive; naive.Search(15, neighborsNaive, distancesNaive); - for (size_t i = 0; i < neighborsTree.n_elem; i++) + for (size_t i = 0; i < neighborsTree.n_elem; ++i) { BOOST_REQUIRE_EQUAL(neighborsTree[i], neighborsNaive[i]); BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5); diff --git a/src/mlpack/tests/kmeans_test.cpp b/src/mlpack/tests/kmeans_test.cpp index e03dbafeeb..df879a048f 100644 --- a/src/mlpack/tests/kmeans_test.cpp +++ b/src/mlpack/tests/kmeans_test.cpp @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(KMeansSimpleTest) // clusters are ordered, so we have to be careful about that. size_t firstClass = assignments(0); - for (size_t i = 1; i < 13; i++) + for (size_t i = 1; i < 13; ++i) BOOST_REQUIRE_EQUAL(assignments(i), firstClass); size_t secondClass = assignments(13); @@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(KMeansSimpleTest) // To ensure that class 1 != class 2. BOOST_REQUIRE_NE(firstClass, secondClass); - for (size_t i = 13; i < 20; i++) + for (size_t i = 13; i < 20; ++i) BOOST_REQUIRE_EQUAL(assignments(i), secondClass); size_t thirdClass = assignments(20); @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(KMeansSimpleTest) BOOST_REQUIRE_NE(firstClass, thirdClass); BOOST_REQUIRE_NE(secondClass, thirdClass); - for (size_t i = 20; i < 30; i++) + for (size_t i = 20; i < 30; ++i) BOOST_REQUIRE_EQUAL(assignments(i), thirdClass); } @@ -128,11 +128,11 @@ BOOST_AUTO_TEST_CASE(AllowEmptyClusterTest) metric, 0); // Make sure no assignments were changed. - for (size_t i = 0; i < assignments.n_elem; i++) + for (size_t i = 0; i < assignments.n_elem; ++i) BOOST_REQUIRE_EQUAL(assignments[i], assignmentsOld[i]); // Make sure no counts were changed. - for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; ++i) BOOST_REQUIRE_EQUAL(counts[i], countsOld[i]); } @@ -161,11 +161,11 @@ BOOST_AUTO_TEST_CASE(KillEmptyClusterTest) metric, 0); // Make sure no assignments were changed. - for (size_t i = 0; i < assignments.n_elem; i++) + for (size_t i = 0; i < assignments.n_elem; ++i) BOOST_REQUIRE_EQUAL(assignments[i], assignmentsOld[i]); // Make sure no counts were changed for clusters that are not empty. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) BOOST_REQUIRE_EQUAL(counts[i], countsOld[i]); // Make sure that counts contain one less element than old counts. @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(MaxVarianceNewClusterTest) double minDistance = std::numeric_limits::infinity(); size_t closestCluster = centroids.n_cols; // Invalid value. - for (size_t j = 0; j < centroids.n_cols; j++) + for (size_t j = 0; j < centroids.n_cols; ++j) { const double distance = metric.Evaluate(data.col(i), centroids.col(j)); @@ -249,7 +249,7 @@ BOOST_AUTO_TEST_CASE(RandomPartitionTest) BOOST_REQUIRE_EQUAL(assignments.n_elem, 1000); // Ensure that no value is greater than 17 (the maximum valid cluster). - for (size_t i = 0; i < 1000; i++) + for (size_t i = 0; i < 1000; ++i) BOOST_REQUIRE_LT(assignments[i], 18); } diff --git a/src/mlpack/tests/knn_test.cpp b/src/mlpack/tests/knn_test.cpp index 460fef8511..ac6f429627 100644 --- a/src/mlpack/tests/knn_test.cpp +++ b/src/mlpack/tests/knn_test.cpp @@ -383,7 +383,7 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) KNN knn(std::move(tree)); - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; ++i) { switch (i) { @@ -678,7 +678,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) arma::mat distancesNaive; naive.Search(dataset, 15, neighborsNaive, distancesNaive); - for (size_t i = 0; i < neighborsTree.n_elem; i++) + for (size_t i = 0; i < neighborsTree.n_elem; ++i) { BOOST_REQUIRE_EQUAL(neighborsTree(i), neighborsNaive(i)); BOOST_REQUIRE_CLOSE(distancesTree(i), distancesNaive(i), 1e-5); @@ -713,7 +713,7 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) arma::mat distancesNaive; naive.Search(15, neighborsNaive, distancesNaive); - for (size_t i = 0; i < neighborsTree.n_elem; i++) + for (size_t i = 0; i < neighborsTree.n_elem; ++i) { BOOST_REQUIRE_EQUAL(neighborsTree[i], neighborsNaive[i]); BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5); @@ -748,7 +748,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) arma::mat distancesNaive; naive.Search(15, neighborsNaive, distancesNaive); - for (size_t i = 0; i < neighborsTree.n_elem; i++) + for (size_t i = 0; i < neighborsTree.n_elem; ++i) { BOOST_REQUIRE_EQUAL(neighborsTree[i], neighborsNaive[i]); BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5); diff --git a/src/mlpack/tests/krann_search_test.cpp b/src/mlpack/tests/krann_search_test.cpp index 7762ef83e9..87c8bffa83 100644 --- a/src/mlpack/tests/krann_search_test.cpp +++ b/src/mlpack/tests/krann_search_test.cpp @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(NaiveGuaranteeTest) { rsRann.Search(queryData, 1, neighbors, distances); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (qrRanks(i, neighbors(0, i)) < expectedRankErrorUB) numSuccessRounds[i]++; @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(NaiveGuaranteeTest) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -116,7 +116,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeSearch) { tssRann.Search(queryData, 1, neighbors, distances); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (qrRanks(i, neighbors(0, i)) < expectedRankErrorUB) numSuccessRounds[i]++; @@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeSearch) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(DualTreeSearch) { tsdRann.Search(&queryTree, 1, neighbors, distances); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) { const size_t oldIndex = oldFromNewQueries[i]; if (qrRanks(oldIndex, neighbors(0, i)) < expectedRankErrorUB) @@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE(DualTreeSearch) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -305,7 +305,7 @@ BOOST_AUTO_TEST_CASE(SingleCoverTreeTest) { tssRann.Search(queryData, 1, neighbors, distances); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (qrRanks(i, neighbors(0, i)) < expectedRankErrorUB) numSuccessRounds[i]++; @@ -318,7 +318,7 @@ BOOST_AUTO_TEST_CASE(SingleCoverTreeTest) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -370,7 +370,7 @@ BOOST_AUTO_TEST_CASE(DualCoverTreeTest) { tsdRann.Search(&queryTree, 1, neighbors, distances); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (qrRanks(i, neighbors(0, i)) < expectedRankErrorUB) numSuccessRounds[i]++; @@ -385,7 +385,7 @@ BOOST_AUTO_TEST_CASE(DualCoverTreeTest) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -437,7 +437,7 @@ BOOST_AUTO_TEST_CASE(SingleBallTreeTest) { tssRann.Search(1, neighbors, distances, 1.0, 0.95, false, false, 5); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (qrRanks(i, neighbors(0, i)) < expectedRankErrorUB) numSuccessRounds[i]++; @@ -450,7 +450,7 @@ BOOST_AUTO_TEST_CASE(SingleBallTreeTest) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -502,7 +502,7 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) { tsdRann.Search(1, neighbors, distances, 1.0, 0.95, false, false, 5); - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (qrRanks(i, neighbors(0, i)) < expectedRankErrorUB) numSuccessRounds[i]++; @@ -517,7 +517,7 @@ BOOST_AUTO_TEST_CASE(DualBallTreeTest) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t i = 0; i < queryData.n_cols; i++) + for (size_t i = 0; i < queryData.n_cols; ++i) if (numSuccessRounds[i] < threshold) numQueriesFail++; @@ -689,7 +689,7 @@ BOOST_AUTO_TEST_CASE(RAModelTest) { arma::mat queryCopy(queryData); models[i].Search(std::move(queryCopy), 1, neighbors, distances); - for (size_t k = 0; k < queryData.n_cols; k++) + for (size_t k = 0; k < queryData.n_cols; ++k) if (qrRanks(k, neighbors(0, k)) < expectedRankErrorUB) numSuccessRounds[k]++; @@ -702,7 +702,7 @@ BOOST_AUTO_TEST_CASE(RAModelTest) size_t threshold = floor(numRounds * (0.95 - (1.96 * sqrt(0.95 * 0.05 / numRounds)))); size_t numQueriesFail = 0; - for (size_t k = 0; k < queryData.n_cols; k++) + for (size_t k = 0; k < queryData.n_cols; ++k) if (numSuccessRounds[k] < threshold) numQueriesFail++; diff --git a/src/mlpack/tests/lars_test.cpp b/src/mlpack/tests/lars_test.cpp index 16a9f73055..cbbe5687a3 100644 --- a/src/mlpack/tests/lars_test.cpp +++ b/src/mlpack/tests/lars_test.cpp @@ -35,7 +35,7 @@ void LARSVerifyCorrectness(arma::vec beta, arma::vec errCorr, double lambda) { size_t nDims = beta.n_elem; const double tol = 1e-10; - for (size_t j = 0; j < nDims; j++) + for (size_t j = 0; j < nDims; ++j) { if (beta(j) == 0) { @@ -60,7 +60,7 @@ void LassoTest(size_t nPoints, size_t nDims, bool elasticNet, bool useCholesky) arma::mat X; arma::rowvec y; - for (size_t i = 0; i < 100; i++) + for (size_t i = 0; i < 100; ++i) { GenerateProblem(X, y, nPoints, nDims); diff --git a/src/mlpack/tests/lin_alg_test.cpp b/src/mlpack/tests/lin_alg_test.cpp index b74c9e323a..47a4448804 100644 --- a/src/mlpack/tests/lin_alg_test.cpp +++ b/src/mlpack/tests/lin_alg_test.cpp @@ -179,8 +179,8 @@ BOOST_AUTO_TEST_CASE(TestSvecSmat) Smat(sx, Xtest); BOOST_REQUIRE_EQUAL(Xtest.n_rows, 3); BOOST_REQUIRE_EQUAL(Xtest.n_cols, 3); - for (size_t i = 0; i < 3; i++) - for (size_t j = 0; j < 3; j++) + for (size_t i = 0; i < 3; ++i) + for (size_t j = 0; j < 3; ++j) BOOST_REQUIRE_CLOSE(X(i, j), Xtest(i, j), 1e-7); } @@ -227,7 +227,7 @@ BOOST_AUTO_TEST_CASE(TestSymKronIdSimple) Svec(Rhs, rhs); BOOST_REQUIRE_EQUAL(lhs.n_elem, rhs.n_elem); - for (size_t j = 0; j < lhs.n_elem; j++) + for (size_t j = 0; j < lhs.n_elem; ++j) BOOST_REQUIRE_CLOSE(lhs(j), rhs(j), 1e-5); } @@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE(TestSymKronId) arma::mat Op; SymKronId(A, Op); - for (size_t i = 0; i < 5; i++) + for (size_t i = 0; i < 5; ++i) { arma::mat X = arma::randu(n, n); X += X.t(); @@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(TestSymKronId) Svec(Rhs, rhs); BOOST_REQUIRE_EQUAL(lhs.n_elem, rhs.n_elem); - for (size_t j = 0; j < lhs.n_elem; j++) + for (size_t j = 0; j < lhs.n_elem; ++j) BOOST_REQUIRE_CLOSE(lhs(j), rhs(j), 1e-5); } } diff --git a/src/mlpack/tests/linear_svm_test.cpp b/src/mlpack/tests/linear_svm_test.cpp index 9934f959c9..1a52264e8a 100644 --- a/src/mlpack/tests/linear_svm_test.cpp +++ b/src/mlpack/tests/linear_svm_test.cpp @@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionRandomBinaryEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // Create a LinearSVMFunction, Regularization term ignored. @@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionRandomEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // Create a LinearSVMFunction, Regularization term ignored. @@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionRegularizationEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // 3 objects for comparing regularization costs. @@ -220,7 +220,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionRegularizationEvaluate) LinearSVMFunction svmfBigReg(data, labels, numClasses, 20); // Run a number of trials. - for (size_t i = 0; i < trials; i++) + for (size_t i = 0; i < trials; ++i) { // Create a random set of parameters. arma::mat parameters; @@ -257,7 +257,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionSeparableEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); LinearSVMFunction<> svmf(data, labels, numClasses); @@ -297,7 +297,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionRegularizationSeparableEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); LinearSVMFunction<> svmfNoReg(data, labels, numClasses, 0.0); @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionGradient) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // Create a LinearSVMFunction, Regularization term ignored. @@ -423,7 +423,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMFunctionSeparableGradient) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); LinearSVMFunction<> svmfNoReg(data, labels, numClasses, 0.0); @@ -552,12 +552,12 @@ BOOST_AUTO_TEST_CASE(LinearSVMLBFGSTwoClasses) bool success = false; for (size_t trial = 0; trial < 5; ++trial) { - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -574,12 +574,12 @@ BOOST_AUTO_TEST_CASE(LinearSVMLBFGSTwoClasses) } // Create test dataset. - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -698,12 +698,12 @@ BOOST_AUTO_TEST_CASE(LinearSVMDeltaLBFGSTwoClasses) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -807,12 +807,12 @@ BOOST_AUTO_TEST_CASE(LinearSVMParallelSGDTwoClasses) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -833,12 +833,12 @@ BOOST_AUTO_TEST_CASE(LinearSVMParallelSGDTwoClasses) BOOST_REQUIRE_CLOSE(acc, 1.0, 2.0); // Create test dataset. - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -905,27 +905,27 @@ BOOST_AUTO_TEST_CASE(LinearSVMLBFGSMultipleClasses) bool success = false; for (size_t trial = 0; trial < 5; ++trial) { - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -940,27 +940,27 @@ BOOST_AUTO_TEST_CASE(LinearSVMLBFGSMultipleClasses) continue; // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -999,27 +999,27 @@ BOOST_AUTO_TEST_CASE(LinearSVMClassifySinglePointTest) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -1029,27 +1029,27 @@ BOOST_AUTO_TEST_CASE(LinearSVMClassifySinglePointTest) LinearSVM lsvm(data, labels, numClasses, lambda); // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -1085,27 +1085,27 @@ BOOST_AUTO_TEST_CASE(SinglePointClassifyTest) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -1115,27 +1115,27 @@ BOOST_AUTO_TEST_CASE(SinglePointClassifyTest) LinearSVM lsvm(data, labels, numClasses, lambda); // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; diff --git a/src/mlpack/tests/lmnn_test.cpp b/src/mlpack/tests/lmnn_test.cpp index 37caaed173..d903e60ffd 100644 --- a/src/mlpack/tests/lmnn_test.cpp +++ b/src/mlpack/tests/lmnn_test.cpp @@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(LMNNTargetNeighborsTest) // Calculate norm of datapoints. arma::vec norm(dataset.n_cols); - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { norm(i) = arma::norm(dataset.col(i)); } @@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(LMNNImpostorsTest) // Calculate norm of datapoints. arma::vec norm(dataset.n_cols); - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { norm(i) = arma::norm(dataset.col(i)); } @@ -409,12 +409,12 @@ double KnnAccuracy(const arma::mat& dataset, // Keep count. size_t count = 0.0; - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { arma::vec Map; Map.zeros(uniqueLabels.n_cols); - for (size_t j = 0; j < k; j++) + for (size_t j = 0; j < k; ++j) Map(labels(neighbors(j, i))) += 1 / std::pow(distances(j, i) + 1, 2); diff --git a/src/mlpack/tests/load_save_test.cpp b/src/mlpack/tests/load_save_test.cpp index 2c528ba796..301c7ccadf 100644 --- a/src/mlpack/tests/load_save_test.cpp +++ b/src/mlpack/tests/load_save_test.cpp @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(LoadCSVTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -174,7 +174,7 @@ BOOST_AUTO_TEST_CASE(LoadTSVTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE(LoadTSVExtensionTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(SaveCSVTest) BOOST_REQUIRE_EQUAL(test2.n_rows, 4); BOOST_REQUIRE_EQUAL(test2.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test2[i], (double) (i + 1), 1e-5); // Remove the file. @@ -759,7 +759,7 @@ BOOST_AUTO_TEST_CASE(LoadArmaASCIITest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -784,7 +784,7 @@ BOOST_AUTO_TEST_CASE(SaveArmaASCIITest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -810,7 +810,7 @@ BOOST_AUTO_TEST_CASE(LoadRawASCIITest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -836,7 +836,7 @@ BOOST_AUTO_TEST_CASE(LoadCSVTxtTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -863,7 +863,7 @@ BOOST_AUTO_TEST_CASE(LoadArmaBinaryTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -887,7 +887,7 @@ BOOST_AUTO_TEST_CASE(SaveArmaBinaryTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -914,7 +914,7 @@ BOOST_AUTO_TEST_CASE(LoadRawBinaryTest) BOOST_REQUIRE_EQUAL(test.n_rows, 1); BOOST_REQUIRE_EQUAL(test.n_cols, 8); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -941,7 +941,7 @@ BOOST_AUTO_TEST_CASE(LoadPGMBinaryTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. @@ -966,7 +966,7 @@ BOOST_AUTO_TEST_CASE(SavePGMBinaryTest) BOOST_REQUIRE_EQUAL(test.n_rows, 4); BOOST_REQUIRE_EQUAL(test.n_cols, 2); - for (size_t i = 0; i < 8; i++) + for (size_t i = 0; i < 8; ++i) BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5); // Remove the file. diff --git a/src/mlpack/tests/local_coordinate_coding_test.cpp b/src/mlpack/tests/local_coordinate_coding_test.cpp index e282bba586..d96f3dc9e6 100644 --- a/src/mlpack/tests/local_coordinate_coding_test.cpp +++ b/src/mlpack/tests/local_coordinate_coding_test.cpp @@ -29,7 +29,7 @@ void VerifyCorrectness(const vec& beta, const vec& errCorr, double lambda) { const double tol = 0.1; size_t nDims = beta.n_elem; - for (size_t j = 0; j < nDims; j++) + for (size_t j = 0; j < nDims; ++j) { if (beta(j) == 0) { @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(LocalCoordinateCodingTestCodingStep) uword nPoints = X.n_cols; // normalize each point since these are images - for (uword i = 0; i < nPoints; i++) + for (uword i = 0; i < nPoints; ++i) { X.col(i) /= norm(X.col(i), 2); } @@ -71,10 +71,10 @@ BOOST_AUTO_TEST_CASE(LocalCoordinateCodingTestCodingStep) mat D = lcc.Dictionary(); - for (uword i = 0; i < nPoints; i++) + for (uword i = 0; i < nPoints; ++i) { vec sqDists = vec(nAtoms); - for (uword j = 0; j < nAtoms; j++) + for (uword j = 0; j < nAtoms; ++j) { sqDists[j] = arma::norm(D.col(j) - X.col(i)); } @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(LocalCoordinateCodingTestDictionaryStep) uword nPoints = X.n_cols; // normalize each point since these are images - for (uword i = 0; i < nPoints; i++) + for (uword i = 0; i < nPoints; ++i) { X.col(i) /= norm(X.col(i), 2); } @@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(LocalCoordinateCodingTestDictionaryStep) mat D = lcc.Dictionary(); mat grad = zeros(D.n_rows, D.n_cols); - for (uword i = 0; i < nPoints; i++) + for (uword i = 0; i < nPoints; ++i) { grad += (D - repmat(X.unsafe_col(i), 1, nAtoms)) * diagmat(abs(Z.unsafe_col(i))); @@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(LocalCoordinateCodingTrainReturnObjective) uword nPoints = X.n_cols; // Normalize each point since these are images. - for (uword i = 0; i < nPoints; i++) + for (uword i = 0; i < nPoints; ++i) { X.col(i) /= norm(X.col(i), 2); } diff --git a/src/mlpack/tests/loss_functions_test.cpp b/src/mlpack/tests/loss_functions_test.cpp index 75485fda5c..a750ade85d 100644 --- a/src/mlpack/tests/loss_functions_test.cpp +++ b/src/mlpack/tests/loss_functions_test.cpp @@ -274,7 +274,7 @@ BOOST_AUTO_TEST_CASE(SimpleSigmoidCrossEntropyErrorTest) // Test the Backward function. module.Backward(input1, target1, output); expected = 0.62245929; - for (size_t i = 0; i < output.n_elem; i++) + for (size_t i = 0; i < output.n_elem; ++i) BOOST_REQUIRE_SMALL(output(i) - expected, 1e-5); BOOST_REQUIRE_EQUAL(output.n_rows, input1.n_rows); BOOST_REQUIRE_EQUAL(output.n_cols, input1.n_cols); @@ -282,7 +282,7 @@ BOOST_AUTO_TEST_CASE(SimpleSigmoidCrossEntropyErrorTest) expectedOutput = arma::mat( "0.7310586 0.88079709 -0.04742587 0.98201376 -0.00669285"); module.Backward(input2, target2, output); - for (size_t i = 0; i < output.n_elem; i++) + for (size_t i = 0; i < output.n_elem; ++i) BOOST_REQUIRE_SMALL(output(i) - expectedOutput(i), 1e-5); BOOST_REQUIRE_EQUAL(output.n_rows, input2.n_rows); BOOST_REQUIRE_EQUAL(output.n_cols, input2.n_cols); @@ -326,14 +326,14 @@ BOOST_AUTO_TEST_CASE(SimpleEarthMoverDistanceLayerTest) // Test the Backward function. module.Backward(input1, target1, output); expected = 0.0; - for (size_t i = 0; i < output.n_elem; i++) + for (size_t i = 0; i < output.n_elem; ++i) BOOST_REQUIRE_SMALL(output(i) - expected, 1e-5); BOOST_REQUIRE_EQUAL(output.n_rows, input1.n_rows); BOOST_REQUIRE_EQUAL(output.n_cols, input1.n_cols); expectedOutput = arma::mat("-1 0 -1 0 -1"); module.Backward(input2, target2, output); - for (size_t i = 0; i < output.n_elem; i++) + for (size_t i = 0; i < output.n_elem; ++i) BOOST_REQUIRE_SMALL(output(i) - expectedOutput(i), 1e-5); BOOST_REQUIRE_EQUAL(output.n_rows, input2.n_rows); BOOST_REQUIRE_EQUAL(output.n_cols, input2.n_cols); diff --git a/src/mlpack/tests/main_tests/adaboost_test.cpp b/src/mlpack/tests/main_tests/adaboost_test.cpp index a7ab26555f..495f381864 100644 --- a/src/mlpack/tests/main_tests/adaboost_test.cpp +++ b/src/mlpack/tests/main_tests/adaboost_test.cpp @@ -109,7 +109,7 @@ BOOST_AUTO_TEST_CASE(AdaBoostProbabilitiesTest) BOOST_REQUIRE_EQUAL(probabilities.n_cols, testSize); - for (size_t i = 0; i < testSize; i++) + for (size_t i = 0; i < testSize; ++i) BOOST_REQUIRE_CLOSE(arma::accu(probabilities.col(i)), 1, 1e-5); } diff --git a/src/mlpack/tests/main_tests/emst_test.cpp b/src/mlpack/tests/main_tests/emst_test.cpp index 6801a1a375..041fb90b69 100644 --- a/src/mlpack/tests/main_tests/emst_test.cpp +++ b/src/mlpack/tests/main_tests/emst_test.cpp @@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(EMSTFirstTwoOutputRowsIntegerTest) SetInputParam("input", std::move(x)); SetInputParam("leaf_size", (int) 2); - for (size_t i = 0; i < CLI::GetParam("output").n_cols; i++) + for (size_t i = 0; i < CLI::GetParam("output").n_cols; ++i) { BOOST_REQUIRE_CLOSE(CLI::GetParam("output")(0, i), boost::math::iround(CLI::GetParam("output")(0, i)), 1e-5); diff --git a/src/mlpack/tests/main_tests/fastmks_test.cpp b/src/mlpack/tests/main_tests/fastmks_test.cpp index 7519113e12..3c07752cdb 100644 --- a/src/mlpack/tests/main_tests/fastmks_test.cpp +++ b/src/mlpack/tests/main_tests/fastmks_test.cpp @@ -427,7 +427,7 @@ BOOST_AUTO_TEST_CASE(FastMKSKernelTest) arma::mat kernels; // Looping over all the kernels - for (size_t i = 0; i < nofkerneltypes; i++) + for (size_t i = 0; i < nofkerneltypes; ++i) { if (kerneltypes[i] == "hyptan") { diff --git a/src/mlpack/tests/main_tests/gmm_train_test.cpp b/src/mlpack/tests/main_tests/gmm_train_test.cpp index 3da10ef3ad..4d86d9e9b4 100644 --- a/src/mlpack/tests/main_tests/gmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/gmm_train_test.cpp @@ -554,11 +554,11 @@ BOOST_AUTO_TEST_CASE(GmmTrainDiagCovariance) arma::uvec sortedIndices = sort_index(gmm->Weights()); - for (size_t k = 0; k < sortedIndices.n_elem; k++) + for (size_t k = 0; k < sortedIndices.n_elem; ++k) { arma::mat diagCov(gmm->Component(sortedIndices[k]).Covariance()); - for (size_t i = 0; i < diagCov.n_rows; i++) - for (size_t j = 0; j < diagCov.n_cols; j++) + for (size_t i = 0; i < diagCov.n_rows; ++i) + for (size_t j = 0; j < diagCov.n_cols; ++j) if (i != j && diagCov(i, j) != (double) 0) BOOST_FAIL("Covariance is not diagonal"); } diff --git a/src/mlpack/tests/main_tests/hmm_train_test.cpp b/src/mlpack/tests/main_tests/hmm_train_test.cpp index 985ab99361..427dcec9ec 100644 --- a/src/mlpack/tests/main_tests/hmm_train_test.cpp +++ b/src/mlpack/tests/main_tests/hmm_train_test.cpp @@ -64,7 +64,7 @@ inline void CheckMatricesDiffer(arma::mat& a, arma::mat& b, double tolerance) bool valsEqual = true; if (dimsEqual) { - for (size_t i=0; i(neighborsFile); distances = ReadData(distanceFile); - for (size_t i = 1; i < leafSizes.size(); i++) + for (size_t i = 1; i < leafSizes.size(); ++i) { SetInputParam("leaf_size", leafSizes[i]); SetInputParam("reference", inputData); @@ -400,7 +400,7 @@ BOOST_AUTO_TEST_CASE(TreeTypeTesting) distances = ReadData(distanceFile); RSModel* outputModel1 = CLI::GetParam("output_model"); - for (size_t i = 1; i < trees.size(); i++) + for (size_t i = 1; i < trees.size(); ++i) { if (!data::Load("iris.csv", inputData)) BOOST_FAIL("Unable to load dataset iris.csv!"); diff --git a/src/mlpack/tests/main_tests/range_search_utils.hpp b/src/mlpack/tests/main_tests/range_search_utils.hpp index 4f1fa53eb3..8f1385eafb 100644 --- a/src/mlpack/tests/main_tests/range_search_utils.hpp +++ b/src/mlpack/tests/main_tests/range_search_utils.hpp @@ -43,12 +43,12 @@ inline void CheckMatrices(std::vector>& vec1, const double tolerance = 1e-3) { BOOST_REQUIRE_EQUAL(vec1.size() , vec2.size()); - for (size_t i = 0; i < vec1.size(); i++) + for (size_t i = 0; i < vec1.size(); ++i) { BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size()); std::sort(vec1[i].begin(), vec1[i].end()); std::sort(vec2[i].begin(), vec2[i].end()); - for (size_t j = 0 ; j < vec1[i].size(); j++) + for (size_t j = 0 ; j < vec1[i].size(); ++j) { BOOST_REQUIRE_CLOSE(vec1[i][j], vec2[i][j], tolerance); } @@ -65,12 +65,12 @@ inline void CheckMatrices(std::vector>& vec1, std::vector>& vec2) { BOOST_REQUIRE_EQUAL(vec1.size() , vec2.size()); - for (size_t i = 0; i < vec1.size(); i++) + for (size_t i = 0; i < vec1.size(); ++i) { BOOST_REQUIRE_EQUAL(vec1[i].size(), vec2[i].size()); std::sort(vec1[i].begin(), vec1[i].end()); std::sort(vec2[i].begin(), vec2[i].end()); - for (size_t j = 0; j < vec1[i].size(); j++) + for (size_t j = 0; j < vec1[i].size(); ++j) { BOOST_REQUIRE_EQUAL(vec1[i][j], vec2[i][j]); } diff --git a/src/mlpack/tests/mean_shift_test.cpp b/src/mlpack/tests/mean_shift_test.cpp index f03b9294a6..818602f632 100644 --- a/src/mlpack/tests/mean_shift_test.cpp +++ b/src/mlpack/tests/mean_shift_test.cpp @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) // clusters are ordered, so we have to be careful about that. size_t firstClass = assignments(0); - for (size_t i = 1; i < 13; i++) + for (size_t i = 1; i < 13; ++i) BOOST_REQUIRE_EQUAL(assignments(i), firstClass); size_t secondClass = assignments(13); @@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) // To ensure that class 1 != class 2. BOOST_REQUIRE_NE(firstClass, secondClass); - for (size_t i = 13; i < 20; i++) + for (size_t i = 13; i < 20; ++i) BOOST_REQUIRE_EQUAL(assignments(i), secondClass); size_t thirdClass = assignments(20); @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(MeanShiftSimpleTest) BOOST_REQUIRE_NE(firstClass, thirdClass); BOOST_REQUIRE_NE(secondClass, thirdClass); - for (size_t i = 20; i < 30; i++) + for (size_t i = 20; i < 30; ++i) BOOST_REQUIRE_EQUAL(assignments(i), thirdClass); } diff --git a/src/mlpack/tests/mlpack_test.cpp b/src/mlpack/tests/mlpack_test.cpp index 8d6e6d2d0a..7848a618a9 100644 --- a/src/mlpack/tests/mlpack_test.cpp +++ b/src/mlpack/tests/mlpack_test.cpp @@ -107,7 +107,7 @@ struct GlobalFixture #endif for (int i = 0; i < boost::unit_test::framework::master_test_suite().argc; - i++) + ++i) { std::string argument( boost::unit_test::framework::master_test_suite().argv[i]); diff --git a/src/mlpack/tests/nbc_test.cpp b/src/mlpack/tests/nbc_test.cpp index ce596c18b7..fd2867e35b 100644 --- a/src/mlpack/tests/nbc_test.cpp +++ b/src/mlpack/tests/nbc_test.cpp @@ -43,20 +43,20 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierTest) size_t dimension = nbcTest.Means().n_rows; calcMat.zeros(2 * dimension + 1, classes); - for (size_t i = 0; i < dimension; i++) + for (size_t i = 0; i < dimension; ++i) { - for (size_t j = 0; j < classes; j++) + for (size_t j = 0; j < classes; ++j) { calcMat(i, j) = nbcTest.Means()(i, j); calcMat(i + dimension, j) = nbcTest.Variances()(i, j); } } - for (size_t i = 0; i < classes; i++) + for (size_t i = 0; i < classes; ++i) calcMat(2 * dimension, i) = nbcTest.Probabilities()(i); - for (size_t i = 0; i < calcMat.n_rows; i++) - for (size_t j = 0; j < classes; j++) + for (size_t i = 0; i < calcMat.n_rows; ++i) + for (size_t j = 0; j < classes; ++j) BOOST_REQUIRE_CLOSE(trainRes(i, j) + .00001, calcMat(i, j), 0.01); arma::mat testData; @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierTest) nbcTest.Classify(testData, calcVec, calcProbs); - for (size_t i = 0; i < testData.n_cols; i++) + for (size_t i = 0; i < testData.n_cols; ++i) BOOST_REQUIRE_EQUAL(testRes(i), calcVec(i)); for (size_t i = 0; i < testResProbs.n_cols; ++i) @@ -111,20 +111,20 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierIncrementalTest) size_t dimension = nbcTest.Means().n_rows; calcMat.zeros(2 * dimension + 1, classes); - for (size_t i = 0; i < dimension; i++) + for (size_t i = 0; i < dimension; ++i) { - for (size_t j = 0; j < classes; j++) + for (size_t j = 0; j < classes; ++j) { calcMat(i, j) = nbcTest.Means()(i, j); calcMat(i + dimension, j) = nbcTest.Variances()(i, j); } } - for (size_t i = 0; i < classes; i++) + for (size_t i = 0; i < classes; ++i) calcMat(2 * dimension, i) = nbcTest.Probabilities()(i); - for (size_t i = 0; i < calcMat.n_cols; i++) - for (size_t j = 0; j < classes; j++) + for (size_t i = 0; i < calcMat.n_cols; ++i) + for (size_t j = 0; j < classes; ++j) BOOST_REQUIRE_CLOSE(trainRes(j, i) + .00001, calcMat(j, i), 0.01); arma::mat testData; @@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierIncrementalTest) nbcTest.Classify(testData, calcVec, calcProbs); - for (size_t i = 0; i < testData.n_cols; i++) + for (size_t i = 0; i < testData.n_cols; ++i) BOOST_REQUIRE_EQUAL(testRes(i), calcVec(i)); for (size_t i = 0; i < testResProba.n_cols; ++i) @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(NaiveBayesClassifierHighDimensionsTest) nbcTest.Classify(testData, calcVec, calcProbs); // Check the results. - for (size_t i = 0; i < calcVec.n_cols; i++) + for (size_t i = 0; i < calcVec.n_cols; ++i) BOOST_REQUIRE_EQUAL(calcVec(i), testLabels(i)); } diff --git a/src/mlpack/tests/pca_test.cpp b/src/mlpack/tests/pca_test.cpp index 6060e6838f..d270c15d20 100644 --- a/src/mlpack/tests/pca_test.cpp +++ b/src/mlpack/tests/pca_test.cpp @@ -47,7 +47,7 @@ void ArmaComparisonPCA( princomp(coeff, score, eigVal, trans(data)); // Verify the PCA results based on the eigenvalues. - for (size_t i = 0; i < eigVal.n_elem; i++) + for (size_t i = 0; i < eigVal.n_elem; ++i) { if (eigVal[i] == 0.0) BOOST_REQUIRE_SMALL(eigVal1[i], 1e-15); @@ -99,7 +99,7 @@ void PCADimensionalityReduction( // If the eigenvectors are pointed opposite directions, they will cancel // each other out in this summation. - for (size_t i = 0; i < data.n_rows; i++) + for (size_t i = 0; i < data.n_rows; ++i) { if (accu(abs(correct.row(i) + data.row(i))) < 0.001 /* arbitrary */) { diff --git a/src/mlpack/tests/perceptron_test.cpp b/src/mlpack/tests/perceptron_test.cpp index 2302b3e525..de7d9b0870 100644 --- a/src/mlpack/tests/perceptron_test.cpp +++ b/src/mlpack/tests/perceptron_test.cpp @@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(Random3) Row predictedLabels(testData.n_cols); p.Classify(testData, predictedLabels); - for (size_t i = 0; i < predictedLabels.n_cols; i++) + for (size_t i = 0; i < predictedLabels.n_cols; ++i) BOOST_CHECK_EQUAL(predictedLabels(0, i), 0); } diff --git a/src/mlpack/tests/radical_test.cpp b/src/mlpack/tests/radical_test.cpp index 3f02a499b8..cfb6844d8c 100644 --- a/src/mlpack/tests/radical_test.cpp +++ b/src/mlpack/tests/radical_test.cpp @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(Radical_Test_Radical3D) mat matYT = trans(matY); double valEst = 0; - for (uword i = 0; i < matYT.n_cols; i++) + for (uword i = 0; i < matYT.n_cols; ++i) { vec y = vec(matYT.col(i)); valEst += rad.Vasicek(y); @@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(Radical_Test_Radical3D) matYT = trans(matY); double valBest = 0; - for (uword i = 0; i < matYT.n_cols; i++) + for (uword i = 0; i < matYT.n_cols; ++i) { vec y = vec(matYT.col(i)); valBest += rad.Vasicek(y); diff --git a/src/mlpack/tests/range_search_test.cpp b/src/mlpack/tests/range_search_test.cpp index cfea35b987..33dd5c56ca 100644 --- a/src/mlpack/tests/range_search_test.cpp +++ b/src/mlpack/tests/range_search_test.cpp @@ -33,10 +33,10 @@ void SortResults(const vector>& neighbors, vector>>& output) { output.resize(neighbors.size()); - for (size_t i = 0; i < neighbors.size(); i++) + for (size_t i = 0; i < neighbors.size(); ++i) { output[i].resize(neighbors[i].size()); - for (size_t j = 0; j < neighbors[i].size(); j++) + for (size_t j = 0; j < neighbors[i].size(); ++j) output[i][j] = make_pair(distances[i][j], neighbors[i][j]); // Now that it's constructed, sort it. @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest) std::vector oldFromNew; std::vector newFromOld; TreeType* tree = new TreeType(data, oldFromNew, newFromOld, 1); - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; ++i) { RangeSearch<>* rs; @@ -485,11 +485,11 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive1) vector>> sortedNaive; SortResults(neighborsNaive, distancesNaive, sortedNaive); - for (size_t i = 0; i < sortedTree.size(); i++) + for (size_t i = 0; i < sortedTree.size(); ++i) { BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); - for (size_t j = 0; j < sortedTree[i].size(); j++) + for (size_t j = 0; j < sortedTree[i].size(); ++j) { BOOST_REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); BOOST_REQUIRE_CLOSE(sortedTree[i][j].first, sortedNaive[i][j].first, @@ -534,11 +534,11 @@ BOOST_AUTO_TEST_CASE(DualTreeVsNaive2) vector>> sortedNaive; SortResults(neighborsNaive, distancesNaive, sortedNaive); - for (size_t i = 0; i < sortedTree.size(); i++) + for (size_t i = 0; i < sortedTree.size(); ++i) { BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); - for (size_t j = 0; j < sortedTree[i].size(); j++) + for (size_t j = 0; j < sortedTree[i].size(); ++j) { BOOST_REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); BOOST_REQUIRE_CLOSE(sortedTree[i][j].first, sortedNaive[i][j].first, @@ -583,11 +583,11 @@ BOOST_AUTO_TEST_CASE(SingleTreeVsNaive) vector>> sortedNaive; SortResults(neighborsNaive, distancesNaive, sortedNaive); - for (size_t i = 0; i < sortedTree.size(); i++) + for (size_t i = 0; i < sortedTree.size(); ++i) { BOOST_REQUIRE(sortedTree[i].size() == sortedNaive[i].size()); - for (size_t j = 0; j < sortedTree[i].size(); j++) + for (size_t j = 0; j < sortedTree[i].size(); ++j) { BOOST_REQUIRE(sortedTree[i][j].second == sortedNaive[i][j].second); BOOST_REQUIRE_CLOSE(sortedTree[i][j].first, sortedNaive[i][j].first, diff --git a/src/mlpack/tests/rbm_network_test.cpp b/src/mlpack/tests/rbm_network_test.cpp index b3d365e0e0..0cf8ff2316 100644 --- a/src/mlpack/tests/rbm_network_test.cpp +++ b/src/mlpack/tests/rbm_network_test.cpp @@ -86,13 +86,13 @@ BOOST_AUTO_TEST_CASE(BinaryRBMClassificationTest) // Test that objective value returned by RBM::Train() is finite. BOOST_REQUIRE_EQUAL(std::isfinite(objVal), true); - for (size_t i = 0; i < trainData.n_cols; i++) + for (size_t i = 0; i < trainData.n_cols; ++i) { model.HiddenMean(std::move(trainData.col(i)), std::move(output)); XRbm.col(i) = output; } - for (size_t i = 0; i < testData.n_cols; i++) + for (size_t i = 0; i < testData.n_cols; ++i) { model.HiddenMean(std::move(testData.col(i)), std::move(output)); @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_CASE(ssRBMClassificationTest) for (size_t i = 0; i < testLabelsTemp.n_cols; ++i) testLabels(i) = arma::as_scalar(testLabelsTemp.col(i)); - for (size_t i = 0; i < trainData.n_cols; i++) + for (size_t i = 0; i < trainData.n_cols; ++i) { tempRadius = arma::norm(trainData.col(i)); if (radius < tempRadius) @@ -187,14 +187,14 @@ BOOST_AUTO_TEST_CASE(ssRBMClassificationTest) // Test that objective value returned by RBM::Train() is finite. BOOST_REQUIRE_EQUAL(std::isfinite(objVal), true); - for (size_t i = 0; i < trainData.n_cols; i++) + for (size_t i = 0; i < trainData.n_cols; ++i) { modelssRBM.HiddenMean(std::move(trainData.col(i)), std::move(output)); XRbm.col(i) = output; } - for (size_t i = 0; i < testData.n_cols; i++) + for (size_t i = 0; i < testData.n_cols; ++i) { modelssRBM.HiddenMean(std::move(testData.col(i)), std::move(output)); @@ -236,12 +236,12 @@ void BuildVanillaNetwork(MatType& trainData, arma::Mat freeEnergy = MatType( "-0.87523715, 0.50615066, 0.46923476, 1.21509084;"); arma::vec calculatedFreeEnergy(4, arma::fill::zeros); - for (size_t i = 0; i < trainData.n_cols; i++) + for (size_t i = 0; i < trainData.n_cols; ++i) { calculatedFreeEnergy(i) = model.FreeEnergy(std::move(trainData.col(i))); } - for (size_t i = 0; i < freeEnergy.n_elem; i++) + for (size_t i = 0; i < freeEnergy.n_elem; ++i) BOOST_REQUIRE_CLOSE(calculatedFreeEnergy(i), freeEnergy(i), 1e-3); } diff --git a/src/mlpack/tests/rectangle_tree_test.cpp b/src/mlpack/tests/rectangle_tree_test.cpp index 1db6e1a5b2..63117bd858 100644 --- a/src/mlpack/tests/rectangle_tree_test.cpp +++ b/src/mlpack/tests/rectangle_tree_test.cpp @@ -72,7 +72,7 @@ std::vector GetAllPointsInTree(const TreeType& tree) std::vector vec; if (tree.NumChildren() > 0) { - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { std::vector tmp = GetAllPointsInTree(tree.Child(i)); vec.insert(vec.begin(), tmp.begin(), tmp.end()); @@ -80,7 +80,7 @@ std::vector GetAllPointsInTree(const TreeType& tree) } else { - for (size_t i = 0; i < tree.Count(); i++) + for (size_t i = 0; i < tree.Count(); ++i) { arma::vec* c = new arma::vec(tree.Dataset().col(tree.Point(i))); vec.push_back(c); @@ -103,21 +103,21 @@ BOOST_AUTO_TEST_CASE(RectangleTreeConstructionRepeatTest) TreeType tree(dataset, 20, 6, 5, 2, 0); std::vector allPoints = GetAllPointsInTree(tree); - for (size_t i = 0; i < allPoints.size(); i++) + for (size_t i = 0; i < allPoints.size(); ++i) { - for (size_t j = i + 1; j < allPoints.size(); j++) + for (size_t j = i + 1; j < allPoints.size(); ++j) { arma::vec v1 = *(allPoints[i]); arma::vec v2 = *(allPoints[j]); bool same = true; - for (size_t k = 0; k < v1.n_rows; k++) + for (size_t k = 0; k < v1.n_rows; ++k) same &= (v1[k] == v2[k]); BOOST_REQUIRE_NE(same, true); } } - for (size_t i = 0; i < allPoints.size(); i++) + for (size_t i = 0; i < allPoints.size(); ++i) delete allPoints[i]; } @@ -133,15 +133,15 @@ void CheckContainment(const TreeType& tree) { if (tree.NumChildren() == 0) { - for (size_t i = 0; i < tree.Count(); i++) + for (size_t i = 0; i < tree.Count(); ++i) BOOST_REQUIRE(tree.Bound().Contains( tree.Dataset().unsafe_col(tree.Point(i)))); } else { - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { - for (size_t j = 0; j < tree.Bound().Dim(); j++) + for (size_t j = 0; j < tree.Bound().Dim(); ++j) { // All children should be covered by the parent node. // Some children can be empty (only in case of the R++ tree) @@ -167,11 +167,11 @@ void CheckExactContainment(const TreeType& tree) { if (tree.NumChildren() == 0) { - for (size_t i = 0; i < tree.Bound().Dim(); i++) + for (size_t i = 0; i < tree.Bound().Dim(); ++i) { double min = DBL_MAX; double max = -1.0 * DBL_MAX; - for (size_t j = 0; j < tree.Count(); j++) + for (size_t j = 0; j < tree.Count(); ++j) { if (tree.Dataset().col(tree.Point(j))[i] < min) min = tree.Dataset().col(tree.Point(j))[i]; @@ -184,11 +184,11 @@ void CheckExactContainment(const TreeType& tree) } else { - for (size_t i = 0; i < tree.Bound().Dim(); i++) + for (size_t i = 0; i < tree.Bound().Dim(); ++i) { double min = DBL_MAX; double max = -1.0 * DBL_MAX; - for (size_t j = 0; j < tree.NumChildren(); j++) + for (size_t j = 0; j < tree.NumChildren(); ++j) { if (tree.Child(j).Bound()[i].Lo() < min) min = tree.Child(j).Bound()[i].Lo(); @@ -200,7 +200,7 @@ void CheckExactContainment(const TreeType& tree) BOOST_REQUIRE_EQUAL(min, tree.Bound()[i].Lo()); } - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) CheckExactContainment(tree.Child(i)); } } @@ -211,7 +211,7 @@ void CheckExactContainment(const TreeType& tree) template void CheckHierarchy(const TreeType& tree) { - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { BOOST_REQUIRE_EQUAL(&tree, tree.Child(i).Parent()); CheckHierarchy(tree.Child(i)); @@ -254,7 +254,7 @@ void CheckFills(const TreeType& tree) } else { - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { BOOST_REQUIRE(tree.NumChildren() >= tree.MinNumChildren() || tree.Parent() == NULL); @@ -292,7 +292,7 @@ int GetMaxLevel(const TreeType& tree) if (!tree.IsLeaf()) { int m = 0; - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { int n = GetMaxLevel(tree.Child(i)); if (n > m) @@ -319,7 +319,7 @@ int GetMinLevel(const TreeType& tree) if (!tree.IsLeaf()) { int m = INT_MAX; - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { int n = GetMinLevel(tree.Child(i)); if (n < m) @@ -345,7 +345,7 @@ size_t CheckNumDescendants(const TreeType& tree) size_t numDescendants = 0; - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) numDescendants += CheckNumDescendants(tree.Child(i)); BOOST_REQUIRE_EQUAL(tree.NumDescendants(), numDescendants); @@ -387,28 +387,28 @@ BOOST_AUTO_TEST_CASE(PointDeletion) arma::mat> TreeType; TreeType tree(dataset, 20, 6, 5, 2, 0); - for (int i = 0; i < numIter; i++) + for (int i = 0; i < numIter; ++i) tree.DeletePoint(999 - i); // Do a few sanity checks. Ensure each point is unique, the tree has the // correct number of points, the tree has legal containment, and the tree's // data is in sync. std::vector allPoints = GetAllPointsInTree(tree); - for (size_t i = 0; i < allPoints.size(); i++) + for (size_t i = 0; i < allPoints.size(); ++i) { - for (size_t j = i + 1; j < allPoints.size(); j++) + for (size_t j = i + 1; j < allPoints.size(); ++j) { arma::vec v1 = *(allPoints[i]); arma::vec v2 = *(allPoints[j]); bool same = true; - for (size_t k = 0; k < v1.n_rows; k++) + for (size_t k = 0; k < v1.n_rows; ++k) same &= (v1[k] == v2[k]); BOOST_REQUIRE(!same); } } - for (size_t i = 0; i < allPoints.size(); i++) + for (size_t i = 0; i < allPoints.size(); ++i) delete allPoints[i]; BOOST_REQUIRE_EQUAL(tree.NumDescendants(), 1000 - numIter); @@ -437,7 +437,7 @@ BOOST_AUTO_TEST_CASE(PointDeletion) knn2.Search(querySet, 5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); @@ -467,7 +467,7 @@ BOOST_AUTO_TEST_CASE(PointDynamicAdd) dataset.reshape(8, 1000 + numIter); arma::mat tmpData; tmpData.randu(8, numIter); - for (int i = 0; i < numIter; i++) + for (int i = 0; i < numIter; ++i) { tree.Dataset().col(1000 + i) = tmpData.col(i); dataset.col(1000 + i) = tmpData.col(i); @@ -478,21 +478,21 @@ BOOST_AUTO_TEST_CASE(PointDynamicAdd) // correct number of points, the tree has legal containment, and the tree's // data is in sync. std::vector allPoints = GetAllPointsInTree(tree); - for (size_t i = 0; i < allPoints.size(); i++) + for (size_t i = 0; i < allPoints.size(); ++i) { - for (size_t j = i + 1; j < allPoints.size(); j++) + for (size_t j = i + 1; j < allPoints.size(); ++j) { arma::vec v1 = *(allPoints[i]); arma::vec v2 = *(allPoints[j]); bool same = true; - for (size_t k = 0; k < v1.n_rows; k++) + for (size_t k = 0; k < v1.n_rows; ++k) same &= (v1[k] == v2[k]); BOOST_REQUIRE(!same); } } - for (size_t i = 0; i < allPoints.size(); i++) + for (size_t i = 0; i < allPoints.size(); ++i) delete allPoints[i]; BOOST_REQUIRE_EQUAL(tree.NumDescendants(), 1000 + numIter); @@ -518,7 +518,7 @@ BOOST_AUTO_TEST_CASE(PointDynamicAdd) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); @@ -558,7 +558,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); @@ -601,7 +601,7 @@ BOOST_AUTO_TEST_CASE(XTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); @@ -642,7 +642,7 @@ BOOST_AUTO_TEST_CASE(HilbertRTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); @@ -654,7 +654,7 @@ void CheckHilbertOrdering(const TreeType& tree) { if (tree.IsLeaf()) { - for (size_t i = 0; i < tree.NumPoints() - 1; i++) + for (size_t i = 0; i < tree.NumPoints() - 1; ++i) BOOST_REQUIRE_LE(tree.AuxiliaryInfo().HilbertValue().ComparePoints( tree.Dataset().col(tree.Point(i)), tree.Dataset().col(tree.Point(i + 1))), @@ -666,7 +666,7 @@ void CheckHilbertOrdering(const TreeType& tree) } else { - for (size_t i = 0; i < tree.NumChildren() - 1; i++) + for (size_t i = 0; i < tree.NumChildren() - 1; ++i) BOOST_REQUIRE_LE(tree.AuxiliaryInfo().HilbertValue().CompareValues( tree.Child(i).AuxiliaryInfo().HilbertValue(), tree.Child(i + 1).AuxiliaryInfo().HilbertValue()), @@ -676,7 +676,7 @@ void CheckHilbertOrdering(const TreeType& tree) tree.Child(tree.NumChildren() - 1).AuxiliaryInfo().HilbertValue()), 0); - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) CheckHilbertOrdering(tree.Child(i)); } } @@ -704,7 +704,7 @@ void CheckDiscreteHilbertValueSync(const TreeType& tree) { const HilbertValue& value = tree.AuxiliaryInfo().HilbertValue(); - for (size_t i = 0; i < tree.NumPoints(); i++) + for (size_t i = 0; i < tree.NumPoints(); ++i) { arma::Col pointValue = HilbertValue::CalculateValue(tree.Dataset().col(tree.Point(i))); @@ -717,7 +717,7 @@ void CheckDiscreteHilbertValueSync(const TreeType& tree) } else { - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) CheckDiscreteHilbertValueSync(tree.Child(i)); } } @@ -885,7 +885,7 @@ void CheckHilbertValue(const TreeType& tree) return; } - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { const HilbertValue& childValue = tree.Child(i).AuxiliaryInfo().HilbertValue(); @@ -904,7 +904,7 @@ void CheckHilbertValue(const TreeType& tree) BOOST_REQUIRE_EQUAL(value.OwnsLocalHilbertValues(), false); - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) CheckHilbertValue(tree.Child(i)); } @@ -954,11 +954,11 @@ void CheckOverlap(const TreeType& tree) bool success = true; // Check if two nodes overlap each other. - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { success = true; - for (size_t j = 0; j < tree.NumChildren(); j++) + for (size_t j = 0; j < tree.NumChildren(); ++j) { if (j == i) continue; @@ -973,7 +973,7 @@ void CheckOverlap(const TreeType& tree) } BOOST_REQUIRE_EQUAL(success, true); - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) CheckOverlap(tree.Child(i)); } @@ -1034,7 +1034,7 @@ BOOST_AUTO_TEST_CASE(RPlusTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); @@ -1050,7 +1050,7 @@ void CheckRPlusPlusTreeBound(const TreeType& tree) bool success = true; // Ensure that the maximum bounding rectangle contains all children. - for (size_t k = 0; k < tree.Bound().Dim(); k++) + for (size_t k = 0; k < tree.Bound().Dim(); ++k) { BOOST_REQUIRE_LE(tree.Bound()[k].Hi(), tree.AuxiliaryInfo().OuterBound()[k].Hi()); @@ -1061,7 +1061,7 @@ void CheckRPlusPlusTreeBound(const TreeType& tree) if (tree.IsLeaf()) { // Ensure that the maximum bounding rectangle contains all points. - for (size_t i = 0; i < tree.Count(); i++) + for (size_t i = 0; i < tree.Count(); ++i) BOOST_REQUIRE_EQUAL(true, tree.Bound().Contains(tree.Dataset().col(tree.Point(i)))); @@ -1070,12 +1070,12 @@ void CheckRPlusPlusTreeBound(const TreeType& tree) // Ensure that two children's maximum bounding rectangles do not overlap // each other. - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) { const Bound& bound1 = tree.Child(i).AuxiliaryInfo().OuterBound(); success = true; - for (size_t j = 0; j < tree.NumChildren(); j++) + for (size_t j = 0; j < tree.NumChildren(); ++j) { if (j == i) continue; @@ -1091,7 +1091,7 @@ void CheckRPlusPlusTreeBound(const TreeType& tree) } BOOST_REQUIRE_EQUAL(success, true); - for (size_t i = 0; i < tree.NumChildren(); i++) + for (size_t i = 0; i < tree.NumChildren(); ++i) CheckRPlusPlusTreeBound(tree.Child(i)); } @@ -1165,7 +1165,7 @@ BOOST_AUTO_TEST_CASE(RPlusPlusTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); diff --git a/src/mlpack/tests/recurrent_network_test.cpp b/src/mlpack/tests/recurrent_network_test.cpp index 00195514f9..1bef406e26 100644 --- a/src/mlpack/tests/recurrent_network_test.cpp +++ b/src/mlpack/tests/recurrent_network_test.cpp @@ -480,14 +480,14 @@ arma::Mat GenerateReberGrammarData( arma::colvec translation; // Generate the training data. - for (size_t i = 0; i < trainReberGrammarCount; i++) + for (size_t i = 0; i < trainReberGrammarCount; ++i) { if (recursive) GenerateRecursiveReber(transitions, 3, 5, trainReber); else GenerateReber(transitions, trainReber); - for (size_t j = 0; j < trainReber.length() - 1; j++) + for (size_t j = 0; j < trainReber.length() - 1; ++j) { ReberTranslation(trainReber[j], translation); trainInput(0, i) = arma::join_cols(trainInput(0, i), translation); @@ -498,7 +498,7 @@ arma::Mat GenerateReberGrammarData( } // Generate the test data. - for (size_t i = 0; i < testReberGrammarCount; i++) + for (size_t i = 0; i < testReberGrammarCount; ++i) { if (recursive) GenerateRecursiveReber(transitions, averageRecursion, maxRecursion, @@ -506,7 +506,7 @@ arma::Mat GenerateReberGrammarData( else GenerateReber(transitions, testReber); - for (size_t j = 0; j < testReber.length() - 1; j++) + for (size_t j = 0; j < testReber.length() - 1; ++j) { ReberTranslation(testReber[j], translation); testInput(0, i) = arma::join_cols(testInput(0, i), translation); @@ -576,7 +576,7 @@ void ReberGrammarTestNetwork(ModelType& model, arma::cube inputTemp, labelsTemp; for (size_t iteration = 0; iteration < (iterations + offset); iteration++) { - for (size_t j = 0; j < trainReberGrammarCount; j++) + for (size_t j = 0; j < trainReberGrammarCount; ++j) { // Each sequence may be a different length, so we need to extract them // manually. We will reshape them into a cube with each slice equal to @@ -595,7 +595,7 @@ void ReberGrammarTestNetwork(ModelType& model, double error = 0; // Ask the network to predict the next Reber grammar in the given sequence. - for (size_t i = 0; i < testReberGrammarCount; i++) + for (size_t i = 0; i < testReberGrammarCount; ++i) { arma::cube prediction; arma::cube input(testInput.at(0, i).memptr(), inputSize, 1, @@ -609,7 +609,7 @@ void ReberGrammarTestNetwork(ModelType& model, size_t reberError = 0; - for (size_t j = 0; j < (prediction.n_elem / reberGrammerSize); j++) + for (size_t j = 0; j < (prediction.n_elem / reberGrammerSize); ++j) { char predictedSymbol, inputSymbol; std::string reberChoices; @@ -736,14 +736,14 @@ void GenerateDistractedSequence(arma::mat& input, arma::mat& output) // Set the target in the input sequence and the corresponding targets in the // output sequence by following the correct order. - for (size_t i = 0; i < 2; i++) + for (size_t i = 0; i < 2; ++i) { size_t idx = rand() % 2; input(idx, index(i)) = 1; output(idx, index(i) > index(i == 0) ? 9 : 8) = 1; } - for (size_t i = 2; i < 8; i++) + for (size_t i = 2; i < 8; ++i) input(2 + rand() % 6, index(i)) = 1; // Set the prompts which direct the network to give an answer. @@ -771,11 +771,11 @@ void DistractedSequenceRecallTestNetwork( arma::field testLabels(1, testDistractedSequenceCount); // Generate the training data. - for (size_t i = 0; i < trainDistractedSequenceCount; i++) + for (size_t i = 0; i < trainDistractedSequenceCount; ++i) GenerateDistractedSequence(trainInput(0, i), trainLabels(0, i)); // Generate the test data. - for (size_t i = 0; i < testDistractedSequenceCount; i++) + for (size_t i = 0; i < testDistractedSequenceCount; ++i) GenerateDistractedSequence(testInput(0, i), testLabels(0, i)); /* @@ -820,7 +820,7 @@ void DistractedSequenceRecallTestNetwork( arma::cube inputTemp, labelsTemp; for (size_t iteration = 0; iteration < (9 + offset); iteration++) { - for (size_t j = 0; j < trainDistractedSequenceCount; j++) + for (size_t j = 0; j < trainDistractedSequenceCount; ++j) { inputTemp = arma::cube(trainInput.at(0, j).memptr(), inputSize, 1, trainInput.at(0, j).n_elem / inputSize, false, true); @@ -835,7 +835,7 @@ void DistractedSequenceRecallTestNetwork( // Ask the network to predict the targets in the given sequence at the // prompts. - for (size_t i = 0; i < testDistractedSequenceCount; i++) + for (size_t i = 0; i < testDistractedSequenceCount; ++i) { arma::cube output; arma::cube input(testInput.at(0, i).memptr(), inputSize, 1, @@ -1103,7 +1103,7 @@ void ReberGrammarTestCustomNetwork(const size_t hiddenSize = 4, arma::cube inputTemp, labelsTemp; for (size_t iteration = 0; iteration < (iterations + offset); iteration++) { - for (size_t j = 0; j < trainReberGrammarCount; j++) + for (size_t j = 0; j < trainReberGrammarCount; ++j) { // Each sequence may be a different length, so we need to extract them // manually. We will reshape them into a cube with each slice equal to @@ -1122,7 +1122,7 @@ void ReberGrammarTestCustomNetwork(const size_t hiddenSize = 4, double error = 0; // Ask the network to predict the next Reber grammar in the given sequence. - for (size_t i = 0; i < testReberGrammarCount; i++) + for (size_t i = 0; i < testReberGrammarCount; ++i) { arma::cube prediction; arma::cube input(testInput.at(0, i).memptr(), inputSize, 1, @@ -1136,7 +1136,7 @@ void ReberGrammarTestCustomNetwork(const size_t hiddenSize = 4, size_t reberError = 0; - for (size_t j = 0; j < (prediction.n_elem / reberGrammerSize); j++) + for (size_t j = 0; j < (prediction.n_elem / reberGrammerSize); ++j) { char predictedSymbol, inputSymbol; std::string reberChoices; @@ -1233,7 +1233,7 @@ void GenerateNoisySinRNN(arma::cube& data, x.for_each([&i, gain, freq, phase, noisePercent, interval] (arma::colvec::elem_type& val) { - double t = interval * (i++); + double t = interval * (++i); val = gain * ::sin(2 * M_PI * freq * t + phase) + (noisePercent * gain / 100 * Random(0.0, 0.1)); }); diff --git a/src/mlpack/tests/regularized_svd_test.cpp b/src/mlpack/tests/regularized_svd_test.cpp index 92f429a3f6..32b438b69b 100644 --- a/src/mlpack/tests/regularized_svd_test.cpp +++ b/src/mlpack/tests/regularized_svd_test.cpp @@ -46,13 +46,13 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionRandomEvaluate) // Make a RegularizedSVDFunction with zero regularization. RegularizedSVDFunction rSVDFunc(data, rank, 0); - for (size_t i = 0; i < numTrials; i++) + for (size_t i = 0; i < numTrials; ++i) { arma::mat parameters = arma::randu(rank, numUsers + numItems); // Calculate cost by summing up cost of each example. double cost = 0; - for (size_t j = 0; j < numRatings; j++) + for (size_t j = 0; j < numRatings; ++j) { const size_t user = data(0, j); const size_t item = data(1, j) + numUsers; @@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionRegularizationEvaluate) RegularizedSVDFunction rSVDFuncSmallReg(data, rank, 0.5); RegularizedSVDFunction rSVDFuncBigReg(data, rank, 20); - for (size_t i = 0; i < numTrials; i++) + for (size_t i = 0; i < numTrials; ++i) { arma::mat parameters = arma::randu(rank, numUsers + numItems); @@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionRegularizationEvaluate) // each rating and sum them up. double smallRegTerm = 0; double bigRegTerm = 0; - for (size_t j = 0; j < numRatings; j++) + for (size_t j = 0; j < numRatings; ++j) { const size_t user = data(0, j); const size_t item = data(1, j) + numUsers; @@ -162,9 +162,9 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionGradient) double costPlus1, costMinus1, numGradient1; double costPlus2, costMinus2, numGradient2; - for (size_t i = 0; i < rank; i++) + for (size_t i = 0; i < rank; ++i) { - for (size_t j = 0; j < numUsers + numItems; j++) + for (size_t j = 0; j < numUsers + numItems; ++j) { // Perturb parameter with a positive constant and get costs. parameters(i, j) += epsilon; @@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionOptimize) data(1, numRatings - 1) = numItems - 1; // Make rating entries based on the parameters. - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { data(2, i) = arma::dot(parameters.col(data(0, i)), parameters.col(numUsers + data(1, i))); @@ -237,7 +237,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionOptimize) // Get predicted ratings from optimized parameters. arma::mat predictedData(1, numRatings); - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { predictedData(0, i) = arma::dot(optParameters.col(data(0, i)), optParameters.col(numUsers + data(1, i))); @@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionOptimizeHOGWILD) data(1, numRatings - 1) = numItems - 1; // Make rating entries based on the parameters. - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { data(2, i) = arma::dot(parameters.col(data(0, i)), parameters.col(numUsers + data(1, i))); @@ -302,7 +302,7 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionOptimizeHOGWILD) // Get predicted ratings from optimized parameters. arma::mat predictedData(1, numRatings); - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { predictedData(0, i) = arma::dot(optParameters.col(data(0, i)), optParameters.col(numUsers + data(1, i))); diff --git a/src/mlpack/tests/scaling_test.cpp b/src/mlpack/tests/scaling_test.cpp index e865062f8b..07a343ce74 100644 --- a/src/mlpack/tests/scaling_test.cpp +++ b/src/mlpack/tests/scaling_test.cpp @@ -149,7 +149,7 @@ BOOST_AUTO_TEST_CASE(PCAWhiteningTest) arma::vec diagonals = (mlpack::math::ColumnCovariance(output)).diag(); // Checking covarience is close to 1.0 double ccovsum = 0.0; - for (size_t i = 0; i < diagonals.n_elem; i++) + for (size_t i = 0; i < diagonals.n_elem; ++i) ccovsum += diagonals(i); BOOST_REQUIRE_CLOSE(ccovsum, 1.0, 1e-3); scale.InverseTransform(output, temp); @@ -168,7 +168,7 @@ BOOST_AUTO_TEST_CASE(ZCAWhiteningTest) arma::vec diagonals = (mlpack::math::ColumnCovariance(output)).diag(); // Check that the covariance is close to 1.0. double ccovsum = 0.0; - for (size_t i = 0; i < diagonals.n_elem; i++) + for (size_t i = 0; i < diagonals.n_elem; ++i) ccovsum += diagonals(i); BOOST_REQUIRE_CLOSE(ccovsum, 1.0, 1e-3); scale.InverseTransform(output, temp); diff --git a/src/mlpack/tests/serialization_test.cpp b/src/mlpack/tests/serialization_test.cpp index 3f12dcc897..e30fcc4dc9 100644 --- a/src/mlpack/tests/serialization_test.cpp +++ b/src/mlpack/tests/serialization_test.cpp @@ -1559,7 +1559,7 @@ BOOST_AUTO_TEST_CASE(ssRBMTest) data.randu(3, 100); double slabPenalty = 1; double tempRadius, radius = arma::norm(data.col(0)); - for (size_t i = 1; i < data.n_cols; i++) + for (size_t i = 1; i < data.n_cols; ++i) { tempRadius = arma::norm(data.col(i)); if (radius < tempRadius) diff --git a/src/mlpack/tests/softmax_regression_test.cpp b/src/mlpack/tests/softmax_regression_test.cpp index 0cdbbab382..e44f7e3f91 100644 --- a/src/mlpack/tests/softmax_regression_test.cpp +++ b/src/mlpack/tests/softmax_regression_test.cpp @@ -34,14 +34,14 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // Create a SoftmaxRegressionFunction. Regularization term ignored. SoftmaxRegressionFunction srf(data, labels, numClasses, 0); // Run a number of trials. - for (size_t i = 0; i < trials; i++) + for (size_t i = 0; i < trials; ++i) { // Create a random set of parameters. arma::mat parameters; @@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionEvaluate) double logLikelihood = 0; // Compute error for each training example. - for (size_t j = 0; j < points; j++) + for (size_t j = 0; j < points; ++j) { arma::mat hypothesis, probabilities; @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionRegularizationEvaluate) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // 3 objects for comparing regularization costs. @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionRegularizationEvaluate) SoftmaxRegressionFunction srfBigReg(data, labels, numClasses, 20); // Run a number of trials. - for (size_t i = 0; i < trials; i++) + for (size_t i = 0; i < trials; ++i) { // Create a random set of parameters. arma::mat parameters; @@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionGradient) // Create random class labels. arma::Row labels(points); - for (size_t i = 0; i < points; i++) + for (size_t i = 0; i < points; ++i) labels(i) = math::RandInt(0, numClasses); // 2 objects for 2 terms in the cost function. Each term contributes towards @@ -143,9 +143,9 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionGradient) double costPlus2, costMinus2, numGradient2; // For each parameter. - for (size_t i = 0; i < numClasses; i++) + for (size_t i = 0; i < numClasses; ++i) { - for (size_t j = 0; j < inputSize; j++) + for (size_t j = 0; j < inputSize; ++j) { // Perturb parameter with a positive constant and get costs. parameters(i, j) += epsilon; @@ -185,12 +185,12 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionTwoClasses) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -204,12 +204,12 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionTwoClasses) BOOST_REQUIRE_CLOSE(acc, 100.0, 0.5); // Create test dataset. - for (size_t i = 0; i < points / 2; i++) + for (size_t i = 0; i < points / 2; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 2; i < points; i++) + for (size_t i = points / 2; i < points; ++i) { data.col(i) = g2.Random(); labels(i) = 1; @@ -282,27 +282,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionMultipleClasses) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -316,27 +316,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionMultipleClasses) BOOST_REQUIRE_CLOSE(acc, 100.0, 2.0); // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -428,27 +428,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionClassifySinglePointTest) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -458,27 +458,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionClassifySinglePointTest) SoftmaxRegression sr(data, labels, numClasses, lambda); // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -510,27 +510,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionComputeProbabilitiesTest) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -540,27 +540,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionComputeProbabilitiesTest) SoftmaxRegression sr(data, labels, numClasses, lambda); // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -596,27 +596,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionComputeProbabilitiesAndLabelsTest) arma::mat data(inputSize, points); arma::Row labels(points); - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; @@ -626,27 +626,27 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionComputeProbabilitiesAndLabelsTest) SoftmaxRegression sr(data, labels, numClasses, lambda); // Create test dataset. - for (size_t i = 0; i < points / 5; i++) + for (size_t i = 0; i < points / 5; ++i) { data.col(i) = g1.Random(); labels(i) = 0; } - for (size_t i = points / 5; i < (2 * points) / 5; i++) + for (size_t i = points / 5; i < (2 * points) / 5; ++i) { data.col(i) = g2.Random(); labels(i) = 1; } - for (size_t i = (2 * points) / 5; i < (3 * points) / 5; i++) + for (size_t i = (2 * points) / 5; i < (3 * points) / 5; ++i) { data.col(i) = g3.Random(); labels(i) = 2; } - for (size_t i = (3 * points) / 5; i < (4 * points) / 5; i++) + for (size_t i = (3 * points) / 5; i < (4 * points) / 5; ++i) { data.col(i) = g4.Random(); labels(i) = 3; } - for (size_t i = (4 * points) / 5; i < points; i++) + for (size_t i = (4 * points) / 5; i < points; ++i) { data.col(i) = g5.Random(); labels(i) = 4; diff --git a/src/mlpack/tests/sparse_autoencoder_test.cpp b/src/mlpack/tests/sparse_autoencoder_test.cpp index a87bdc2c61..03e95f8534 100644 --- a/src/mlpack/tests/sparse_autoencoder_test.cpp +++ b/src/mlpack/tests/sparse_autoencoder_test.cpp @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionRandomEvaluate) SparseAutoencoderFunction saf(data, vSize, hSize, 0, 0); // Run a number of trials. - for (size_t i = 0; i < trials; i++) + for (size_t i = 0; i < trials; ++i) { // Create a random set of parameters. arma::mat parameters; @@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionRandomEvaluate) double reconstructionError = 0; // Compute error for each training example. - for (size_t j = 0; j < points; j++) + for (size_t j = 0; j < points; ++j) { arma::mat hiddenLayer, outputLayer, diff; @@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionRegularizationEvaluate) SparseAutoencoderFunction safBigReg(data, vSize, hSize, 20, 0); // Run a number of trials. - for (size_t i = 0; i < trials; i++) + for (size_t i = 0; i < trials; ++i) { // Create a random set of parameters. arma::mat parameters; @@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionKLDivergenceEvaluate) SparseAutoencoderFunction safBigDiv(data, vSize, hSize, 0, 20, rho); // Run a number of trials. - for (size_t i = 0; i < trials; i++) + for (size_t i = 0; i < trials; ++i) { // Create a random set of parameters. arma::mat parameters; @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionKLDivergenceEvaluate) rhoCap.zeros(hSize, 1); // Compute hidden layer activations for each example. - for (size_t j = 0; j < points; j++) + for (size_t j = 0; j < points; ++j) { arma::mat hiddenLayer; @@ -236,9 +236,9 @@ BOOST_AUTO_TEST_CASE(SparseAutoencoderFunctionGradient) double costPlus3, costMinus3, numGradient3; // For each parameter. - for (size_t i = 0; i <= l3; i++) + for (size_t i = 0; i <= l3; ++i) { - for (size_t j = 0; j <= l2; j++) + for (size_t j = 0; j <= l2; ++j) { // Perturb parameter with a positive constant and get costs. parameters(i, j) += epsilon; diff --git a/src/mlpack/tests/sparse_coding_test.cpp b/src/mlpack/tests/sparse_coding_test.cpp index 05cfb7136e..513db86c85 100644 --- a/src/mlpack/tests/sparse_coding_test.cpp +++ b/src/mlpack/tests/sparse_coding_test.cpp @@ -30,7 +30,7 @@ void SCVerifyCorrectness(vec beta, vec errCorr, double lambda) { const double tol = 1e-12; size_t nDims = beta.n_elem; - for (size_t j = 0; j < nDims; j++) + for (size_t j = 0; j < nDims; ++j) { if (beta(j) == 0) { diff --git a/src/mlpack/tests/spill_tree_test.cpp b/src/mlpack/tests/spill_tree_test.cpp index c7504b2236..83677b5078 100644 --- a/src/mlpack/tests/spill_tree_test.cpp +++ b/src/mlpack/tests/spill_tree_test.cpp @@ -143,7 +143,7 @@ void SpillTreeHyperplaneTestAux() // Let's check that points in the left child are projected to values // in the range: (-inf, tau] size_t numDesc = node->Left()->NumDescendants(); - for (size_t i = 0; i < numDesc; i++) + for (size_t i = 0; i < numDesc; ++i) { size_t descIndex = node->Left()->Descendant(i); BOOST_REQUIRE_LE( @@ -156,7 +156,7 @@ void SpillTreeHyperplaneTestAux() // Let's check that points in the right child are projected to values // in the range: (-tau, inf) size_t numDesc = node->Right()->NumDescendants(); - for (size_t i = 0; i < numDesc; i++) + for (size_t i = 0; i < numDesc; ++i) { size_t descIndex = node->Right()->Descendant(i); BOOST_REQUIRE_GT( @@ -173,7 +173,7 @@ void SpillTreeHyperplaneTestAux() // Let's check that points in the left child are considered to the // left by the splitting hyperplane. size_t numDesc = node->Left()->NumDescendants(); - for (size_t i = 0; i < numDesc; i++) + for (size_t i = 0; i < numDesc; ++i) { size_t descIndex = node->Left()->Descendant(i); BOOST_REQUIRE( @@ -185,7 +185,7 @@ void SpillTreeHyperplaneTestAux() // Let's check that points in the right child are considered to the // right by the splitting hyperplane. size_t numDesc = node->Right()->NumDescendants(); - for (size_t i = 0; i < numDesc; i++) + for (size_t i = 0; i < numDesc; ++i) { size_t descIndex = node->Right()->Descendant(i); BOOST_REQUIRE( diff --git a/src/mlpack/tests/string_encoding_test.cpp b/src/mlpack/tests/string_encoding_test.cpp index 9aeaa9d633..b50eea8e6d 100644 --- a/src/mlpack/tests/string_encoding_test.cpp +++ b/src/mlpack/tests/string_encoding_test.cpp @@ -66,11 +66,11 @@ void CheckVectors(const vector>& a, { BOOST_REQUIRE_EQUAL(a.size(), b.size()); - for (size_t i = 0; i < a.size(); i++) + for (size_t i = 0; i < a.size(); ++i) { BOOST_REQUIRE_EQUAL(a[i].size(), b[i].size()); - for (size_t j = 0; j < a[i].size(); j++) + for (size_t j = 0; j < a[i].size(); ++j) BOOST_REQUIRE_CLOSE(a[i][j], b[i][j], tolerance); } } @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(SplitByAnyOfTokenizerTest) BOOST_REQUIRE_EQUAL(tokens.size(), expected.size()); - for (size_t i = 0; i < tokens.size(); i++) + for (size_t i = 0; i < tokens.size(); ++i) BOOST_REQUIRE_EQUAL(tokens[i], expected[i]); } @@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(SplitByAnyOfTokenizerUnicodeTest) BOOST_REQUIRE_EQUAL(tokens.size(), expectedUtf8Tokens.size()); - for (size_t i = 0; i < tokens.size(); i++) + for (size_t i = 0; i < tokens.size(); ++i) BOOST_REQUIRE_EQUAL(tokens[i], expectedUtf8Tokens[i]); } @@ -417,7 +417,7 @@ void CheckDictionaries( BOOST_REQUIRE_EQUAL(mapping.size(), expectedMapping.size()); BOOST_REQUIRE_EQUAL(mapping.size(), tokens.size()); - for (size_t i = 0; i < tokens.size(); i++) + for (size_t i = 0; i < tokens.size(); ++i) { BOOST_REQUIRE_EQUAL(tokens[i], expectedTokens[i]); BOOST_REQUIRE_EQUAL(expectedMapping.at(tokens[i]), mapping.at(tokens[i])); @@ -440,7 +440,7 @@ void CheckDictionaries(const StringEncodingDictionary& expected, BOOST_REQUIRE_EQUAL(expected.Size(), obtained.Size()); - for (size_t i = 0; i < mapping.size(); i++) + for (size_t i = 0; i < mapping.size(); ++i) { BOOST_REQUIRE_EQUAL(mapping[i], expectedMapping[i]); } diff --git a/src/mlpack/tests/svdplusplus_test.cpp b/src/mlpack/tests/svdplusplus_test.cpp index 6a38104fd2..a7918a259c 100644 --- a/src/mlpack/tests/svdplusplus_test.cpp +++ b/src/mlpack/tests/svdplusplus_test.cpp @@ -49,13 +49,13 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusEvaluate) // Make a SVDPlusPlusFunction with zero regularization. SVDPlusPlusFunction svdPPFunc(data, implicitData, rank, 0); - for (size_t i = 0; i < numTrials; i++) + for (size_t i = 0; i < numTrials; ++i) { arma::mat parameters = arma::randu(rank + 1, numUsers + 2 * numItems); // Calculate cost by summing up cost of each example. double cost = 0; - for (size_t j = 0; j < data.n_cols; j++) + for (size_t j = 0; j < data.n_cols; ++j) { const size_t user = data(0, j); const size_t item = data(1, j) + numUsers; @@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionRegularizationEvaluate) 0.5); SVDPlusPlusFunction svdPPFuncBigReg(data, implicitData, rank, 20); - for (size_t i = 0; i < numTrials; i++) + for (size_t i = 0; i < numTrials; ++i) { arma::mat parameters = arma::randu(rank + 1, numUsers + 2 * numItems); @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionRegularizationEvaluate) // each rating and sum them up. double smallRegTerm = 0; double bigRegTerm = 0; - for (size_t j = 0; j < data.n_cols; j++) + for (size_t j = 0; j < data.n_cols; ++j) { const size_t user = data(0, j); const size_t item = data(1, j) + numUsers; @@ -219,9 +219,9 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionGradient) double costPlus1, costMinus1, numGradient1; double costPlus2, costMinus2, numGradient2; - for (size_t i = 0; i < rank; i++) + for (size_t i = 0; i < rank; ++i) { - for (size_t j = 0; j < numUsers + numItems; j++) + for (size_t j = 0; j < numUsers + numItems; ++j) { // Perturb parameter with a positive constant and get costs. parameters(i, j) += epsilon; @@ -311,7 +311,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusCleanDataTest) } else { - i++; + ++i; } } @@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusCleanDataTest) BOOST_REQUIRE_EQUAL(cleanedData.n_nonzero, implicitData.n_cols); // Make sure all implicitData are in cleanedData. - for (size_t i = 0; i < implicitData.n_cols; i++) + for (size_t i = 0; i < implicitData.n_cols; ++i) { double value = cleanedData(implicitData(1, i), implicitData(0, i)); BOOST_REQUIRE_GT(std::fabs(value), 0); @@ -361,7 +361,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionOptimize) arma::sp_mat implicitData = arma::sprandu(numItems, numUsers, 0.05); // Make rating entries based on the parameters. - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; @@ -399,7 +399,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionOptimize) // Get predicted ratings from optimized parameters. arma::mat predictedData(1, numRatings); - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; @@ -468,7 +468,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionParallelOptimize) arma::sp_mat implicitData = arma::sprandu(numItems, numUsers, 0.05); // Make rating entries based on the parameters. - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; @@ -513,7 +513,7 @@ BOOST_AUTO_TEST_CASE(SVDPlusPlusFunctionParallelOptimize) // Get predicted ratings from optimized parameters. arma::mat predictedData(1, numRatings); - for (size_t i = 0; i < numRatings; i++) + for (size_t i = 0; i < numRatings; ++i) { const size_t user = data(0, i); const size_t item = data(1, i) + numUsers; diff --git a/src/mlpack/tests/tree_test.cpp b/src/mlpack/tests/tree_test.cpp index e646c791e0..9efb8c8769 100644 --- a/src/mlpack/tests/tree_test.cpp +++ b/src/mlpack/tests/tree_test.cpp @@ -408,7 +408,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundMaxDistanceBound) */ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistanceBound) { - for (int i = 0; i < 50; i++) + for (int i = 0; i < 50; ++i) { size_t dim = math::RandInt(20); @@ -429,7 +429,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistanceBound) lo_b.randu(); width_b.randu(); - for (size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; ++j) { a[j] = Range(loA[j], loA[j] + widthA[j]); b[j] = Range(lo_b[j], lo_b[j] + width_b[j]); @@ -459,7 +459,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistanceBound) */ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistancePoint) { - for (int i = 0; i < 20; i++) + for (int i = 0; i < 20; ++i) { size_t dim = math::RandInt(20); @@ -473,11 +473,11 @@ BOOST_AUTO_TEST_CASE(HRectBoundRangeDistancePoint) loA.randu(); widthA.randu(); - for (size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; ++j) a[j] = Range(loA[j], loA[j] + widthA[j]); // Now run the test on a few points. - for (int j = 0; j < 10; j++) + for (int j = 0; j < 10; ++j) { arma::vec point(dim); @@ -931,7 +931,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootMaxDistanceBound) */ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistanceBound) { - for (int i = 0; i < 50; i++) + for (int i = 0; i < 50; ++i) { size_t dim = math::RandInt(20); @@ -952,7 +952,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistanceBound) lo_b.randu(); width_b.randu(); - for (size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; ++j) { a[j] = Range(loA[j], loA[j] + widthA[j]); b[j] = Range(lo_b[j], lo_b[j] + width_b[j]); @@ -982,7 +982,7 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistanceBound) */ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistancePoint) { - for (int i = 0; i < 20; i++) + for (int i = 0; i < 20; ++i) { size_t dim = math::RandInt(20); @@ -996,11 +996,11 @@ BOOST_AUTO_TEST_CASE(HRectBoundRootRangeDistancePoint) loA.randu(); widthA.randu(); - for (size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; ++j) a[j] = Range(loA[j], loA[j] + widthA[j]); // Now run the test on a few points. - for (int j = 0; j < 10; j++) + for (int j = 0; j < 10; ++j) { arma::vec point(dim); @@ -1322,9 +1322,9 @@ BOOST_AUTO_TEST_CASE(KdTreeTest) BOOST_REQUIRE_EQUAL(root.Count(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); @@ -1343,8 +1343,8 @@ BOOST_AUTO_TEST_CASE(KdTreeTest) // Compare each peer against every other peer. while (depth < v.size()) { - for (size_t i = depth; i < 2 * depth && i < v.size(); i++) - for (size_t j = i + 1; j < 2 * depth && j < v.size(); j++) + for (size_t i = depth; i < 2 * depth && i < v.size(); ++i) + for (size_t j = i + 1; j < 2 * depth && j < v.size(); ++j) if (v[i] != NULL && v[j] != NULL) BOOST_REQUIRE(!v[i]->Bound().Contains(v[j]->Bound())); @@ -1391,9 +1391,9 @@ BOOST_AUTO_TEST_CASE(MaxRPTreeTest) BOOST_REQUIRE_EQUAL(root.Count(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); @@ -1424,17 +1424,17 @@ bool CheckHyperplaneSplit(const TreeType& tree) // The hyperplane splits the node if the expression takes on opposite // values on node's children. - for (size_t i = 0; i < tree.Left()->NumDescendants(); i++) + for (size_t i = 0; i < tree.Left()->NumDescendants(); ++i) { - for (size_t k = 0; k < dataset.n_rows; k++) + for (size_t k = 0; k < dataset.n_rows; ++k) mat(k, i) = - dataset(k, tree.Left()->Descendant(i)); mat(dataset.n_rows, i) = -1; } - for (size_t i = 0; i < tree.Right()->NumDescendants(); i++) + for (size_t i = 0; i < tree.Right()->NumDescendants(); ++i) { - for (size_t k = 0; k < dataset.n_rows; k++) + for (size_t k = 0; k < dataset.n_rows; ++k) mat(k, i + tree.Left()->NumDescendants()) = dataset(k, tree.Right()->Descendant(i)); @@ -1456,7 +1456,7 @@ bool CheckHyperplaneSplit(const TreeType& tree) for (size_t it = 0; it < numIters; it++) { success = true; - for (size_t k = 0; k < tree.Count(); k++) + for (size_t k = 0; k < tree.Count(); ++k) { ElemType result = arma::dot(mat.col(k), x); if (result > 0) @@ -1533,9 +1533,9 @@ BOOST_AUTO_TEST_CASE(RPTreeTest) BOOST_REQUIRE_EQUAL(root.Count(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); @@ -1557,7 +1557,7 @@ void CheckRPTreeSplit(const TreeType& tree) arma::Col center; tree.Left()->Bound().Center(center); ElemType maxDist = 0; - for (size_t k =0; k < tree.Left()->NumDescendants(); k++) + for (size_t k =0; k < tree.Left()->NumDescendants(); ++k) { ElemType dist = MetricType::Evaluate(center, tree.Dataset().col(tree.Left()->Descendant(k))); @@ -1566,7 +1566,7 @@ void CheckRPTreeSplit(const TreeType& tree) maxDist = dist; } - for (size_t k =0; k < tree.Right()->NumDescendants(); k++) + for (size_t k =0; k < tree.Right()->NumDescendants(); ++k) { ElemType dist = MetricType::Evaluate(center, tree.Dataset().col(tree.Right()->Descendant(k))); @@ -1648,9 +1648,9 @@ BOOST_AUTO_TEST_CASE(BallTreeTest) BOOST_REQUIRE_EQUAL(root.NumDescendants(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); @@ -1753,9 +1753,9 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSparseKDTreeTest) BOOST_REQUIRE_EQUAL(root.Count(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); @@ -1774,8 +1774,8 @@ BOOST_AUTO_TEST_CASE(ExhaustiveSparseKDTreeTest) // Compare each peer against every other peer. while (depth < v.size()) { - for (size_t i = depth; i < 2 * depth && i < v.size(); i++) - for (size_t j = i + 1; j < 2 * depth && j < v.size(); j++) + for (size_t i = depth; i < 2 * depth && i < v.size(); ++i) + for (size_t j = i + 1; j < 2 * depth && j < v.size(); ++j) if (v[i] != NULL && v[j] != NULL) BOOST_REQUIRE(!v[i]->Bound().Contains(v[j]->Bound())); diff --git a/src/mlpack/tests/ub_tree_test.cpp b/src/mlpack/tests/ub_tree_test.cpp index 8bdd609229..b1fb57b0bf 100644 --- a/src/mlpack/tests/ub_tree_test.cpp +++ b/src/mlpack/tests/ub_tree_test.cpp @@ -39,12 +39,12 @@ BOOST_AUTO_TEST_CASE(AddressTest) arma::Col point(dataset.n_rows); // Ensure that this is one-to-one transform. - for (size_t i = 0; i < dataset.n_cols; i++) + for (size_t i = 0; i < dataset.n_cols; ++i) { addr::PointToAddress(address, dataset.col(i)); addr::AddressToPoint(point, address); - for (size_t k = 0; k < dataset.n_rows; k++) + for (size_t k = 0; k < dataset.n_rows; ++k) BOOST_REQUIRE_CLOSE(dataset(k, i), point[k], 1e-13); } } @@ -69,7 +69,7 @@ void CheckSplit(const TreeType& tree) arma::Col address(tree.Bound().Dim()); // Find the highest address of the left node. - for (size_t i = 0; i < tree.Left()->NumDescendants(); i++) + for (size_t i = 0; i < tree.Left()->NumDescendants(); ++i) { addr::PointToAddress(address, tree.Dataset().col(tree.Left()->Descendant(i))); @@ -79,7 +79,7 @@ void CheckSplit(const TreeType& tree) } // Find the lowest address of the right node. - for (size_t i = 0; i < tree.Right()->NumDescendants(); i++) + for (size_t i = 0; i < tree.Right()->NumDescendants(); ++i) { addr::PointToAddress(address, tree.Dataset().col(tree.Right()->Descendant(i))); @@ -110,7 +110,7 @@ template void CheckBound(const TreeType& tree) { typedef typename TreeType::ElemType ElemType; - for (size_t i = 0; i < tree.NumDescendants(); i++) + for (size_t i = 0; i < tree.NumDescendants(); ++i) { arma::Col point = tree.Dataset().col(tree.Descendant(i)); @@ -122,10 +122,10 @@ void CheckBound(const TreeType& tree) // Ensure that there is a hyperrectangle that contains the point. bool success = false; - for (size_t j = 0; j < tree.Bound().NumBounds(); j++) + for (size_t j = 0; j < tree.Bound().NumBounds(); ++j) { success = true; - for (size_t k = 0; k < loBound.n_rows; k++) + for (size_t k = 0; k < loBound.n_rows; ++k) { if (point[k] < loBound(k, j) - 1e-14 * std::fabs(loBound(k, j)) || point[k] > hiBound(k, j) + 1e-14 * std::fabs(hiBound(k, j))) @@ -173,12 +173,12 @@ void CheckDistance(TreeType& tree, TreeType* node = NULL) CheckDistance(tree, node); - for (size_t j = 0; j < tree.Dataset().n_cols; j++) + for (size_t j = 0; j < tree.Dataset().n_cols; ++j) { const arma::Col& point = tree. Dataset().col(j); ElemType maxDist = 0; ElemType minDist = std::numeric_limits::max(); - for (size_t i = 0; i < tree.NumDescendants(); i++) + for (size_t i = 0; i < tree.NumDescendants(); ++i) { ElemType dist = MetricType::Evaluate( tree.Dataset().col(tree.Descendant(i)), @@ -215,8 +215,8 @@ void CheckDistance(TreeType& tree, TreeType* node = NULL) { ElemType maxDist = 0; ElemType minDist = std::numeric_limits::max(); - for (size_t i = 0; i < tree.NumDescendants(); i++) - for (size_t j = 0; j < node->NumDescendants(); j++) + for (size_t i = 0; i < tree.NumDescendants(); ++i) + for (size_t j = 0; j < node->NumDescendants(); ++j) { ElemType dist = MetricType::Evaluate( tree.Dataset().col(tree.Descendant(i)), @@ -292,9 +292,9 @@ BOOST_AUTO_TEST_CASE(UBTreeTest) BOOST_REQUIRE_EQUAL(root.NumDescendants(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); @@ -323,7 +323,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); @@ -350,7 +350,7 @@ BOOST_AUTO_TEST_CASE(DualTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); diff --git a/src/mlpack/tests/union_find_test.cpp b/src/mlpack/tests/union_find_test.cpp index ebbfaad5be..47cd9c3d18 100644 --- a/src/mlpack/tests/union_find_test.cpp +++ b/src/mlpack/tests/union_find_test.cpp @@ -25,7 +25,7 @@ BOOST_AUTO_TEST_CASE(TestFind) static const size_t testSize = 10; UnionFind testUnionFind(testSize); - for (size_t i = 0; i < testSize; i++) + for (size_t i = 0; i < testSize; ++i) BOOST_REQUIRE(testUnionFind.Find(i) == i); testUnionFind.Union(0, 1); diff --git a/src/mlpack/tests/vantage_point_tree_test.cpp b/src/mlpack/tests/vantage_point_tree_test.cpp index 50685238d1..b31d679692 100644 --- a/src/mlpack/tests/vantage_point_tree_test.cpp +++ b/src/mlpack/tests/vantage_point_tree_test.cpp @@ -139,7 +139,7 @@ void CheckBound(TreeType& tree) if (tree.IsLeaf()) { // Ensure that the bound contains all descendant points. - for (size_t i = 0; i < tree.NumPoints(); i++) + for (size_t i = 0; i < tree.NumPoints(); ++i) { ElemType dist = tree.Bound().Metric().Evaluate(tree.Bound().Center(), tree.Dataset().col(tree.Point(i))); @@ -157,7 +157,7 @@ void CheckBound(TreeType& tree) else { // Ensure that the bound contains all descendant points. - for (size_t i = 0; i < tree.NumDescendants(); i++) + for (size_t i = 0; i < tree.NumDescendants(); ++i) { ElemType dist = tree.Bound().Metric().Evaluate(tree.Bound().Center(), tree.Dataset().col(tree.Descendant(i))); @@ -220,9 +220,9 @@ BOOST_AUTO_TEST_CASE(VPTreeTest) BOOST_REQUIRE_EQUAL(root.NumDescendants(), size); // Check the forward and backward mappings for correctness. - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < dimensions; j++) + for (size_t j = 0; j < dimensions; ++j) { BOOST_REQUIRE_EQUAL(treeset(j, i), dataset(j, newToOld[i])); BOOST_REQUIRE_EQUAL(treeset(j, oldToNew[i]), dataset(j, i)); @@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(DualTreeTraverserTest) knn2.Search(5, neighbors2, distances2); - for (size_t i = 0; i < neighbors1.size(); i++) + for (size_t i = 0; i < neighbors1.size(); ++i) { BOOST_REQUIRE_EQUAL(neighbors1[i], neighbors2[i]); BOOST_REQUIRE_EQUAL(distances1[i], distances2[i]); diff --git a/src/mlpack/tests/wgan_test.cpp b/src/mlpack/tests/wgan_test.cpp index c570b299a6..a590746ed0 100644 --- a/src/mlpack/tests/wgan_test.cpp +++ b/src/mlpack/tests/wgan_test.cpp @@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(WGANMNISTTest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } ); @@ -301,7 +301,7 @@ BOOST_AUTO_TEST_CASE(WGANGPMNISTTest) size_t dim = std::sqrt(trainData.n_rows); arma::mat generatedData(2 * dim, dim * numSamples); - for (size_t i = 0; i < numSamples; i++) + for (size_t i = 0; i < numSamples; ++i) { arma::mat samples; noise.imbue( [&]() { return noiseFunction(); } );