File size: 1,257 Bytes
b025706 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | # SPDX-FileCopyrightText: © 2025 Tenstorrent USA, Inc.
# SPDX-License-Identifier: Apache-2.0
def clamp(value, min_value, max_value):
if value < min_value:
return min_value
elif value > max_value:
return max_value
return value
def is_default_value(values, default):
"""Check if values match a default, handling None, scalar, and iterable inputs."""
if values is None:
return True
if isinstance(values, (int, float)):
return values == default
return all(value == default for value in values)
def filter_none(kwargs: dict) -> dict:
return {k: v for k, v in kwargs.items() if v is not None}
def split_list(lst, n):
"""Split list into n equal parts."""
chunk_size = len(lst) // n
return [list(lst[i * chunk_size : (i + 1) * chunk_size]) for i in range(n)]
def is_power_of_2(n):
return n > 0 and (n & (n - 1)) == 0
def upper_power_of_2(n: int) -> int:
if n <= 1:
return 1
return 1 << (n - 1).bit_length()
def topk_would_route_to_large_indices(x, k) -> bool:
"""Return the authoritative C++ route decision for the sampling call shape."""
import ttnn
return ttnn._ttnn.operations.reduction._sampling_topk_would_route_to_large_indices(x, k)
|