phlower.PhlowerTensor¶
- class phlower.PhlowerTensor(tensor, dimension_tensor=None, is_time_series=False, is_voxel=False)[source]¶
Bases:
IPhlowerTensor
PhlowerTensor is a wrapper of torch.Tensor with a physical dimension.
- Parameters:
(torch.Tensor) (tensor) – Tensor to be wrapped.
(PhlowerDimensionTensor (dimension_tensor) – Physical dimension tensor.
optional) – Physical dimension tensor.
(bool (is_voxel) – Whether the tensor is a time series.
optional) – Whether the tensor is a time series.
(bool – Whether the tensor is a voxel.
optional) – Whether the tensor is a voxel.
tensor (torch.Tensor)
dimension_tensor (PhlowerDimensionTensor | None)
is_time_series (bool)
is_voxel (bool)
Examples
>>> tensor = torch.randn(5, 100, 3) >>> phlower_tensor = PhlowerTensor( ... tensor, ... dimension_tensor={"L": 1, "T": -1}, ... is_time_series=True, ... is_voxel=False, ... ) >>> print(phlower_tensor)
Methods
__init__
(tensor[, dimension_tensor, ...])as_pattern
(pattern)Convert the tensor to a pattern.
backward
()Backward the tensor.
clone
()Clone the tensor.
coalesce
()Coalesce the tensor.
detach
()Detach the tensor.
from_pattern
(tensor[, dimension_tensor, pattern])indices
()Returns the indices of the tensor.
Returns the number of vertices.
numel
()Number of elements in the tensor.
numpy
()rank
()Returns the tensor rank.
rearrange
(pattern, **axes_length)Rearrange the tensor.
reshape
(shape[, is_time_series, is_voxel])Reshape the tensor.
size
()Size of the tensor.
slice_time
(indices)Slice the time series tensor.
to
([device, non_blocking, dtype])Convert the tensor to a different device or data type.
to_numpy
()Convert to numpy.ndarray.
to_phlower_array
()Convert to torch.Tensor.
Convert to vertexwise 2D tensor which has (n_vertices, -1) shape.
transpose
(dim0, dim1)Transpose the tensor.
values
()Returns the values of the tensor.
Attributes
Device of the tensor.
Physical dimension tensor.
Data type of the tensor.
Whether the tensor has a physical dimension.
Whether the tensor is a sparse tensor.
Whether the tensor is a time series.
Whether the tensor is a voxel.
Shape of the tensor.
Shape pattern of the tensor.
- as_pattern(pattern)[source]¶
Convert the tensor to a pattern.
- Returns:
Patterned tensor.
- Return type:
- Parameters:
pattern (str)
- property device: device¶
Device of the tensor.
- Returns:
Device of the tensor.
- Return type:
torch.device
- property dimension: PhlowerDimensionTensor | None¶
Physical dimension tensor.
- Returns:
Physical dimension tensor.
- Return type:
PhlowerDimensionTensor | None
- property dtype: dtype¶
Data type of the tensor.
- Returns:
Data type of the tensor.
- Return type:
torch.dtype
- property has_dimension: bool¶
Whether the tensor has a physical dimension.
- Returns:
Whether the tensor has a physical dimension.
- Return type:
bool
- indices()[source]¶
Returns the indices of the tensor.
- Returns:
Indices of the tensor.
- Return type:
torch.Tensor
- property is_sparse: bool¶
Whether the tensor is a sparse tensor.
- Returns:
Whether the tensor is a sparse tensor.
- Return type:
bool
- property is_time_series: bool¶
Whether the tensor is a time series.
- Returns:
Whether the tensor is a time series.
- Return type:
bool
- property is_voxel: bool¶
Whether the tensor is a voxel.
- Returns:
Whether the tensor is a voxel.
- Return type:
bool
- n_vertices()[source]¶
Returns the number of vertices.
- Returns:
Number of vertices.
- Return type:
int
- numel()[source]¶
Number of elements in the tensor.
- Returns:
Number of elements in the tensor.
- Return type:
int
- rearrange(pattern, **axes_length)[source]¶
Rearrange the tensor.
- Returns:
Rearranged tensor.
- Return type:
- Parameters:
pattern (str)
axes_length (dict[str, int])
- reshape(shape, is_time_series=False, is_voxel=False)[source]¶
Reshape the tensor.
- Returns:
Reshaped tensor.
- Return type:
- Parameters:
shape (Sequence[int])
is_time_series (bool)
is_voxel (bool)
- property shape: Size¶
Shape of the tensor.
- Returns:
Shape of the tensor.
- Return type:
torch.Size
- property shape_pattern: PhlowerShapePattern¶
Shape pattern of the tensor.
- Returns:
Shape pattern of the tensor.
- Return type:
PhlowerShapePattern
- slice_time(indices)[source]¶
Slice the time series tensor.
- Returns:
Sliced tensor.
- Return type:
- Parameters:
indices (int | slice | list[int] | ndarray | Tensor)
- to(device=None, non_blocking=False, dtype=None)[source]¶
Convert the tensor to a different device or data type.
- Returns:
Converted tensor.
- Return type:
- Parameters:
device (str | device | None)
non_blocking (bool)
dtype (dtype | None)
- to_vertexwise()[source]¶
Convert to vertexwise 2D tensor which has (n_vertices, -1) shape.
- Returns:
- PhlowerTensor
Vertexwise PhlowerTensor object.
- resultant_patternstr
Pattern of the resultant shape. Can be used for rearrange.
- Return type:
vertexwise_tensor