image.domain\self_evolve\equiv_check.mbt
83.3% · 25 / 30 points · 67 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/equiv_check - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 算子等价性检查 — 恒等算子 + 互逆算子对 - 7
// Op equivalence: identity ops + inverse pairs - 8
- 9
///| - 10
/// 判断算子是否为恒等(对图像无效果)。 - 11
/// 检查 Check if an op is identity (no effect on image). - 12
pub fn is_identity_op(op : @imgir.IROp) -> Bool { - 13●
match op { - 14●
@imgir.Brightness(0) => true - 15●
@imgir.GaussianBlur(0, _) => true - 16●
@imgir.BoxBlur(0) => true - 17●
@imgir.Sharpen(0.0F) => true - 18●
@imgir.Resize(w, h) => w == -1 && h == -1 // 标记恒等(非实际语义) - 19●
_ => false - 20
} - 21
} - 22
- 23
///| - 24
/// 判断两个算子是否互逆(连续执行 = 恒等)。 - 25
/// 检查 Check if two ops are inverse (composition = identity). - 26
pub fn check_inverse_pair(op1 : @imgir.IROp, op2 : @imgir.IROp) -> Bool { - 27●
match (op1, op2) { - 28●
(@imgir.FlipH, @imgir.FlipH) => true - 29●
(@imgir.FlipV, @imgir.FlipV) => true - 30●
(@imgir.Rotate90, @imgir.Rotate90) => false // 需要四次才恒等 - 31○
(@imgir.ToGray, @imgir.ToGray) => false // 幂等但非互逆 - 32●
_ => false - 33
} - 34
} - 35
- 36
///| - 37
/// 判断两个算子是否可合并(同类相邻)。 - 38
/// 检查 Check if two ops can be merged (same type, adjacent). - 39
pub fn can_merge(op1 : @imgir.IROp, op2 : @imgir.IROp) -> Bool { - 40●
match (op1, op2) { - 41●
(@imgir.Brightness(_), @imgir.Brightness(_)) => true - 42●
(@imgir.GaussianBlur(r1, _), @imgir.GaussianBlur(r2, _)) => r1 == r2 // 同半径可合并 - 43●
(@imgir.BoxBlur(_), @imgir.BoxBlur(_)) => true - 44●
_ => false - 45
} - 46
} - 47
- 48
///| - 49
/// 合并两个同类算子。 - 50
/// 合并 Merge two same-type ops into one. - 51
pub fn merge_ops(op1 : @imgir.IROp, op2 : @imgir.IROp) -> @imgir.IROp { - 52●
match (op1, op2) { - 53●
(@imgir.Brightness(a), @imgir.Brightness(b)) => @imgir.Brightness(a + b) - 54
(@imgir.GaussianBlur(r, s1), @imgir.GaussianBlur(_, s2)) => - 55●
@imgir.GaussianBlur(r, s1 + s2) // sigma 简单相加(近似) - 56
(@imgir.BoxBlur(r1), @imgir.BoxBlur(r2)) => - 57○
@imgir.BoxBlur(if r1 > r2 { r1 } else { r2 }) // 取较大半径 - 58○
_ => op1 // 无法合并,返回第一个 - 59
} - 60
} - 61
- 62
///| - 63
/// 判断 Rotate90 的连续次数是否为恒等。 - 64
/// 检查 Check if n consecutive Rotate90 = identity (n % 4 == 0). - 65
pub fn rotate90_power_is_identity(n : Int32) -> Bool { - 66●
n % 4 == 0 - 67
}