differential_geometry.dense_utils.dense_tensor_product#

differential_geometry.dense_utils.dense_tensor_product(tensor_a: ndarray, type_a: tuple[int, int], tensor_b: ndarray, type_b: tuple[int, int]) ndarray[source]#

Compute the tensor product of two tensor fields with specified (p, q) types, ensuring that the result has contravariant indices first and covariant indices last.

Parameters:
  • tensor_a (numpy.ndarray) – First tensor field of shape (…, i₁, …, i_p, j₁, …, j_q).

  • type_a (tuple[int, int]) – Tuple (p, q) specifying number of contravariant and covariant indices of tensor_a.

  • tensor_b (numpy.ndarray) – Second tensor field of shape (…, k₁, …, k_r, l₁, …, l_t).

  • type_b (tuple[int, int]) – Tuple (r, t) specifying number of contravariant and covariant indices of tensor_b.

Returns:

The tensor product with type (p + r, q + t), shape (…, i₁, …, i_p, k₁, …, k_r, j₁, …, j_q, l₁, …, l_t).

Return type:

numpy.ndarray

Raises:

ValueError – If tensor shapes are incompatible or types are invalid.

Examples

>>> import numpy as np
>>> A = np.random.rand(4, 3)     # (1, 0) vector
>>> B = np.random.rand(4, 3)     # (0, 1) covector
>>> tensor_product(A, (1, 0), B, (0, 1)).shape
(4, 3, 3)