image.domain\self_evolve\optimize_types.mbt
100% · 2 / 2 points · 74 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/optimize_types - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 算法优化类型 — 优化建议 + 优化报告 - 7
// Optimization types: suggestion + report - 8
- 9
///| - 10
/// 优化类型。 - 11
/// 描述 Optimization kind. - 12
/// `#non_exhaustive` 表示未来可能添加新构造器 - 13
#derive(Eq, @debug.Debug) - 14
#non_exhaustive - 15
pub(all) enum OptimizationKind { - 16
RemoveRedundant // 消除冗余算子对(如 FlipH ∘ FlipH) - 17
RemoveIdentity // 消除恒等算子(如 Brightness(0)) - 18
MergeAdjacent // 合并相邻同类算子(如 Brightness(a) ∘ Brightness(b) → Brightness(a+b)) - 19
} - 20
- 21
///| - 22
pub extend OptimizationKind with @debug.Debug::{to_repr} - 23
- 24
///| - 25
pub extend OptimizationKind with Eq::{not_equal, equal} - 26
- 27
///| - 28
/// 优化建议。 - 29
/// 描述 Optimization suggestion. - 30
#derive(Eq, @debug.Debug) - 31
pub(all) struct OptimizationSuggestion { - 32
kind : OptimizationKind - 33
op_indices : Array[Int32] - 34
description : String - 35
before_count : Int32 - 36
after_count : Int32 - 37
} - 38
- 39
///| - 40
pub extend OptimizationSuggestion with @debug.Debug::{to_repr} - 41
- 42
///| - 43
pub extend OptimizationSuggestion with Eq::{not_equal, equal} - 44
- 45
///| - 46
/// 优化报告。 - 47
/// 描述 Optimization report. - 48
#derive(Eq, @debug.Debug) - 49
pub(all) struct OptimizationReport { - 50
original_length : Int32 - 51
optimized_length : Int32 - 52
suggestions : Array[OptimizationSuggestion] - 53
optimized_pipeline : @imgir.IRPipeline - 54
} - 55
- 56
///| - 57
pub extend OptimizationReport with @debug.Debug::{to_repr} - 58
- 59
///| - 60
pub extend OptimizationReport with Eq::{not_equal, equal} - 61
- 62
///| - 63
/// 优化是否减少了算子数。 - 64
/// 描述 Whether optimization reduced op count. - 65
pub fn OptimizationReport::is_reduced(self : OptimizationReport) -> Bool { - 66●
self.optimized_length < self.original_length - 67
} - 68
- 69
///| - 70
/// 减少的算子数。 - 71
/// 描述 Number of ops removed. - 72
pub fn OptimizationReport::reduction(self : OptimizationReport) -> Int32 { - 73●
self.original_length - self.optimized_length - 74
}