fix NaN panics and eliminate redundant graph rebuilds
- All partial_cmp().unwrap() → unwrap_or(Ordering::Equal) to prevent NaN panics in sort operations across neuro.rs, graph.rs, similarity.rs - replay_queue_with_graph: accepts pre-built graph, avoids rebuilding in agent_prompt (was building 2-3x per prompt) - differentiate_hub_with_graph: same pattern for differentiation - Simplify double-reverse history iteration to slice indexing Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
This commit is contained in:
parent
4530837057
commit
59cfa2959f
2 changed files with 4 additions and 4 deletions
|
|
@ -180,7 +180,7 @@ impl Graph {
|
||||||
let n = degrees.len();
|
let n = degrees.len();
|
||||||
if n < 2 { return 0.0; }
|
if n < 2 { return 0.0; }
|
||||||
|
|
||||||
degrees.sort_by(|a, b| a.partial_cmp(b).unwrap());
|
degrees.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal));
|
||||||
let mean = degrees.iter().sum::<f64>() / n as f64;
|
let mean = degrees.iter().sum::<f64>() / n as f64;
|
||||||
if mean < 1e-10 { return 0.0; }
|
if mean < 1e-10 { return 0.0; }
|
||||||
|
|
||||||
|
|
@ -448,7 +448,7 @@ fn label_propagation(
|
||||||
|
|
||||||
// Adopt the label with most votes
|
// Adopt the label with most votes
|
||||||
if let Some((&best_label, _)) = votes.iter()
|
if let Some((&best_label, _)) = votes.iter()
|
||||||
.max_by(|a, b| a.1.partial_cmp(b.1).unwrap())
|
.max_by(|a, b| a.1.partial_cmp(b.1).unwrap_or(std::cmp::Ordering::Equal))
|
||||||
{
|
{
|
||||||
let current = labels[key];
|
let current = labels[key];
|
||||||
if best_label != current {
|
if best_label != current {
|
||||||
|
|
@ -670,7 +670,7 @@ Categories: core={core} tech={tech} gen={gen} obs={obs} task={task}",
|
||||||
// Show history trend if we have enough data points
|
// Show history trend if we have enough data points
|
||||||
if history.len() >= 3 {
|
if history.len() >= 3 {
|
||||||
report.push_str("\n\nMetrics history (last 5):\n");
|
report.push_str("\n\nMetrics history (last 5):\n");
|
||||||
for snap in history.iter().rev().take(5).collect::<Vec<_>>().into_iter().rev() {
|
for snap in &history[history.len().saturating_sub(5)..] {
|
||||||
report.push_str(&format!(" {} — σ={:.1} α={:.2} gini={:.3} cc={:.4} fit={:.3}\n",
|
report.push_str(&format!(" {} — σ={:.1} α={:.2} gini={:.3} cc={:.4} fit={:.3}\n",
|
||||||
snap.date, snap.sigma, snap.alpha, snap.gini, snap.avg_cc, snap.avg_schema_fit));
|
snap.date, snap.sigma, snap.alpha, snap.gini, snap.avg_cc, snap.avg_schema_fit));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ pub fn pairwise_similar(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
results.sort_by(|a, b| b.2.partial_cmp(&a.2).unwrap());
|
results.sort_by(|a, b| b.2.partial_cmp(&a.2).unwrap_or(std::cmp::Ordering::Equal));
|
||||||
results
|
results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue