MCPcopy Create free account
hub / github.com/apache/arrow / ScalarUnpackGenerator

Class ScalarUnpackGenerator

cpp/src/arrow/util/bpacking_scalar_codegen.py:74–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72
73@dataclasses.dataclass
74class ScalarUnpackGenerator:
75 out_type: str
76 # Used to reduce the number of bytes read on odd bit width by reading
77 # the last input in half width.
78 smart_halve: bool
79
80 @property
81 def out_bit_width(self) -> int:
82 if self.out_type.startswith("uint"):
83 return int(self.out_type.removeprefix("uint").removesuffix("_t"))
84 raise NotImplementedError(f"Unsupported type {self.out_type}")
85
86 @property
87 def out_byte_width(self) -> int:
88 return self.out_bit_width // 8
89
90 @property
91 def out_type_half(self) -> str:
92 return f"uint{self.out_bit_width // 2}_t"
93
94 @property
95 def struct_name(self) -> str:
96 return "ScalarUnpackerForWidth"
97
98 def struct_specialization(self, bit: int) -> str:
99 return f"{self.struct_name}<{self.out_type}, {bit}>"
100
101 def print_struct_declaration(self):
102 print("template<typename Uint, int kBitWidth>")
103 print(f"struct {self.struct_name};")
104
105 @property
106 def total_in_values(self) -> int:
107 """How many values are we going to unpack?"""
108 if self.smart_halve:
109 return self.out_bit_width // 2
110 return self.out_bit_width
111
112 def total_out_values(self, bit: int) -> int:
113 return (
114 self.total_in_values * bit + self.out_bit_width - 1
115 ) // self.out_bit_width
116
117 def total_in_bytes(self, bit: int) -> int:
118 return (self.total_in_values * bit) // 8
119
120 def total_out_bytes(self, bit: int) -> int:
121 return (
122 self.total_in_values * bit + self.out_byte_width - 1
123 ) // self.out_byte_width
124
125 def print_unpack_k(self, bit: int) -> None:
126 print(
127 f" static const uint8_t* unpack(const uint8_t* in, {self.out_type}* out) {{"
128 )
129
130 print(
131 f" constexpr {self.out_type} mask = "

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected