Skip to content

filter_blocks

Extract subset of tensor blocks and prune unused sectors.

filter_blocks

filter_blocks(
    tensor: Tensor, block_indices: Union[int, Sequence[int]]
) -> Tensor

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:

>>> from nicole import filter_blocks, Tensor
>>> # Assuming t has 5 blocks numbered 1-5 in display
>>> t_sub = filter_blocks(t, [1, 3, 5])  # Extract blocks 1, 3, and 5
>>> t_single = filter_blocks(t, 2)  # Extract just block 2

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

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.