phlower.PhlowerDimensionTensor

class phlower.PhlowerDimensionTensor(tensor=None, dtype=torch.float32)[source]

Bases: object

PhlowerDimensionTensor is a tensor that represents the physical dimensions

Examples

>>> dimension_tensor = PhlowerDimensionTensor(
...     values={"M": 1.0, "L": 1.0, "T": -2.0}
... )

Methods

__init__([tensor, dtype])

clone()

detach()

from_list(values[, dtype, device])

Parse from list object

to([device, non_blocking, dtype])

Convert to different device or data type

to_dict()

Convert to dict

to_physics_dimension()

Convert to PhysicalDimensions object

Attributes

device

dtype

is_dimensionless

Return True if the tensor is dimensionless.

Parameters:
  • tensor (torch.Tensor | None)

  • dtype (torch.dtype)

classmethod from_list(values, dtype=torch.float32, device=None)[source]

Parse from list object

Parameters:
  • values (list[float] | tuple[float]) – list or tuple if length of values is not equal to the number of registered dimension type, raise ValueError.

  • dtype (dtype)

  • device (str | device | None)

Returns:

tensor object

Return type:

PhlowerDimensionTensor

property is_dimensionless: bool

Return True if the tensor is dimensionless.

Returns:

True if the tensor is dimensionless.

Return type:

bool

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

Convert to different device or data type

Parameters:
  • device (str | torch.device, optional) – device. Defaults to None.

  • non_blocking (bool, optional) – non-blocking. Defaults to False.

  • dtype (torch.dtype, optional) – data type. Defaults to None.

Return type:

PhlowerDimensionTensor

to_dict()[source]

Convert to dict

Returns:

Dict

Return type:

dict[str, float]

to_physics_dimension()[source]

Convert to PhysicalDimensions object

Returns:

PhysicalDimensions object

Return type:

PhysicalDimensions