image.domain\self_evolve\equivalence.mbt
97.4% · 38 / 39 points · 147 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/equivalence - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 算子等价性验证 — 验证两个算子序列是否等价 - 7
// Op equivalence verification: verify whether two op sequences are equivalent - 8
// - 9
// Phase 7 v294: 将演化从"独立"推向"等价验证" — 证明两个管道产生相同结果。 - 10
- 11
///| - 12
/// 单次等价性检查结果。 - 13
/// 描述 Single equivalence check result. - 14
#derive(Eq, @debug.Debug) - 15
pub(all) struct EquivalenceCheck { - 16
pipeline_a_desc : String - 17
pipeline_b_desc : String - 18
is_equivalent : Bool - 19
reason : String - 20
} - 21
- 22
///| - 23
pub extend EquivalenceCheck with @debug.Debug::{to_repr} - 24
- 25
///| - 26
pub extend EquivalenceCheck with Eq::{not_equal, equal} - 27
- 28
///| - 29
/// 等价性验证报告。 - 30
/// 描述 Equivalence verification report. - 31
#derive(Eq, @debug.Debug) - 32
pub(all) struct EquivalenceReport { - 33
checks : Array[EquivalenceCheck] - 34
total_equivalent : Int32 - 35
total_not_equivalent : Int32 - 36
summary : String - 37
} - 38
- 39
///| - 40
pub extend EquivalenceReport with @debug.Debug::{to_repr} - 41
- 42
///| - 43
pub extend EquivalenceReport with Eq::{not_equal, equal} - 44
- 45
///| - 46
/// 检查两个管道是否等价(相同算子序列)。 - 47
/// 检查 Check whether two pipelines are equivalent (same op sequence). - 48
pub fn check_equivalence( - 49
pipe_a : @imgir.IRPipeline, - 50
pipe_b : @imgir.IRPipeline, - 51
) -> EquivalenceCheck { - 52●
let desc_a = @imgir.ir_describe(pipe_a) - 53●
let desc_b = @imgir.ir_describe(pipe_b) - 54
let ops_a = pipe_a.ops - 55
let ops_b = pipe_b.ops - 56●
let len_a = ops_a.length() - 57●
let len_b = ops_b.length() - 58
let mut is_equiv = true - 59
let mut reason = "" - 60
if len_a != len_b { - 61●
is_equiv = false - 62●
reason = "长度不同: " + len_a.to_string() + " vs " + len_b.to_string() - 63
} else { - 64●
for i in 0..<len_a { - 65●
let tag_a = ops_a[i].tag() - 66●
let tag_b = ops_b[i].tag() - 67
if tag_a != tag_b { - 68●
is_equiv = false - 69●
reason = "位置 " + i.to_string() + ": " + tag_a + " vs " + tag_b - 70
break - 71
} - 72
} - 73
if is_equiv { - 74●
reason = "算子序列完全相同" - 75
} - 76
} - 77
{ - 78
pipeline_a_desc: desc_a, - 79
pipeline_b_desc: desc_b, - 80
is_equivalent: is_equiv, - 81
reason, - 82
} - 83
} - 84
- 85
///| - 86
/// 简化等价判断。 - 87
/// 描述 Simplified equivalence check. - 88
pub fn are_equivalent( - 89
pipe_a : @imgir.IRPipeline, - 90
pipe_b : @imgir.IRPipeline, - 91
) -> Bool { - 92●
check_equivalence(pipe_a, pipe_b).is_equivalent - 93
} - 94
- 95
///| - 96
/// 检查所有算子的自等价性(每个算子与自己等价)。 - 97
/// 检查 Check self-equivalence for all ops. - 98
pub fn check_equivalence_all() -> EquivalenceReport { - 99●
let checks : Array[EquivalenceCheck] = [] - 100●
let ops = all_ops() - 101
for op in ops { - 102●
let pipe_a = @imgir.IRPipeline::new().add(op) - 103●
let pipe_b = @imgir.IRPipeline::new().add(op) - 104●
checks.push(check_equivalence(pipe_a, pipe_b)) - 105
} - 106
let mut equiv_count = 0 - 107
let mut non_equiv_count = 0 - 108
for c in checks { - 109●
if c.is_equivalent { - 110●
equiv_count = equiv_count + 1 - 111
} else { - 112○
non_equiv_count = non_equiv_count + 1 - 113
} - 114
} - 115
let summary = "等价性验证: " + - 116●
equiv_count.to_string() + - 117
" 等价, " + - 118●
non_equiv_count.to_string() + - 119
" 不等价" - 120
{ - 121
checks, - 122
total_equivalent: equiv_count, - 123
total_not_equivalent: non_equiv_count, - 124
summary, - 125
} - 126
} - 127
- 128
///| - 129
/// 获取与指定算子等价的算子标签(相同 tag 的算子)。 - 130
/// 获取 Get equivalent op tags (ops with same tag). - 131
pub fn equivalence_class(op : @imgir.IROp) -> Array[String] { - 132●
let target_tag = op.tag() - 133
let result : Array[String] = [] - 134●
for other in all_ops() { - 135●
if other.tag() == target_tag { - 136●
result.push(other.tag()) - 137
} - 138
} - 139
result - 140
} - 141
- 142
///| - 143
/// 等价性报告是否全部等价。 - 144
/// 描述 Whether all checks are equivalent. - 145
pub fn EquivalenceReport::all_equivalent(self : EquivalenceReport) -> Bool { - 146●
self.total_not_equivalent == 0 - 147
}