pub fn bicgstab<T, F>(
apply_a: F,
b: &T,
x0: &T,
options: &BiCgStabOptions,
) -> Result<BiCgStabResult<T>, KrylovError>Expand description
Solve A x = b with matrix-free BiCGSTAB.
§Arguments
apply_a- Fixed linear operator preserving the vector space. It may be nonsymmetric or complex non-Hermitian.b- Right-hand side in the same vector space asx0.x0- Initial guess. A zero-norm RHS returns the zero vector, the exact solution, after checking thatx0andbshare a vector space.options- Cycle budget and tolerances; start with the defaults for double precision.
§Returns
The approximate solution, consumed cycles, absolute true residual, and
convergence flag. True residuals are checked at intermediate and full-step
convergence and at budget exhaustion. Residual replacement restarts the
recurrence within the original budget.
Working vectors and operator images are normalized by powers of two before
inner products. Intermediate arithmetic remains in TensorVectorSpace and
AnyScalar; norm, range, and stopping decisions cross scalar control-flow boundaries.
This solver does not promise a differentiable solve. The caller’s vector
space must provide a norm preserving the required dynamic range.
BiCGSTAB may break down even for an invertible operator. In that case,
super::gmres provides an alternative with different memory requirements.
§Errors
Returns KrylovError::InvalidOptions for invalid tolerances or an
overflowing stopping threshold, KrylovError::NumericalBreakdown for
unusable recurrence quantities, and KrylovError::Operation for invalid
or incompatible vector spaces, callback failures, or tensor errors.
Underlying operation errors retain their source chains.
§Examples
use tensor4all_core::{contract, krylov::{bicgstab, BiCgStabOptions}, DynIndex, IdxTensor, TensorIndex};
let i = DynIndex::new_dyn(2);
let input = i.prime();
// Column-major [[1, 1], [0, 2]], with solution [-0.5, 0.5].
let a = IdxTensor::from_dense(vec![i.clone(), input.clone()], vec![1.0_f64, 0.0, 1.0, 2.0])?;
let b = IdxTensor::from_dense(vec![i.clone()], vec![0.0_f64, 1.0])?;
let x0 = IdxTensor::zeros::<f64>(vec![i.clone()])?;
let result = bicgstab(
|x: &IdxTensor| Ok(contract(&[&a, &x.replaceind(&i, &input)?])?),
&b, &x0, &BiCgStabOptions::default(),
)?;
assert!(result.converged);
assert_eq!(result.solution.to_vec::<f64>()?, vec![-0.5, 0.5]);
assert_eq!(result.residual_norm, 0.0);