Download helpers.py from fomofo/tap-ct-s-3d: direct link, hf CLI and curl.
- Browser
- Download file 2.17 kB
-
https://huggingface.co/fomofo/tap-ct-s-3d/resolve/69cbc867c6abdea8ccc1a936b6e9c97de21aeb4d/helpers.py
- Command line
-
hf download hf://fomofo/tap-ct-s-3d@69cbc867c6abdea8ccc1a936b6e9c97de21aeb4d/helpers.py
-
curl -L -o helpers.py https://huggingface.co/fomofo/tap-ct-s-3d/resolve/69cbc867c6abdea8ccc1a936b6e9c97de21aeb4d/helpers.py
2.17 kB
| # Copyright 2025 AI for Oncology Research Group. All Rights Reserved. | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| def make_tuple(x: int | tuple, n: int) -> tuple: | |
| """Convert an integer or a tuple to an n-tuple. | |
| Parameters | |
| ---------- | |
| x : int or tuple | |
| Input value which can be an integer or a tuple of n integers. | |
| n : int | |
| The length of the tuple to return. | |
| Returns | |
| ------- | |
| tuple | |
| A tuple of n integers. | |
| """ | |
| if isinstance(x, tuple) or isinstance(x, list): | |
| if len(x) != n: | |
| raise ValueError(f"Expected a tuple of length {n}, got {len(x)}") | |
| if not all(isinstance(i, int) for i in x): | |
| raise ValueError("All elements in the tuple must be integers") | |
| return tuple(x) | |
| if not isinstance(x, int): | |
| raise TypeError(f"Expected int, got {type(x)}") | |
| return (x,) * n | |
| def make_2tuple(x: int | tuple[int, int]) -> tuple[int, int]: | |
| """Convert an integer or a tuple to a 2-tuple. | |
| Parameters | |
| ---------- | |
| x : int or tuple[int, int] | |
| Input value which can be an integer or a tuple of two integers with two elements. | |
| Returns | |
| ------- | |
| tuple[int, int] | |
| A tuple of two integers. | |
| """ | |
| return make_tuple(x, 2) | |
| def make_3tuple(x: int | tuple[int, int, int]) -> tuple[int, int, int]: | |
| """Convert an integer or a tuple to a 3-tuple. | |
| Parameters | |
| ---------- | |
| x : int or tuple[int, int, int] | |
| Input value which can be an integer or a tuple of three integers with three elements. | |
| Returns | |
| ------- | |
| tuple[int, int, int] | |
| A tuple of three integers. | |
| """ | |
| return make_tuple(x, 3) | |