Miscellaneous Functions¶
- Utilities.usefulfunctions.flatten_tensor_list(l, out_list=None)[source]¶
Simple recursive list flattening function that stops at torch.Tensor (without unwrapping).
- Utilities.usefulfunctions.grid2vec(*args)[source]¶
Convert a grid of points (such as given by torch.meshgrid) to a tensor of vectors.
- Utilities.usefulfunctions.import_implicit1_growth(filename, fieldname='growth', dtype=None)[source]¶
- Utilities.usefulfunctions.linear_transform(points, A)[source]¶
Applies a linear transformation to a point tensor.
- Parameters
points (torch.Tensor) – A \(N\times d\) tensor that will be transformed.
A (torch.Tensor) – A \(d\times d\) matrix that represent the linear transformation.
- Returns
The transformed points.
- Return type
- Utilities.usefulfunctions.pixels2points(pixels, frame_shape, frame_extent)[source]¶
Transform points from pixel space onto an uniformly mapped square space defined by an extent.
- Utilities.usefulfunctions.points2pixels(points, frame_shape, frame_extent, toindices=False)[source]¶
Transform points to pixel space.
- Utilities.usefulfunctions.points2voxels_affine(points, cube_shape, affine, toindices=False)[source]¶
Check if all tensors share the same property.
given by prop(tensor). Ignores None tensors and None property values. Returns the shared property or None if the property is not shared.
- Parameters
tensors (Iterable) – Iterable of tensors we want to check the common property from.
prop (callable) – Callable function which outputs the parameter we want to compare of the input tensor.
- Returns
Common property shared by all tensors. Returns none if properties are different among the tensors.
- Return type
- Utilities.usefulfunctions.tensors_device(tensors)[source]¶
Returns the common device on which tensors (an iterable of torch.Tensor) lives. Return None if tensors are on different devices.
- Parameters
tensors (Iterable) – Iterable of tensors.
- Returns
The common device of the iterable of tensors. None if tensors lives on different devices.
- Return type
torch.device
- Utilities.usefulfunctions.tensors_dtype(tensors)[source]¶
Returns the common dtypes on which tensors (an iterable of torch.Tensor) lives. Return None if tensors are of different dtypes.
- Parameters
tensors (Iterable) – Iterable of tensors.
- Returns
The common dtype of the iterable of tensors. None if tensors lives on different devices.
- Return type
torch.dtype