filter_blocks¶
Extract subset of tensor blocks and prune unused sectors.
filter_blocks
¶
Return a new tensor containing only the specified blocks with pruned sectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
Tensor
|
The input tensor to extract blocks from. |
required |
block_indices
|
Union[int, Sequence[int]]
|
Block index or sequence of block indices (1-indexed, matching display numbering) specifying which blocks to include in the new tensor. Can be a single integer or a sequence of integers. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
A new tensor instance containing only the specified blocks with unused sectors removed from the indices. Other attributes (itags, dtype, label) are preserved. For SU(2) tensors, the corresponding intertwiner (intw) data is also extracted. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If any block index is out of range. |
Examples:
Description¶
Returns a new tensor containing only specified blocks, with unused sectors automatically removed from the indices. Block indices are 1-based to match display output from print(tensor).
Useful for:
- Extracting blocks by quantum numbers
- Filtering to specific charge sectors
- Debugging tensor structure
- Creating tensors with reduced block structure
See Also¶
- Tensor: Main tensor class
- Examples: Manipulation
Notes¶
Block indices are 1-based. Use Tensor.key(i) to get the charge key for block i.
The returned tensor will have indices with only the sectors that appear in the selected blocks. This ensures the tensor structure remains consistent and minimal.