From 1f72bc157fea2897af1893d497b84fe5cc23565e Mon Sep 17 00:00:00 2001 From: Ed Addario Date: Sun, 17 Aug 2025 08:35:17 +0100 Subject: [PATCH] Avoid using if statements with initialiser --- tools/imatrix/imatrix.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/imatrix/imatrix.cpp b/tools/imatrix/imatrix.cpp index a76962efcc..52a15ebd82 100644 --- a/tools/imatrix/imatrix.cpp +++ b/tools/imatrix/imatrix.cpp @@ -206,9 +206,8 @@ static bool compute_vector_statistics(std::vector & tstats, c if (e.activations.empty()) { if (sum > 0) { for (const auto act : activations) { - if (const float p = act / sum; p > 0) { - entropy -= p * std::log2(p); - } + const float p = act / sum; + if (p > 0) { entropy -= p * std::log2(p); } } } } else { @@ -231,21 +230,22 @@ static bool compute_vector_statistics(std::vector & tstats, c int zd_score = 0; if (std_deviation > 0.0f) { for (const auto act : activations) { - if (const float z = (act - mean) / std_deviation; std::fabs(z) > 1.0f) zd_score++; + const float z = (act - mean) / std_deviation; + if (std::fabs(z) > 1.0f) { zd_score++; } } } auto & ts = tstats.emplace_back(); - ts.tensor = name; - ts.stats = e; - ts.sum_values = sum; - ts.mean_values = mean; - ts.max_values = max; - ts.min_values = min; - ts.elements = static_cast(activations.size()); - ts.std_deviation = std_deviation; - ts.entropy = entropy; - ts.zd_score = static_cast(zd_score) / ts.elements; + ts.tensor = name; + ts.stats = e; + ts.sum_values = sum; + ts.mean_values = mean; + ts.max_values = max; + ts.min_values = min; + ts.elements = static_cast(activations.size()); + ts.std_deviation = std_deviation; + ts.entropy = entropy; + ts.zd_score = static_cast(zd_score) / ts.elements; return e.activations.empty(); }