Conversion: Array/Tensor#

This module contains function for conversions of PyTorch tensors. This includes, for example, reshaping. Conversion into tensors from other data types (integer, float, etc.) is not provided by this module.

tad_mctc.convert.tensor.reshape_fortran(x, shape)[source]#

Implements Fortran’s reshape function (column-major).

Parameters:
  • x (Tensor) – Input tensor.

  • shape (Size) – Output size to which x is reshaped.

Returns:

Reshaped tensor of size shape.

Return type:

Tensor

tad_mctc.convert.tensor.symmetrize(x, force=False)[source]#

Symmetrize a tensor after checking if it is symmetric within a threshold.

Parameters:
  • x (Tensor) – Tensor to check and symmetrize.

  • force (bool) – Whether symmetry should be forced. This allows switching between actual symmetrizing and only cleaning up numerical noise. Defaults to False.

Returns:

Symmetrized tensor.

Return type:

Tensor

Raises:

RuntimeError – If the tensor is not symmetric within the threshold.

tad_mctc.convert.tensor.symmetrizef(x, *, force=True)#

Force symmetrization of a tensor.