yobx.xshape._shape_helper#
- yobx.xshape._shape_helper._reshape_shape(shape: Tuple[int, ...], new_shape: Tuple[int, ...]) Tuple[int, ...][source]#
Computes the shape of the reshaped shape.
- yobx.xshape._shape_helper.all_float(seq: Sequence[Any]) bool[source]#
Returns True if all elements of seq are floats.
- yobx.xshape._shape_helper.all_int(seq: Sequence[Any]) bool[source]#
Returns True if all elements of seq are integers.
- yobx.xshape._shape_helper.all_int_or_float(seq: Sequence[Any]) bool[source]#
Returns True if all elements of seq are integers or floats.
- yobx.xshape._shape_helper.all_int_or_str(seq: Sequence[Any]) bool[source]#
Returns True if all elements of seq are integers or strings.
- yobx.xshape._shape_helper.compatible_dimensions(*dims: Sequence[int | str]) bool[source]#
Evaluates the fact all the dimensions can be equal or not.
- Parameters:
dims – dimensions
- Returns:
compatibility
<<<
from yobx.xshape._shape_helper import compatible_dimensions print(compatible_dimensions(1, 1)) # True print(compatible_dimensions(1, 2)) # False print(compatible_dimensions(1, "D")) # True print(compatible_dimensions(1, "D", "DD")) # True
>>>
True False True True
- yobx.xshape._shape_helper.compatible_shapes(sh1: Tuple[int | torch.SymInt | torch.SymFloat | float | str, ...], sh2: Tuple[int | torch.SymInt | torch.SymFloat | float | str, ...]) bool[source]#
Checks that two shapes are compatible. If both static, they must be equal. If dynamic, the variable part must be compatible meaning they could be equal.
- Parameters:
sh1 – first shape
sh2 – seconde shape
- Returns:
compatibility
<<<
from yobx.xshape._shape_helper import compatible_shapes print(compatible_shapes((1, 2), (1, 2))) # True print(compatible_shapes((1, 2), (1, "D2"))) # True print(compatible_shapes(("D2", 2), (1, "D2"))) # False print(compatible_shapes(("D2", 2), (2, "D2"))) # True
>>>
True True False True
- yobx.xshape._shape_helper.is_static_dimension(d: Any) bool[source]#
Returns True if dimension d is a static (plain integer) dimension.
- yobx.xshape._shape_helper.is_static_shape(shape: Tuple[int | torch.SymInt | torch.SymFloat | float | str, ...]) bool[source]#
Returns True if all dimensions of shape are static integers.