Skip to content

Commit 0b7f9c4

Browse files
committed
Change statistics' sort order
1 parent 200d88c commit 0b7f9c4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

examples/imatrix/imatrix.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,16 +695,25 @@ int main(int argc, char ** argv) {
695695
return 1;
696696
}
697697

698-
std::sort(ts.begin(), ts.end(), [](const tensor_statistics &a, const tensor_statistics &b) { return a.total > b.total; });
698+
struct tensor_comparer {
699+
bool operator()(const tensor_statistics & a, const tensor_statistics & b) const {
700+
std::string layer, name_a, name_b;;
701+
process_tensor_name(a.tensor, layer, name_a);
702+
process_tensor_name(b.tensor, layer, name_b);
703+
return name_a < name_b || (name_a == name_b && a.total > b.total);
704+
}
705+
};
706+
std::sort(ts.begin(), ts.end(), tensor_comparer());
707+
699708
LOG_INF("\nComputing statistics for %s (%d tensors)\n", params.in_files[0].c_str(), static_cast<int>(ts.size()));
700709
LOG_INF("\n%5s\t%-20s\t%10s\t%7s\t%12s\t%9s\t%10s\t%9s\t%6s\t%12s\t%7s\t%10s\n",
701710
"Layer", "Tensor", "Σ(Bias)", "Min", "Max", "μ", "σ", "% Active", "N", "Entropy", "E (norm)", "ZD Score");
702711
LOG_INF("==========================================================================================================================================================================\n");
703712
for (const auto & [tensor, total, mean, max, min, stddev, cv, zd, active, entropy, elements] : ts) {
704713
std::string layer, name;
705714
process_tensor_name(tensor, layer, name);
706-
LOG_INF("%5s\t%-20s\t%10.2f\t%7.4f\t%12.4f\t%8.4f\t%9.4f\t%8.2f%%\t%6d\t%12.4f\t%7.2f%%\t%10.4f\n",
707-
layer.c_str(), name.c_str(), total, min, max, mean, stddev, active * 100.0f, elements, entropy, 100.0f * (entropy / std::log2(elements)), 1000.0f * zd);
715+
LOG_INF("%5s\t%-20s\t%10.2f\t%7.4f\t%12.4f\t%8.4f\t%9.4f\t%8.2f%%\t%6d\t%12.4f\t%7.2f%%\t%9.2f%%\n",
716+
layer.c_str(), name.c_str(), total, min, max, mean, stddev, active * 100.0f, elements, entropy, 100.0f * (entropy / std::log2(elements)), 100.0f * zd);
708717
}
709718
LOG_INF("\n");
710719

0 commit comments

Comments
 (0)