From 624fd3443306a8b15a6654a162f932d158c013ed Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 16 Apr 2023 16:05:50 +0200 Subject: [PATCH] Fix warnings found by clang. --- mlpp/exp_reg/exp_reg.cpp | 10 +++++----- mlpp/exp_reg/exp_reg_old.cpp | 8 ++++---- mlpp/lin_alg/mlpp_matrix.h | 2 ++ mlpp/lin_alg/mlpp_tensor3.h | 3 +++ mlpp/log_reg/log_reg.h | 2 +- mlpp/log_reg/log_reg_old.h | 2 +- mlpp/numerical_analysis/numerical_analysis.cpp | 2 +- mlpp/numerical_analysis/numerical_analysis_old.cpp | 2 +- 8 files changed, 18 insertions(+), 13 deletions(-) diff --git a/mlpp/exp_reg/exp_reg.cpp b/mlpp/exp_reg/exp_reg.cpp index 76bbe7c..191819a 100644 --- a/mlpp/exp_reg/exp_reg.cpp +++ b/mlpp/exp_reg/exp_reg.cpp @@ -197,10 +197,10 @@ void MLPPExpReg::mbgd(real_t learning_rate, int max_epoch, int mini_batch_size, _weights = regularization.reg_weightsv(_weights, _lambda, _alpha, _reg); // Calculating the bias gradient - real_t sum = 0; - for (int j = 0; j < current_output_batch->size(); j++) { - sum += (y_hat->get_element(j) - current_output_batch->get_element(j)); - } + //real_t sum = 0; + //for (int j = 0; j < current_output_batch->size(); j++) { + // sum += (y_hat->get_element(j) - current_output_batch->get_element(j)); + //} //real_t b_gradient = sum / output_mini_batches[i].size(); y_hat = evaluatem(current_input_batch); @@ -288,7 +288,7 @@ Ref MLPPExpReg::evaluatem(const Ref &X) { y_hat->resize(X->size().y); for (int i = 0; i < X->size().y; i++) { - real_t y; + real_t y = 0; for (int j = 0; j < X->size().x; j++) { y += _initial->get_element(j) * Math::pow(_weights->get_element(j), X->get_element(i, j)); diff --git a/mlpp/exp_reg/exp_reg_old.cpp b/mlpp/exp_reg/exp_reg_old.cpp index 7288199..8e5668d 100644 --- a/mlpp/exp_reg/exp_reg_old.cpp +++ b/mlpp/exp_reg/exp_reg_old.cpp @@ -182,10 +182,10 @@ void MLPPExpRegOld::MBGD(real_t learning_rate, int max_epoch, int mini_batch_siz weights = regularization.regWeights(weights, lambda, alpha, reg); // Calculating the bias gradient - real_t sum = 0; - for (uint32_t j = 0; j < outputMiniBatches[i].size(); j++) { - sum += (y_hat[j] - outputMiniBatches[i][j]); - } + //real_t sum = 0; + //for (uint32_t j = 0; j < outputMiniBatches[i].size(); j++) { + // sum += (y_hat[j] - outputMiniBatches[i][j]); + //} //real_t b_gradient = sum / outputMiniBatches[i].size(); y_hat = Evaluate(inputMiniBatches[i]); diff --git a/mlpp/lin_alg/mlpp_matrix.h b/mlpp/lin_alg/mlpp_matrix.h index 6b026c4..8197b04 100644 --- a/mlpp/lin_alg/mlpp_matrix.h +++ b/mlpp/lin_alg/mlpp_matrix.h @@ -292,6 +292,8 @@ public: for (int i = 0; i < _size.x; ++i) { row_ptr[i] = _data[ind_start + i]; } + + return ret; } _FORCE_INLINE_ PoolRealArray get_row_pool_vector(int p_index_y) { diff --git a/mlpp/lin_alg/mlpp_tensor3.h b/mlpp/lin_alg/mlpp_tensor3.h index caa8df3..0b92c4d 100644 --- a/mlpp/lin_alg/mlpp_tensor3.h +++ b/mlpp/lin_alg/mlpp_tensor3.h @@ -293,6 +293,8 @@ public: for (int i = 0; i < _size.x; ++i) { row_ptr[i] = _data[ind_start + i]; } + + return ret; } _FORCE_INLINE_ PoolRealArray get_row_pool_vector(int p_index_y) { @@ -644,6 +646,7 @@ public: } } + // TODO: These are temporary std::vector to_flat_std_vector() const; void set_from_std_vectors(const std::vector> &p_from); diff --git a/mlpp/log_reg/log_reg.h b/mlpp/log_reg/log_reg.h index 849ef78..c8da89a 100644 --- a/mlpp/log_reg/log_reg.h +++ b/mlpp/log_reg/log_reg.h @@ -76,7 +76,7 @@ protected: int _n; int _k; - real_t _learning_rate; + //real_t _learning_rate; // Regularization Params MLPPReg::RegularizationType _reg; diff --git a/mlpp/log_reg/log_reg_old.h b/mlpp/log_reg/log_reg_old.h index 60760a1..7aa57d4 100644 --- a/mlpp/log_reg/log_reg_old.h +++ b/mlpp/log_reg/log_reg_old.h @@ -40,7 +40,7 @@ private: int n; int k; - real_t learning_rate; + //real_t learning_rate; // Regularization Params std::string reg; diff --git a/mlpp/numerical_analysis/numerical_analysis.cpp b/mlpp/numerical_analysis/numerical_analysis.cpp index 211c093..f012d9a 100644 --- a/mlpp/numerical_analysis/numerical_analysis.cpp +++ b/mlpp/numerical_analysis/numerical_analysis.cpp @@ -77,7 +77,7 @@ real_t MLPPNumericalAnalysis::numDiff_3(real_t (*function)(std::vector), // For third order derivative tensors. // NOTE: Approximations do not appear to be accurate for sinusodial functions... // Should revisit this later. - real_t eps = INT_MAX; + real_t eps = 1e-5; std::vector x_ppp = x; x_ppp[axis1] += eps; diff --git a/mlpp/numerical_analysis/numerical_analysis_old.cpp b/mlpp/numerical_analysis/numerical_analysis_old.cpp index f68d16d..9966c04 100644 --- a/mlpp/numerical_analysis/numerical_analysis_old.cpp +++ b/mlpp/numerical_analysis/numerical_analysis_old.cpp @@ -77,7 +77,7 @@ real_t MLPPNumericalAnalysisOld::numDiff_3(real_t (*function)(std::vector x_ppp = x; x_ppp[axis1] += eps;