jacinle.utils.argument#
Classes
A helper class to ensure that a value is unique. |
Functions
|
Convert a sequence or a single value to a tuple of integers. |
|
Convert a sequence or a single value to a tuple. |
|
Convert the argument list to a tuple of values. |
|
Convert a value or a tuple to a tuple of length 2. |
|
Convert a value or a tuple to a tuple of length 3. |
|
Convert a value or a tuple to a tuple of length 4. |
|
Convert a value or a tuple to a tuple of length ndim. |
Class UniqueValueGetter
- class UniqueValueGetter[source]#
Bases:
object
A helper class to ensure that a value is unique.
Example
uvg = UniqueValueGetter() uvg.set(1) uvg.set(2) # will raise ValueError uvg.set(1) print(uvg.get()) # 1
- __init__(msg='Unique value checking failed', default=None)[source]#
Initialize the UniqueValueGetter.
- __new__(**kwargs)#
Functions
- asshape(arr_like)[source]#
Convert a sequence or a single value to a tuple of integers. It will return None if the input is None.
- astuple(arr_like)[source]#
Convert a sequence or a single value to a tuple. This method differ from the system method tuple in that a single value (incl. int, string, bytes) will be converted to a tuple of length 1.
- canonize_args_list(args, *, allow_empty=False, cvt=None)[source]#
Convert the argument list to a tuple of values. This is useful to make unified interface for shape-related operations.
Example
def foo(*args): args = canonize_args_list(args, allow_empty=True) print(args) foo(1, 2, 3) # (1, 2, 3) foo((1, 2, 3)) # (1, 2, 3) foo(1) # (1,) foo() # ()
- get_2dshape(x, default=None, type=int)[source]#
Convert a value or a tuple to a tuple of length 2.
- Parameters:
- Returns:
a tuple of length 2.
- Return type:
- get_3dshape(x, default=None, type=int)[source]#
Convert a value or a tuple to a tuple of length 3.
- Parameters:
- Returns:
a tuple of length 3.
- Return type:
- get_4dshape(x, default=None, type=int)[source]#
Convert a value or a tuple to a tuple of length 4.
- Parameters:
- Returns:
a tuple of length 4.
- Return type: