Skip to content

Commit 1f72bc1

Browse files
committed
Avoid using if statements with initialiser
1 parent f6934b9 commit 1f72bc1

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

tools/imatrix/imatrix.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,8 @@ static bool compute_vector_statistics(std::vector<tensor_statistics> & tstats, c
206206
if (e.activations.empty()) {
207207
if (sum > 0) {
208208
for (const auto act : activations) {
209-
if (const float p = act / sum; p > 0) {
210-
entropy -= p * std::log2(p);
211-
}
209+
const float p = act / sum;
210+
if (p > 0) { entropy -= p * std::log2(p); }
212211
}
213212
}
214213
} else {
@@ -231,21 +230,22 @@ static bool compute_vector_statistics(std::vector<tensor_statistics> & tstats, c
231230
int zd_score = 0;
232231
if (std_deviation > 0.0f) {
233232
for (const auto act : activations) {
234-
if (const float z = (act - mean) / std_deviation; std::fabs(z) > 1.0f) zd_score++;
233+
const float z = (act - mean) / std_deviation;
234+
if (std::fabs(z) > 1.0f) { zd_score++; }
235235
}
236236
}
237237

238238
auto & ts = tstats.emplace_back();
239-
ts.tensor = name;
240-
ts.stats = e;
241-
ts.sum_values = sum;
242-
ts.mean_values = mean;
243-
ts.max_values = max;
244-
ts.min_values = min;
245-
ts.elements = static_cast<int>(activations.size());
246-
ts.std_deviation = std_deviation;
247-
ts.entropy = entropy;
248-
ts.zd_score = static_cast<float>(zd_score) / ts.elements;
239+
ts.tensor = name;
240+
ts.stats = e;
241+
ts.sum_values = sum;
242+
ts.mean_values = mean;
243+
ts.max_values = max;
244+
ts.min_values = min;
245+
ts.elements = static_cast<int>(activations.size());
246+
ts.std_deviation = std_deviation;
247+
ts.entropy = entropy;
248+
ts.zd_score = static_cast<float>(zd_score) / ts.elements;
249249

250250
return e.activations.empty();
251251
}

0 commit comments

Comments
 (0)