image.domain\self_evolve\degrade_detect.mbt
98.4% · 60 / 61 points · 221 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/degrade_detect - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 退化场景自动发现 — 基于 4.7.4 领域规则 - 7
// Degradation detection: based on 4.7.4 domain rules - 8
// - 9
// 规则集: - 10
// 1. 数值鲁棒性:除零 / 奇异矩阵 / NaN / Inf - 11
// 2. 退化几何:除零 / 零面积 - 12
// 3. 场间断:边界不连续 / 插值外推 - 13
// 4. 时空拓扑:时间超出 [0,1] - 14
// 5. 四目标兼容:纯 MoonBit(静态保证,运行时无需检测) - 15
- 16
///| - 17
/// 检测单个算子的退化场景。 - 18
/// 检测 Detect degradation cases for a single op. - 19
pub fn detect_degradation(op : @imgir.IROp) -> Array[DegradationCase] { - 20●
let tag = op.tag() - 21●
match op { - 22
Resize(w, h) => - 23●
if w == 0 || h == 0 { - 24●
[ - 25
{ - 26
kind: DivisionByZero, - 27
op_tag: tag, - 28
description: "Resize 到零尺寸(w=" + - 29●
w.to_string() + - 30
", h=" + - 31●
h.to_string() + - 32
"),可能触发除零", - 33
severity: Fatal, - 34
}, - 35
] - 36
} else { - 37●
[] - 38
} - 39
Crop(_x, _y, w, h) => - 40●
if w == 0 || h == 0 { - 41●
[ - 42
{ - 43
kind: DivisionByZero, - 44
op_tag: tag, - 45
description: "Crop 零尺寸区域,可能触发除零", - 46
severity: Fatal, - 47
}, - 48
] - 49
} else { - 50●
[] - 51
} - 52
GaussianBlur(_r, sigma) => - 53●
if sigma == 0.0F { - 54●
[ - 55
{ - 56
kind: DivisionByZero, - 57
op_tag: tag, - 58
description: "GaussianBlur sigma=0.0,高斯核归一化除零", - 59
severity: Critical, - 60
}, - 61
] - 62●
} else if sigma < 0.0F { - 63●
[ - 64
{ - 65
kind: NaNValue, - 66
op_tag: tag, - 67
description: "GaussianBlur sigma<0.0,负 sigma 产生 NaN/Inf", - 68
severity: Critical, - 69
}, - 70
] - 71
} else { - 72●
[] - 73
} - 74
Sharpen(amount) => - 75●
if amount > 100.0F || amount < -100.0F { - 76●
[ - 77
{ - 78
kind: Overflow, - 79
op_tag: tag, - 80
description: "Sharpen amount 极端值(" + - 81●
amount.to_string() + - 82
"),可能溢出", - 83
severity: Warning, - 84
}, - 85
] - 86
} else { - 87●
[] - 88
} - 89
FieldClamp(lo, hi) => - 90●
if lo > hi { - 91●
[ - 92
{ - 93
kind: FieldDiscontinuity, - 94
op_tag: tag, - 95
description: "FieldClamp 下界 > 上界(lo=" + - 96●
lo.to_string() + - 97
" > hi=" + - 98●
hi.to_string() + - 99
"),行为未定义", - 100
severity: Critical, - 101
}, - 102
] - 103
} else { - 104●
[] - 105
} - 106
FieldMask(threshold) => - 107●
if threshold > 1000000.0F || threshold < -1000000.0F { - 108●
[ - 109
{ - 110
kind: FieldDiscontinuity, - 111
op_tag: tag, - 112
description: "FieldMask 阈值极端(" + - 113●
threshold.to_string() + - 114
"),全场单值", - 115
severity: Warning, - 116
}, - 117
] - 118
} else { - 119●
[] - 120
} - 121
STSnapshot(t) => - 122●
if t < 0.0F || t > 1.0F { - 123●
[ - 124
{ - 125
kind: FieldDiscontinuity, - 126
op_tag: tag, - 127
description: "STSnapshot t=" + - 128●
t.to_string() + - 129
" 超出 [0,1],时间外推", - 130
severity: Warning, - 131
}, - 132
] - 133
} else { - 134●
[] - 135
} - 136
STInterpolate(t) => - 137●
if t < 0.0F || t > 1.0F { - 138●
[ - 139
{ - 140
kind: FieldDiscontinuity, - 141
op_tag: tag, - 142
description: "STInterpolate t=" + - 143●
t.to_string() + - 144
" 超出 [0,1],插值外推", - 145
severity: Warning, - 146
}, - 147
] - 148
} else { - 149●
[] - 150
} - 151●
_ => [] - 152
} - 153
} - 154
- 155
///| - 156
/// 批量扫描退化场景。 - 157
/// 描述 Batch scan degradations for multiple ops. - 158
pub fn scan_degradations(ops : Array[@imgir.IROp]) -> Array[DegradationCase] { - 159●
let all : Array[DegradationCase] = [] - 160
for op in ops { - 161●
for d in detect_degradation(op) { - 162●
all.push(d) - 163
} - 164
} - 165
all - 166
} - 167
- 168
///| - 169
/// 按严重程度过滤退化场景。 - 170
/// 滤波 Filter degradations by severity. - 171
pub fn filter_by_severity( - 172
cases : Array[DegradationCase], - 173
min_severity : Severity, - 174
) -> Array[DegradationCase] { - 175●
let min_level = match min_severity { - 176○
Warning => 0 - 177●
Critical => 1 - 178●
Fatal => 2 - 179
} - 180
let result : Array[DegradationCase] = [] - 181
for c in cases { - 182●
let level = match c.severity { - 183●
Warning => 0 - 184●
Critical => 1 - 185●
Fatal => 2 - 186
} - 187
if level >= min_level { - 188●
result.push(c) - 189
} - 190
} - 191
result - 192
} - 193
- 194
///| - 195
/// 按退化类型分组计数。 - 196
/// 计数 Count degradations by kind. - 197
pub fn count_by_kind( - 198
cases : Array[DegradationCase], - 199
) -> Array[(DegradationKind, Int32)] { - 200●
let kinds = [ - 201
DivisionByZero, - 202
SingularMatrix, - 203
FieldDiscontinuity, - 204
Overflow, - 205
NaNValue, - 206
InfValue, - 207
] - 208
let result : Array[(DegradationKind, Int32)] = [] - 209
for k in kinds { - 210●
let mut count = 0 - 211
for c in cases { - 212●
if c.kind == k { - 213●
count = count + 1 - 214
} - 215
} - 216
if count > 0 { - 217●
result.push((k, count)) - 218
} - 219
} - 220
result - 221
}