jet.bindings.TensorC128¶
-
class
TensorC128
¶ Bases:
pybind11_builtins.pybind11_object
Tensor represents an \(n\)-rank data structure of complex-valued data for tensor operations. We use the following conventions:
“Rank” and “order” are used interchangeably and refer to the number of tensor indices. In general, “rank” will be preferred.
“Dimension” refers to the number of elements along a tensor index.
“Shape” refers to the dimensions of a tensor; the number of dimensions is the rank of the tensor.
- Parameters
indices (Sequence[str]) – Label of each tensor index.
shape (Sequence[int]) – Dimension of each tensor index.
data (Sequence[complex]) – Row-major encoded complex data representation.
Attributes
Complex data values in row-major order.
Mapping from index labels to dimension sizes.
List of index labels.
First data value of the tensor.
List containing the dimension of each tensor index.
-
data
¶ Complex data values in row-major order.
-
dtype
¶
-
index_to_dimension_map
¶ Mapping from index labels to dimension sizes.
-
indices
¶ List of index labels.
-
scalar
¶ First data value of the tensor.
-
shape
¶ List containing the dimension of each tensor index.
Methods
add_tensor
(self, other)Adds two tensor objects with the same index sets.
conj
(self)Returns the conjugate of the given tensor object.
contract_with_tensor
(self, other)Contracts two tensor objects over the intersection of their index sets.
fill_random
(*args, **kwargs)Overloaded function.
get_value
(self, indices)Returns the tensor data value at the given \(n\)-dimensional index.
init_indices_and_shape
(self, indices, shape)Initializes the indices and shape of a tensor object.
is_scalar
(self)Reports whether the tensor is a scalar.
rename_index
(self, pos, new_label)Renames the index label at the given position.
reshape
(self, shape)Reshapes a tensor object to the given dimensions.
set_value
(self, indices, value)Sets the tensor data value at the given \(n\)-dimensional index.
slice_index
(self, index, value)Slices a tensor object index.
transpose
(*args, **kwargs)Overloaded function.
-
add_tensor
(self: jet.bindings.TensorC128, other: jet.bindings.TensorC128) → jet.bindings.TensorC128¶ Adds two tensor objects with the same index sets. The resulting tensor will have the same indices as the first argument (i.e.,
A
).- Parameters
A (Tensor) – Tensor on the LHS of the addition.
B (Tensor) – Tensor on the RHS of the addition.
- Returns
Element-wise sum of the tensors.
- Return type
Tensor
Example
Given a 2x3 tensor \(A(i,j)\) and a 2x3 tensor \(B(i,j)\), the addition of \(A\) and \(B\) is another 2x3 tensor \(C(i,j)\):
import jet A = jet.Tensor(["i", "j"], [2, 3]) B = jet.Tensor(["i", "j"], [2, 3]) A.fill_random() B.fill_random() C = A.add_tensor(B);
-
conj
(self: jet.bindings.TensorC128) → jet.bindings.TensorC128¶ Returns the conjugate of the given tensor object.
- Returns
Conjugate tensor object.
- Return type
Tensor
-
contract_with_tensor
(self: jet.bindings.TensorC128, other: jet.bindings.TensorC128) → jet.bindings.TensorC128¶ Contracts two tensor objects over the intersection of their index sets. The resulting tensor will be formed with indices given by the symmetric difference of the index sets.
- Parameters
A (Tensor) – Tensor on the LHS of the contraction.
B (Tensor) – Tensor on the RHS of the contraction.
- Returns
Contraction of the tensors.
- Return type
Tensor
Example
Given a 3x2x4 tensor \(A(i,j,k)\) and a 2x4x2 tensor \(B(j,k,l)\), the common indices are \(\{j,k\}\) and the symmetric difference of the sets is \(\{i,l\}\). The result of the contraction will be a tensor 3x2 tensor \(C(i,l)\).
import jet A = jet.Tensor(["i", "j", "k"], [3, 2, 4]) B = jet.Tensor(["j", "k", "l"], [2, 4, 2]) A.fill_random() B.fill_random() C = A.contract_with_tensor(B);
-
fill_random
(*args, **kwargs)¶ Overloaded function.
fill_random(self: jet.bindings.TensorC128) -> None
Assigns random values to the tensor data. The real and imaginary components of each datum will be independently sampled from a uniform distribution with support over \([-1, 1]\).
fill_random(self: jet.bindings.TensorC128, seed: int) -> None
Assigns random values to the tensor data. The real and imaginary components of each datum will be independently sampled from a uniform distribution with support over \([-1, 1]\). This overload enables reproducible random number generation for a given seed.
- Parameters
seed (int) – Seed to supply to the RNG engine.
-
get_value
(self: jet.bindings.TensorC128, indices: List[int]) → complex¶ Returns the tensor data value at the given \(n\)-dimensional index.
- Parameters
indices (Sequence[str]) – \(n\)-dimensional tensor data index in row-major order.
- Returns
Complex data value at the given index.
- Return type
complex
-
init_indices_and_shape
(self: jet.bindings.TensorC128, indices: List[str], shape: List[int]) → None¶ Initializes the indices and shape of a tensor object. The indices and shape must be ordered to map directly such that
indices[i]
has sizeshape[i]
.- Parameters
indices (Sequence[str]) – Label of each tensor index.
shape (Sequence[int]) – Dimension of each tensor index.
-
is_scalar
(self: jet.bindings.TensorC128) → bool¶ Reports whether the tensor is a scalar.
- Returns
True
if the tensor is of rank 0. Otherwise,False
is returned.- Return type
bool
-
rename_index
(self: jet.bindings.TensorC128, pos: int, new_label: str) → None¶ Renames the index label at the given position.
- Parameters
pos (int) – Position of the label.
new_label (str) – New label.
-
reshape
(self: jet.bindings.TensorC128, shape: List[int]) → jet.bindings.TensorC128¶ Reshapes a tensor object to the given dimensions.
- Parameters
shape (Sequence[int]) – Index dimensionality of the reshaped tensor object.
- Returns
Reshaped copy of the given tensor object.
- Return type
Tensor
-
set_value
(self: jet.bindings.TensorC128, indices: List[int], value: complex) → None¶ Sets the tensor data value at the given \(n\)-dimensional index.
- Parameters
indices (Sequence[str]) – \(n\)-dimensional tensor data index in row-major order.
value (complex) – Value to set at the data index.
-
slice_index
(self: jet.bindings.TensorC128, index: str, value: int) → jet.bindings.TensorC128¶ Slices a tensor object index. The result is a tensor object whose indices and data are a subset of the provided tensor object, sliced along the given index argument.
- Parameters
index (str) – Index label on which to slice.
value (int) – Value to slice the index on.
- Returns
Slice of the tensor object.
- Return type
Tensor
Example
Suppose that \(A(i,j)\) is a 2x3 tensor. Then,
import jet A = jet.Tensor({"i", "j"}, {2, 3}) A.fill_random() A.slice_index("i", 0) # Result is a 1x3 tensor A.slice_index("i", 1) # Result is a 1x3 tensor A.slice_index("j", 0) # Result is a 2x1 tensor A.slice_index("j", 1) # Result is a 2x1 tensor A.slice_index("j", 2) # Result is a 2x1 tensor
-
transpose
(*args, **kwargs)¶ Overloaded function.
transpose(self: jet.bindings.TensorC128, new_indices: List[str]) -> jet.bindings.TensorC128
Transposes the indices of a tensor object.
- Parameters
indices (Sequence[str]) – Desired index ordering, specified as a list of labels.
- Returns
Transposed tensor object.
- Return type
Tensor
transpose(self: jet.bindings.TensorC128, new_ordering: List[int]) -> jet.bindings.TensorC128
Transposes the indices of a tensor object.
- Parameters
ordering (Sequence[int]) – Desired index ordering, specified as a permutation.
- Returns
Transposed tensor object.
- Return type
Tensor