1#  Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2#  See https://llvm.org/LICENSE.txt for license information.
3#  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5from typing import List
6
7from mlir.ir import Type
8
9__all__ = [
10  "QuantizedType",
11  "AnyQuantizedType",
12  "UniformQuantizedType",
13  "UniformQuantizedPerAxisType",
14  "CalibratedQuantizedType",
15]
16
17class QuantizedType(Type):
18  @staticmethod
19  def isinstance(type: Type) -> bool: ...
20
21  @staticmethod
22  def default_minimum_for_integer(is_signed: bool, integral_width: int) -> int:
23    ...
24
25  @staticmethod
26  def default_maximum_for_integer(is_signed: bool, integral_width: int) -> int:
27    ...
28
29  @property
30  def expressed_type(self) -> Type: ...
31
32  @property
33  def flags(self) -> int: ...
34
35  @property
36  def is_signed(self) -> bool: ...
37
38  @property
39  def storage_type(self) -> Type: ...
40
41  @property
42  def storage_type_min(self) -> int: ...
43
44  @property
45  def storage_type_max(self) -> int: ...
46
47  @property
48  def storage_type_integral_width(self) -> int: ...
49
50  def is_compatible_expressed_type(self, candidate: Type) -> bool: ...
51
52  @property
53  def quantized_element_type(self) -> Type: ...
54
55  def cast_from_storage_type(self, candidate: Type) -> Type: ...
56
57  @staticmethod
58  def cast_to_storage_type(type: Type) -> Type: ...
59
60  def cast_from_expressed_type(self, candidate: Type) -> Type: ...
61
62  @staticmethod
63  def cast_to_expressed_type(type: Type) -> Type: ...
64
65  def cast_expressed_to_storage_type(self, candidate: Type) -> Type: ...
66
67
68class AnyQuantizedType(QuantizedType):
69
70  @classmethod
71  def get(cls, flags: int, storage_type: Type, expressed_type: Type,
72          storage_type_min: int, storage_type_max: int) -> Type:
73    ...
74
75
76class UniformQuantizedType(QuantizedType):
77
78  @classmethod
79  def get(cls, flags: int, storage_type: Type, expressed_type: Type,
80          scale: float, zero_point: int, storage_type_min: int,
81          storage_type_max: int) -> Type: ...
82
83  @property
84  def scale(self) -> float: ...
85
86  @property
87  def zero_point(self) -> int: ...
88
89  @property
90  def is_fixed_point(self) -> bool: ...
91
92
93class UniformQuantizedPerAxisType(QuantizedType):
94
95  @classmethod
96  def get(cls, flags: int, storage_type: Type, expressed_type: Type,
97          scales: List[float], zero_points: List[int], quantized_dimension: int,
98          storage_type_min: int, storage_type_max: int):
99    ...
100
101  @property
102  def scales(self) -> List[float]: ...
103
104  @property
105  def zero_points(self) -> List[float]: ...
106
107  @property
108  def quantized_dimension(self) -> int: ...
109
110  @property
111  def is_fixed_point(self) -> bool: ...
112
113
114def CalibratedQuantizedType(QuantizedType):
115
116  @classmethod
117  def get(cls, expressed_type: Type, min: float, max: float): ...
118
119  @property
120  def min(self) -> float: ...
121
122  @property
123  def max(self) -> float: ...