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.

is_global(n_batch)

Returns True if the batched tensor is from global ones.

n_vertices()

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[, keep_time_series])

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()

to_tensor()

Convert to torch.Tensor.

to_vertexwise()

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

Device of the tensor.

dimension

Physical dimension tensor.

dtype

Data type of the tensor.

has_dimension

Whether the tensor has a physical dimension.

is_sparse

Whether the tensor is a sparse tensor.

is_time_series

Whether the tensor is a time series.

is_voxel

Whether the tensor is a voxel.

shape

Shape of the tensor.

shape_pattern

Shape pattern of the tensor.

time_series_length

Length of the time series.

as_pattern(pattern)[source]

Convert the tensor to a pattern.

Returns:

Patterned tensor.

Return type:

PhlowerTensor

Parameters:

pattern (str)

backward()[source]

Backward the tensor.

Return type:

None

clone()[source]

Clone the tensor.

Returns:

Cloned tensor.

Return type:

PhlowerTensor

coalesce()[source]

Coalesce the tensor.

Returns:

Coalesced tensor.

Return type:

torch.Tensor

detach()[source]

Detach the tensor.

Returns:

Detached tensor.

Return type:

PhlowerTensor

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

is_global(n_batch)[source]

Returns True if the batched tensor is from global ones.

Parameters:

n_batch (int) – int The number of batches.

Returns:

True if the batched tensor is from global ones.

Return type:

bool

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

rank()[source]

Returns the tensor rank.

Returns:

Tensor rank.

Return type:

int

rearrange(pattern, **axes_length)[source]

Rearrange the tensor.

Returns:

Rearranged tensor.

Return type:

PhlowerTensor

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:

PhlowerTensor

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

size()[source]

Size of the tensor.

Returns:

Size of the tensor.

Return type:

torch.Size

slice_time(indices, keep_time_series=True)[source]

Slice the time series tensor.

Returns:

Sliced tensor.

Return type:

PhlowerTensor

Parameters:
  • indices (int | slice | list[int] | ndarray | Tensor)

  • keep_time_series (bool)

property time_series_length: int

Length of the time series.

Returns:

Length of the time series.

Return type:

int | None

to(device=None, non_blocking=False, dtype=None)[source]

Convert the tensor to a different device or data type.

Returns:

Converted tensor.

Return type:

PhlowerTensor

Parameters:
  • device (str | device | None)

  • non_blocking (bool)

  • dtype (dtype | None)

to_numpy()[source]

Convert to numpy.ndarray.

Returns:

Numpy array.

Return type:

numpy.ndarray

to_tensor()[source]

Convert to torch.Tensor.

Returns:

Tensor.

Return type:

torch.Tensor

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

transpose(dim0, dim1)[source]

Transpose the tensor.

Returns:

Transposed tensor.

Return type:

PhlowerTensor

Parameters:
  • dim0 (int)

  • dim1 (int)

values()[source]

Returns the values of the tensor.

Returns:

Values of the tensor.

Return type:

torch.Tensor