image.domain\self_evolve\auto_repair.mbt
86.8% · 66 / 76 points · 169 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 自动修复 self_evolve/auto_repair - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 退化自动修复 — 检测退化后自动修正参数 - 7
// Auto repair: detect degradation and auto-fix parameters - 8
// - 9
// Phase 5 v282: 将退化检测从"发现"推向"修复" — Resize(0,0)→Resize(1,1) 等。 - 10
- 11
///| - 12
/// 单项修复动作。 - 13
/// 描述 Single repair action. - 14
#derive(Eq, @debug.Debug) - 15
pub(all) struct RepairAction { - 16
op_tag : String - 17
repaired_op_tag : String - 18
repair_desc : String - 19
} - 20
- 21
///| - 22
pub extend RepairAction with @debug.Debug::{to_repr} - 23
- 24
///| - 25
pub extend RepairAction with Eq::{not_equal, equal} - 26
- 27
///| - 28
/// 修复报告。 - 29
/// 描述 Repair report. - 30
#derive(Eq, @debug.Debug) - 31
pub(all) struct RepairReport { - 32
original_op_count : Int32 - 33
repaired_op_count : Int32 - 34
repairs : Array[RepairAction] - 35
remaining_degradations : Array[DegradationCase] - 36
summary : String - 37
} - 38
- 39
///| - 40
pub extend RepairReport with @debug.Debug::{to_repr} - 41
- 42
///| - 43
pub extend RepairReport with Eq::{not_equal, equal} - 44
- 45
///| - 46
/// 修复单个算子的退化参数。 - 47
/// 描述 Repair a single op's degraded parameters. - 48
pub fn repair_op(op : @imgir.IROp) -> @imgir.IROp { - 49●
match op { - 50●
Resize(w, h) => { - 51●
let nw = if w == 0 { 1 } else { w } - 52●
let nh = if h == 0 { 1 } else { h } - 53
@imgir.Resize(nw, nh) - 54
} - 55●
Crop(x, y, w, h) => { - 56◐
let nw = if w == 0 { 1 } else { w } - 57◐
let nh = if h == 0 { 1 } else { h } - 58
@imgir.Crop(x, y, nw, nh) - 59
} - 60●
GaussianBlur(r, sigma) => { - 61
let nsigma = if sigma == 0.0F { - 62●
1.0F - 63●
} else if sigma < 0.0F { - 64○
0.0F - sigma - 65
} else { - 66●
sigma - 67
} - 68
@imgir.GaussianBlur(r, nsigma) - 69
} - 70●
Sharpen(amount) => { - 71
let na = if amount > 100.0F { - 72○
100.0F - 73●
} else if amount < -100.0F { - 74○
-100.0F - 75
} else { - 76●
amount - 77
} - 78
@imgir.Sharpen(na) - 79
} - 80◐
FieldClamp(lo, hi) => if lo > hi { @imgir.FieldClamp(hi, lo) } else { op } - 81
FieldMask(threshold) => - 82●
if threshold > 1000000.0F || threshold < -1000000.0F { - 83○
@imgir.FieldMask(0.0F) - 84
} else { - 85●
op - 86
} - 87●
STSnapshot(t) => { - 88◐
let nt = if t < 0.0F { 0.0F } else if t > 1.0F { 1.0F } else { t } - 89
@imgir.STSnapshot(nt) - 90
} - 91●
STInterpolate(t) => { - 92◐
let nt = if t < 0.0F { 0.0F } else if t > 1.0F { 1.0F } else { t } - 93
@imgir.STInterpolate(nt) - 94
} - 95●
_ => op - 96
} - 97
} - 98
- 99
///| - 100
/// 修复管道中所有算子的退化。 - 101
/// 描述 Repair all ops in a pipeline. - 102
pub fn repair_pipeline(pipeline : @imgir.IRPipeline) -> @imgir.IRPipeline { - 103●
let mut pipe = @imgir.IRPipeline::new() - 104
for op in pipeline.ops { - 105●
pipe = pipe.add(repair_op(op)) - 106
} - 107
pipe - 108
} - 109
- 110
///| - 111
/// 生成修复报告。 - 112
/// 生成 Generate repair report for a pipeline. - 113
pub fn repair_report(pipeline : @imgir.IRPipeline) -> RepairReport { - 114●
let ops = pipeline.ops - 115●
let original_degs = scan_degradations(ops) - 116●
let repaired_pipe = repair_pipeline(pipeline) - 117●
let repaired_degs = scan_degradations(repaired_pipe.ops) - 118
let repairs : Array[RepairAction] = [] - 119
for op in ops { - 120●
let degs = detect_degradation(op) - 121●
if degs.length() > 0 { - 122●
let repaired = repair_op(op) - 123●
repairs.push({ - 124●
op_tag: op.tag(), - 125●
repaired_op_tag: repaired.tag(), - 126●
repair_desc: "修复 " + degs.length().to_string() + " 处退化", - 127
}) - 128
} - 129
} - 130●
let repaired_count = original_degs.length() - repaired_degs.length() - 131
let summary = "修复 " + - 132●
repaired_count.to_string() + - 133
" 处退化,剩余 " + - 134●
repaired_degs.length().to_string() + - 135
" 处" - 136
{ - 137●
original_op_count: ops.length(), - 138●
repaired_op_count: repaired_pipe.ops.length(), - 139
repairs, - 140
remaining_degradations: repaired_degs, - 141
summary, - 142
} - 143
} - 144
- 145
///| - 146
/// 对全部 19 种算子生成修复报告。 - 147
/// 生成 Generate repair report for all 19 op variants. - 148
pub fn repair_all() -> Array[RepairReport] { - 149●
let reports : Array[RepairReport] = [] - 150●
for op in all_ops() { - 151●
let pipe = @imgir.IRPipeline::new().add(op) - 152●
reports.push(repair_report(pipe)) - 153
} - 154
reports - 155
} - 156
- 157
///| - 158
/// 修复后退化是否清零。 - 159
/// 描述 Whether all degradations are fixed. - 160
pub fn RepairReport::is_fully_repaired(self : RepairReport) -> Bool { - 161●
self.remaining_degradations.length() == 0 - 162
} - 163
- 164
///| - 165
/// 修复动作数。 - 166
/// 描述 Number of repair actions. - 167
pub fn RepairReport::repair_count(self : RepairReport) -> Int32 { - 168●
self.repairs.length() - 169
}