(signed=True, total_bits=8, add_zero=True)
| 148 | |
| 149 | |
| 150 | def create_linear_map(signed=True, total_bits=8, add_zero=True): |
| 151 | sign = -1.0 if signed else 0.0 |
| 152 | total_values = 2**total_bits |
| 153 | if add_zero or total_bits < 8: |
| 154 | # add a zero |
| 155 | # since we simulate less bits by having zeros in the data type, we |
| 156 | # we need to center the quantization around zero and as such lose |
| 157 | # a single value |
| 158 | total_values = 2**total_bits if not signed else 2**total_bits - 1 |
| 159 | |
| 160 | values = torch.linspace(sign, 1.0, total_values) |
| 161 | gap = 256 - values.numel() |
| 162 | if gap == 0: |
| 163 | return values |
| 164 | else: |
| 165 | l = values.numel() // 2 # noqa: E741 |
| 166 | return torch.Tensor(values[:l].tolist() + [0] * gap + values[l:].tolist()) |
| 167 | |
| 168 | |
| 169 | def create_normal_map(offset=0.9677083, use_extra_value=True): |
nothing calls this directly
no outgoing calls
no test coverage detected