image.vision\imgir\ir_value.mbt
66% · 33 / 50 points · 164 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # IR 值 imgir/ir_value - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// ImgIR 统一中间表示:IR 值类型。 - 7
// Unified IR value type: represents any intermediate value in the IR pipeline. - 8
// - 9
// 设计思想(GeoVerse 五层): - 10
// 所有图像、场、时空上下文统一编码为 IRValue, - 11
// 支持算子序列化、JIT 编译、GPU 向量化执行、分布式任务分发。 - 12
- 13
///| - 14
/// IR 值类型:统一中间表示,可持有 Image / ScalarField / VectorField / TImage / Float / Int。 - 15
/// IR 值类型:统一表示 IR value type: unified representation holding Image / ScalarField / VectorField / TImage / Float / Int. - 16
/// `#non_exhaustive` 表示未来可能添加新构造器 - 17
#derive(Eq, @debug.Debug) - 18
#non_exhaustive - 19
pub(all) enum IRValue { - 20
VImage(@types.Image) - 21
VScalarField(@fieldimg.ScalarField) - 22
VVectorField(@fieldimg.VectorField) - 23
VTImage(@spatiotemporal.TImage) - 24
VFloat(Float) - 25
VInt(Int32) - 26
VUnit - 27
} - 28
- 29
///| - 30
pub extend IRValue with @debug.Debug::{to_repr} - 31
- 32
///| - 33
pub extend IRValue with Eq::{not_equal, equal} - 34
- 35
///| - 36
/// IR 值类型标签:用于类型检查和序列化。 - 37
/// IR 值类型:统一表示 IR value type tag: for type checking and serialization. - 38
pub fn IRValue::type_tag(self : IRValue) -> String { - 39●
match self { - 40●
VImage(_) => "Image" - 41●
VScalarField(_) => "ScalarField" - 42●
VVectorField(_) => "VectorField" - 43●
VTImage(_) => "TImage" - 44●
VFloat(_) => "Float" - 45●
VInt(_) => "Int" - 46●
VUnit => "Unit" - 47
} - 48
} - 49
- 50
///| - 51
/// 判断 IR 值是否为 Image。 - 52
/// 检查 IR 值是否为 Image Check if IR value is an Image. - 53
pub fn IRValue::is_image(self : IRValue) -> Bool { - 54●
match self { - 55●
VImage(_) => true - 56●
_ => false - 57
} - 58
} - 59
- 60
///| - 61
/// 判断 IR 值是否为 ScalarField。 - 62
/// 检查 IR 值是否为 ScalarField Check if IR value is a ScalarField. - 63
pub fn IRValue::is_scalar_field(self : IRValue) -> Bool { - 64●
match self { - 65●
VScalarField(_) => true - 66○
_ => false - 67
} - 68
} - 69
- 70
///| - 71
/// 判断 IR 值是否为 VectorField。 - 72
/// 检查 IR 值是否为 VectorField Check if IR value is a VectorField. - 73
pub fn IRValue::is_vector_field(self : IRValue) -> Bool { - 74●
match self { - 75●
VVectorField(_) => true - 76○
_ => false - 77
} - 78
} - 79
- 80
///| - 81
/// 判断 IR 值是否为 TImage。 - 82
/// 检查 IR 值是否为 TImage Check if IR value is a TImage. - 83
pub fn IRValue::is_timage(self : IRValue) -> Bool { - 84●
match self { - 85●
VTImage(_) => true - 86○
_ => false - 87
} - 88
} - 89
- 90
///| - 91
/// 提取 Image 值,类型不匹配则抛异常。 - 92
/// 提取 Image 值;类型不匹配时 raise Extract Image value; raises on type mismatch. - 93
pub fn IRValue::as_image(self : IRValue) -> @types.Image raise @types.LoadError { - 94●
match self { - 95●
VImage(img) => img - 96
_ => - 97●
raise @types.LoadError::DecodeFailed( - 98
"IRValue::as_image: 类型不匹配,期望 Image,实际 " + - 99●
self.type_tag(), - 100
) - 101
} - 102
} - 103
- 104
///| - 105
/// 提取 ScalarField 值,类型不匹配则抛异常。 - 106
/// 提取 ScalarField 值;类型不匹配时 raise Extract ScalarField value; raises on type mismatch. - 107
pub fn IRValue::as_scalar_field( - 108
self : IRValue, - 109
) -> @fieldimg.ScalarField raise @types.LoadError { - 110●
match self { - 111●
VScalarField(f) => f - 112
_ => - 113○
raise @types.LoadError::DecodeFailed( - 114
"IRValue::as_scalar_field: 类型不匹配,期望 ScalarField,实际 " + - 115○
self.type_tag(), - 116
) - 117
} - 118
} - 119
- 120
///| - 121
/// 提取 VectorField 值,类型不匹配则抛异常。 - 122
/// 提取 VectorField 值;类型不匹配时 raise Extract VectorField value; raises on type mismatch. - 123
pub fn IRValue::as_vector_field( - 124
self : IRValue, - 125
) -> @fieldimg.VectorField raise @types.LoadError { - 126○
match self { - 127○
VVectorField(f) => f - 128
_ => - 129○
raise @types.LoadError::DecodeFailed( - 130
"IRValue::as_vector_field: 类型不匹配,期望 VectorField,实际 " + - 131○
self.type_tag(), - 132
) - 133
} - 134
} - 135
- 136
///| - 137
/// 提取 TImage 值,类型不匹配则抛异常。 - 138
/// 提取 TImage 值;类型不匹配时 raise Extract TImage value; raises on type mismatch. - 139
pub fn IRValue::as_timage( - 140
self : IRValue, - 141
) -> @spatiotemporal.TImage raise @types.LoadError { - 142●
match self { - 143●
VTImage(ti) => ti - 144
_ => - 145○
raise @types.LoadError::DecodeFailed( - 146
"IRValue::as_timage: 类型不匹配,期望 TImage,实际 " + - 147○
self.type_tag(), - 148
) - 149
} - 150
} - 151
- 152
///| - 153
/// 提取 Float 值,类型不匹配则抛异常。 - 154
/// 提取 Float 值;类型不匹配时 raise Extract Float value; raises on type mismatch. - 155
pub fn IRValue::as_float(self : IRValue) -> Float raise @types.LoadError { - 156○
match self { - 157○
VFloat(v) => v - 158
_ => - 159○
raise @types.LoadError::DecodeFailed( - 160
"IRValue::as_float: 类型不匹配,期望 Float,实际 " + - 161○
self.type_tag(), - 162
) - 163
} - 164
}