qr_with

Function qr_with 

Source
pub fn qr_with<T>(
    t: &TensorDynLen,
    left_inds: &[DynIndex],
    options: &QrOptions,
) -> Result<(TensorDynLen, TensorDynLen), QrError>
Expand description

Compute QR decomposition of a tensor with arbitrary rank, returning (Q, R).

This function allows per-call control of the truncation tolerance via QrOptions. If options.rtol is None, uses the global default rtol.

This function computes the thin QR decomposition, where for an unfolded matrix A (m×n), we return Q (m×k) and R (k×n) with k = min(m, n).

The input tensor can have any rank >= 2, and indices are split into left and right groups. The tensor is unfolded into a matrix by grouping left indices as rows and right indices as columns.

Truncation is performed based on R’s row norms: rows whose norm is below rtol * max_row_norm are discarded.

For the mathematical convention: [ A = Q * R ] where Q is orthogonal (or unitary for complex) and R is upper triangular.

§Arguments

  • t - Input tensor with DenseF64 or DenseC64 storage
  • left_inds - Indices to place on the left (row) side of the unfolded matrix
  • options - QR options including rtol for truncation control

§Returns

A tuple (Q, R) where:

  • Q is a tensor with indices [left_inds..., bond_index] and dimensions [left_dims..., r]
  • R is a tensor with indices [bond_index, right_inds...] and dimensions [r, right_dims...] where r is the retained rank (≤ min(m, n)) determined by rtol truncation.

§Errors

Returns QrError if:

  • The tensor rank is < 2
  • Storage is not DenseF64 or DenseC64
  • left_inds is empty or contains all indices
  • left_inds contains indices not in the tensor or duplicates
  • The QR computation fails
  • options.rtol is invalid (not finite or negative)