image.vision\imgir\ir_value.mbt

66% · 33 / 50 points · 164 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

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