hidet.utils¶
Functions:
|
example: factor(12) => [1, 2, 3, 4, 6, 12] |
|
Decorate an initialization function. |
|
Get the greatest common divisor of non-negative integers a and b. |
|
Get the least common multiple of non-negative integers a and b. |
|
Given two tensors with the same shape and data type, this function finds the minimal e, such that |
|
Get the ceiling of n / d. |
A context manager to disable garbage collection and ensure it is re-enabled afterward. |
Classes:
Directed graph. |
- hidet.utils.initialize(*args, **kwargs)[source]¶
Decorate an initialization function. After decorating with this function, the initialization function will be called after the definition.
- Parameters:
args – The positional arguments of initializing.
kwargs – The keyword arguments of initializing.
- Returns:
A decorator that will call given function with args and kwargs, and return None (to prevent this function to be called again).
- Return type:
ret
- hidet.utils.gcd(a, b, *args)[source]¶
Get the greatest common divisor of non-negative integers a and b.
- Parameters:
a (int) – The lhs operand.
b (int) – The rhs operand.
- Returns:
ret – The greatest common divisor.
- Return type:
int
- hidet.utils.lcm(a, b)[source]¶
Get the least common multiple of non-negative integers a and b. :param a: The lhs operand. :type a: int :param b: The rhs operand. :type b: int
- Returns:
ret – The least common multiple.
- Return type:
int
- Parameters:
a (int) –
b (int) –
- hidet.utils.error_tolerance(a, b)[source]¶
Given two tensors with the same shape and data type, this function finds the minimal e, such that
abs(a - b) <= abs(b) * e + e
- Parameters:
a (Union[np.ndarray, hidet.Tensor]) – The first tensor.
b (Union[np.ndarray, hidet.Tensor]) – The second tensor.
- Returns:
ret – The error tolerance between a and b.
- Return type:
float
- hidet.utils.cdiv(n, d)[source]¶
Get the ceiling of n / d.
- Parameters:
n (int) – The numerator.
d (int) – The denominator.
- Returns:
ret – The ceiling of n / d.
- Return type:
int
- class hidet.utils.DirectedGraph[source]¶
Directed graph.
A directed graph representation.
Methods:
from_edges
(edges)Create a directed graph from edges.
has_node
(node)Whether the node has been added to the graph.
has_edge
(src, dst)Whether there is an edge (src, dst) in the graph.
add_node
(node)Add a node.
add_edge
(src, dst)Add an edge.
Get a topological order of the nodes in the directed graph.
- static from_edges(edges)[source]¶
Create a directed graph from edges.
The edges should be a list of (src, dst) tuples, and each tuple represents an edge.
- Parameters:
edges (List[Tuple[GraphNode, GraphNode]]) – The edges of the directed graph to be created.
- Returns:
ret – The created directed graph.
- Return type:
- has_node(node)[source]¶
Whether the node has been added to the graph.
- Parameters:
node (GraphNode) – The node to be checked.
- Returns:
ret – True if the node has been added.
- Return type:
bool
- has_edge(src, dst)[source]¶
Whether there is an edge (src, dst) in the graph.
- Parameters:
src (GraphNode) – The source node of the edge.
dst (GraphNode) – The destination node of the edge.
- Returns:
ret – True if the edge (src, dst) is in the graph.
- Return type:
bool
- add_node(node)[source]¶
Add a node.
- Parameters:
node (GraphNode) – The node to be added to the graph.