pub trait LinalgBackend: BackendSession {
Show 24 methods
// Required methods
fn cholesky(&mut self, input: &Tensor) -> Result<Tensor>;
fn triangular_solve(
&mut self,
a: &Tensor,
b: &Tensor,
left_side: bool,
lower: bool,
transpose_a: bool,
unit_diagonal: bool,
) -> Result<Tensor>;
fn lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>;
fn full_piv_lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>;
fn full_piv_lu_solve(
&mut self,
a: &Tensor,
b: &Tensor,
transpose_a: bool,
) -> Result<Tensor>;
fn svd(&mut self, input: &Tensor) -> Result<Vec<Tensor>>;
fn qr(&mut self, input: &Tensor) -> Result<Vec<Tensor>>;
fn eigh(&mut self, input: &Tensor) -> Result<Vec<Tensor>>;
fn eig(&mut self, input: &Tensor) -> Result<Vec<Tensor>>;
fn solve(&mut self, a: &Tensor, b: &Tensor) -> Result<Tensor>;
// Provided methods
fn triangular_solve_read(
&mut self,
_a: TensorRead<'_>,
_b: TensorRead<'_>,
_left_side: bool,
_lower: bool,
_transpose_a: bool,
_unit_diagonal: bool,
) -> Result<Tensor> { ... }
fn svd_with_options(
&mut self,
input: &Tensor,
options: SvdOptions,
) -> Result<Vec<Tensor>> { ... }
fn svd_full(&mut self, _input: &Tensor) -> Result<Vec<Tensor>> { ... }
fn svd_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>> { ... }
fn qr_with_options(
&mut self,
input: &Tensor,
options: QrOptions,
) -> Result<Vec<Tensor>> { ... }
fn qr_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>> { ... }
fn eigh_with_options(
&mut self,
input: &Tensor,
options: EighOptions,
) -> Result<Vec<Tensor>> { ... }
fn eigh_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>> { ... }
fn cholesky_read(&mut self, _input: TensorRead<'_>) -> Result<Tensor> { ... }
fn lu_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>> { ... }
fn full_piv_lu_read(
&mut self,
_input: TensorRead<'_>,
) -> Result<Vec<Tensor>> { ... }
fn eig_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>> { ... }
fn solve_read(
&mut self,
_a: TensorRead<'_>,
_b: TensorRead<'_>,
) -> Result<Tensor> { ... }
fn solve_read_into(
&mut self,
a: TensorRead<'_>,
b: TensorRead<'_>,
out: TensorWrite<'_>,
) -> Result<()> { ... }
}Expand description
Backend surface required by the linalg extension runtime.
§Examples
use tenferro_cpu::{with_cpu_exec_session, CpuBackend, CpuExecSession};
use tenferro_linalg::backend::LinalgBackend;
use tenferro_tensor::BackendSessionHost;
fn assert_linalg_backend<B: LinalgBackend>() {}
assert_linalg_backend::<CpuExecSession<'static>>();
let mut host = CpuBackend::new();
host.with_backend_session(|session| {
with_cpu_exec_session(session, |_backend| ())
.expect("CpuBackend must expose a CpuExecSession");
});Required Methods§
Sourcefn cholesky(&mut self, input: &Tensor) -> Result<Tensor>
fn cholesky(&mut self, input: &Tensor) -> Result<Tensor>
Compute a Cholesky factorization.
§Errors
Returns Error::Validation for non-matrix, non-square, or unsupported
input dtypes; Error::Extension with ErrorKind::NumericalFailure
when the matrix is not positive definite; or a typed backend source
when the provider cannot execute the factorization.
Sourcefn triangular_solve(
&mut self,
a: &Tensor,
b: &Tensor,
left_side: bool,
lower: bool,
transpose_a: bool,
unit_diagonal: bool,
) -> Result<Tensor>
fn triangular_solve( &mut self, a: &Tensor, b: &Tensor, left_side: bool, lower: bool, transpose_a: bool, unit_diagonal: bool, ) -> Result<Tensor>
Solve a triangular linear system with explicit side, triangle, transpose, and unit-diagonal flags.
§Errors
Returns Error::Validation for incompatible matrix/rhs shapes, rank,
or dtype; Error::Extension with ErrorKind::NumericalFailure for a
singular or zero-diagonal system; or a typed backend source for a
provider failure.
Sourcefn lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
fn lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
Compute public LU outputs (P, L, U, parity).
§Errors
Returns Error::Validation when the input is not a supported matrix or
dtype, and Error::Extension or a typed backend source when LU
execution or pivot storage fails.
Sourcefn full_piv_lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
fn full_piv_lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
Compute complete-pivot LU outputs (P, L, U, Q, parity).
The reconstruction convention is A = P^T * L * U * Q, equivalently
P * A * Q^T = L * U. parity is a scalar real tensor containing
+1 or -1: F32 for F32/C32 inputs and F64 for F64/C64
inputs.
§Errors
Returns Error::Validation for an invalid rank, square-shape
requirement, or dtype, and Error::Extension or a typed backend source
when complete-pivot factorization cannot be executed.
Sourcefn full_piv_lu_solve(
&mut self,
a: &Tensor,
b: &Tensor,
transpose_a: bool,
) -> Result<Tensor>
fn full_piv_lu_solve( &mut self, a: &Tensor, b: &Tensor, transpose_a: bool, ) -> Result<Tensor>
Solve a linear system through the complete-pivot LU path.
With transpose_a = false, this solves A * x = b. With
transpose_a = true, this solves A^T * x = b.
§Errors
Returns Error::Validation for incompatible coefficient/rhs shapes or
dtypes, Error::Extension with ErrorKind::NumericalFailure for a
singular system, or a typed backend source for provider failure.
Sourcefn svd(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
fn svd(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
Compute public SVD outputs (U, S, Vt).
§Errors
Returns Error::Validation for an unsupported rank or dtype and a
typed Error::Extension or backend source when the solver fails.
Sourcefn qr(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
fn qr(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
Compute public QR outputs (Q, R).
QR is thin: for an m x n input, Q has shape m x min(m, n) and
R has shape min(m, n) x n.
§Errors
Returns Error::Validation for an unsupported rank, shape, or dtype,
and a typed Error::Extension or backend source when QR execution
fails.
Sourcefn eigh(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
fn eigh(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
Compute public Hermitian eigendecomposition outputs (values, vectors).
The returned vector order is [values, vectors], where values has
shape [n] and vectors has shape [n, n].
§Errors
Returns Error::Validation for a non-square or unsupported-dtype input
and a typed Error::Extension or backend source when eigendecomposition
fails.
Sourcefn eig(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
fn eig(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
Compute public general eigendecomposition outputs (values, vectors).
§Errors
Returns Error::Validation for a non-square, rank, or dtype mismatch,
and a typed Error::Extension or backend source when the eigensolver
fails.
Sourcefn solve(&mut self, a: &Tensor, b: &Tensor) -> Result<Tensor>
fn solve(&mut self, a: &Tensor, b: &Tensor) -> Result<Tensor>
Solve a dense linear system.
§Errors
Returns Error::Validation for incompatible matrix/rhs shapes, rank,
or dtype; Error::Extension with ErrorKind::NumericalFailure for a
singular system; or a typed backend source for provider failure.
Provided Methods§
Sourcefn triangular_solve_read(
&mut self,
_a: TensorRead<'_>,
_b: TensorRead<'_>,
_left_side: bool,
_lower: bool,
_transpose_a: bool,
_unit_diagonal: bool,
) -> Result<Tensor>
fn triangular_solve_read( &mut self, _a: TensorRead<'_>, _b: TensorRead<'_>, _left_side: bool, _lower: bool, _transpose_a: bool, _unit_diagonal: bool, ) -> Result<Tensor>
Solve a triangular linear system from tensor read targets.
Backends may canonicalize the inputs inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_linalg::LinalgBackend;
use tenferro_tensor::{BackendSessionHost, Tensor, TensorRead};
let a = Tensor::from_vec_col_major(vec![2, 2], vec![2.0_f64, 0.0, 1.0, 3.0])?;
let b = Tensor::from_vec_col_major(vec![2, 1], vec![4.0_f64, 9.0])?;
let mut host = CpuBackend::new();
let x = host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.triangular_solve_read(
TensorRead::from_tensor(&a),
TensorRead::from_tensor(&b),
true,
false,
false,
false,
)
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
let Tensor::F64(x) = x else { unreachable!("F64 inputs return F64 output") };
assert_eq!(x.host_data()?, &[0.5, 3.0]);§Errors
The default implementation returns Error::Unsupported because the
backend does not accept tensor read targets. Implementations may return
Error::Validation for incompatible shapes or dtypes,
Error::RuntimeState for invalid placement, Error::Extension for a
singular system, or a typed backend-source error.
Sourcefn svd_with_options(
&mut self,
input: &Tensor,
options: SvdOptions,
) -> Result<Vec<Tensor>>
fn svd_with_options( &mut self, input: &Tensor, options: SvdOptions, ) -> Result<Vec<Tensor>>
Compute public SVD outputs (U, S, Vt) with explicit options.
derivative_eps is validated for API consistency, but concrete backend
execution does not perform AD. gauge controls optional singular-vector
post-processing.
§Examples
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_linalg::{LinalgBackend, SvdGauge, SvdOptions};
use tenferro_tensor::{BackendSessionHost, Tensor};
let input = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 0.0, 0.0, 2.0])?;
let mut host = CpuBackend::new();
let outputs = host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.svd_with_options(
&input,
SvdOptions::default().gauge(SvdGauge::CanonicalPivot),
)
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
assert_eq!(outputs[1].shape(), &[2]);§Errors
Returns tenferro_tensor::Error::Validation containing
tenferro_tensor::ValidationError::InvalidArgument when
derivative_eps is non-finite or non-positive, or when canonical gauge
output metadata is malformed. It can return
tenferro_tensor::Error::Validation with
tenferro_tensor::ValidationError::RankMismatch,
tenferro_tensor::ValidationError::ShapeMismatch, or
tenferro_tensor::ValidationError::DTypeMismatch for the input
or generated outputs, tenferro_tensor::Error::Extension with the
typed tenferro_linalg::Error::UnsupportedDType or
NonConvergence source, tenferro_tensor::Error::BackendSource for
provider calls, and tenferro_tensor::Error::RuntimeState for
placement failures. A CPU provider that was not compiled is reported
as tenferro_tensor::ValidationError::InvalidArgument on the
provider configuration.
Sourcefn svd_full(&mut self, _input: &Tensor) -> Result<Vec<Tensor>>
fn svd_full(&mut self, _input: &Tensor) -> Result<Vec<Tensor>>
Compute public full-matrices SVD outputs (U, S, Vt) with U shaped
m x m and Vt shaped n x n, so the trailing Vt rows span the
input’s right nullspace.
§Errors
The default implementation returns Error::Unsupported: a backend that
does not implement the full variant reports it explicitly rather than
silently falling back to the thin decomposition. Implementing backends
may additionally return Error::Validation for an unsupported rank or
dtype and a typed backend source when the solver fails.
Sourcefn svd_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>>
fn svd_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>>
Compute a singular value decomposition from a tensor read target.
Backends may canonicalize the input inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_tensor::{BackendSessionHost, TensorRead, TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![1.0, 0.0, 0.0, 2.0],
)?;
let mut host = CpuBackend::new();
let outputs = host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.svd_read(TensorRead::from_view(TensorView::F64(input.as_view())))
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
assert_eq!(outputs[1].shape(), &[2]);§Errors
The default implementation returns Error::Unsupported because the
backend does not accept tensor read targets; an implementation may instead
return validation or typed backend-source errors after canonicalizing
the view.
Sourcefn qr_with_options(
&mut self,
input: &Tensor,
options: QrOptions,
) -> Result<Vec<Tensor>>
fn qr_with_options( &mut self, input: &Tensor, options: QrOptions, ) -> Result<Vec<Tensor>>
Compute public QR outputs (Q, R) with explicit options.
gauge controls optional sign or phase post-processing.
§Examples
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_linalg::{LinalgBackend, QrGauge, QrOptions};
use tenferro_tensor::{BackendSessionHost, Tensor};
let input = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 0.0, 0.0, 2.0])?;
let mut host = CpuBackend::new();
let outputs = host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.qr_with_options(
&input,
QrOptions::default().gauge(QrGauge::PositiveDiagonal),
)
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
assert_eq!(outputs[0].shape(), &[2, 2]);§Errors
Returns tenferro_tensor::Error::Validation containing
tenferro_tensor::ValidationError::RankMismatch or
tenferro_tensor::ValidationError::ShapeMismatch for an invalid
matrix input, or tenferro_tensor::ValidationError::InvalidArgument
for malformed gauge output metadata, checked size arithmetic, or an
unavailable compiled provider. A mismatched generated Q/R dtype is reported as
tenferro_tensor::ValidationError::DTypeMismatch. Provider
unsupported dtype or numerical rejection is
tenferro_tensor::Error::Extension with a typed linalg source, while
provider failures use tenferro_tensor::Error::BackendSource and a
backend-resident input uses tenferro_tensor::Error::RuntimeState.
Sourcefn qr_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>>
fn qr_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>>
Compute public QR outputs (Q, R) from a tensor read target.
Backends may canonicalize the input inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_tensor::{BackendSessionHost, TensorRead, TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![1.0, 0.0, 0.0, 2.0],
)?;
let mut host = CpuBackend::new();
let outputs = host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.qr_read(TensorRead::from_view(TensorView::F64(input.as_view())))
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
assert_eq!(outputs[0].shape(), &[2, 2]);
assert_eq!(outputs[1].shape(), &[2, 2]);§Errors
The default implementation returns Error::Unsupported because the
backend does not accept tensor read targets; implementations may return
validation or typed backend-source errors.
Sourcefn eigh_with_options(
&mut self,
input: &Tensor,
options: EighOptions,
) -> Result<Vec<Tensor>>
fn eigh_with_options( &mut self, input: &Tensor, options: EighOptions, ) -> Result<Vec<Tensor>>
Compute public Hermitian eigendecomposition outputs with explicit options.
derivative_eps is validated for API consistency, but concrete backend
execution does not perform AD. gauge controls optional eigenvector
post-processing.
§Examples
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_linalg::{EighGauge, EighOptions, LinalgBackend};
use tenferro_tensor::{BackendSessionHost, Tensor};
let input = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 0.0, 0.0, 2.0])?;
let mut host = CpuBackend::new();
let outputs = host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.eigh_with_options(
&input,
EighOptions::default()
.gauge(EighGauge::CanonicalPivot)
.derivative_eps(1.0e-10),
)
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
assert_eq!(outputs[0].shape(), &[2]);§Errors
Returns tenferro_tensor::Error::Validation containing
tenferro_tensor::ValidationError::InvalidArgument when
derivative_eps is non-finite or non-positive, when canonical gauge
output metadata is malformed, or when checked output-size arithmetic
overflows. It can return tenferro_tensor::Error::Validation with
tenferro_tensor::ValidationError::RankMismatch or
tenferro_tensor::ValidationError::ShapeMismatch for the
matrix input, or tenferro_tensor::ValidationError::DTypeMismatch
for generated outputs. It can also return
tenferro_tensor::Error::Extension with typed
tenferro_linalg::Error::UnsupportedDType or NonConvergence, and
tenferro_tensor::Error::BackendSource or
tenferro_tensor::Error::RuntimeState for provider and placement
failures.
Sourcefn eigh_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>>
fn eigh_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>>
Compute public Hermitian eigendecomposition outputs from a tensor read target.
Backends may canonicalize the input inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_tensor::{BackendSessionHost, TensorRead, TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![1.0, 0.0, 0.0, 2.0],
)?;
let mut host = CpuBackend::new();
let outputs = host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.eigh_read(TensorRead::from_view(TensorView::F64(input.as_view())))
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
assert_eq!(outputs[0].shape(), &[2]);
assert_eq!(outputs[1].shape(), &[2, 2]);§Errors
The default implementation returns Error::Unsupported because the
backend does not accept tensor read targets; implementations may return
validation or typed backend-source errors.
Sourcefn cholesky_read(&mut self, _input: TensorRead<'_>) -> Result<Tensor>
fn cholesky_read(&mut self, _input: TensorRead<'_>) -> Result<Tensor>
Compute Cholesky factorization from a tensor read target.
Backends may canonicalize the input inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_tensor::{BackendSessionHost, TensorRead, TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![4.0, 2.0, 2.0, 3.0],
)?;
let mut host = CpuBackend::new();
let output = host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.cholesky_read(TensorRead::from_view(TensorView::F64(input.as_view())))
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
assert_eq!(output.shape(), &[2, 2]);§Errors
The default implementation returns Error::Unsupported because the
backend does not accept tensor read targets; implementations may return
validation or typed backend-source errors.
Sourcefn lu_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>>
fn lu_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>>
Compute public LU outputs from a tensor read target.
Backends may canonicalize the input inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_tensor::{BackendSessionHost, TensorRead, TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![1.0, 3.0, 2.0, 4.0],
)?;
let mut host = CpuBackend::new();
let outputs = host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.lu_read(TensorRead::from_view(TensorView::F64(input.as_view())))
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
assert_eq!(outputs.len(), 4);§Errors
The default implementation returns Error::Unsupported because the
backend does not accept tensor read targets; implementations may return
validation or typed backend-source errors.
Sourcefn full_piv_lu_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>>
fn full_piv_lu_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>>
Compute public full-pivoting LU outputs from a tensor read target.
Backends may canonicalize the input inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_tensor::{BackendSessionHost, TensorRead, TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![1.0, 3.0, 2.0, 4.0],
)?;
let mut host = CpuBackend::new();
let outputs = host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.full_piv_lu_read(TensorRead::from_view(TensorView::F64(input.as_view())))
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
assert_eq!(outputs.len(), 5);§Errors
The default implementation returns Error::Unsupported because the
backend does not accept tensor read targets; implementations may return
validation or typed backend-source errors.
Sourcefn eig_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>>
fn eig_read(&mut self, _input: TensorRead<'_>) -> Result<Vec<Tensor>>
Compute general eigendecomposition outputs from a tensor read target.
Backends may canonicalize the input inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_tensor::{BackendSessionHost, TensorRead, TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![2.0, 0.0, 0.0, 3.0],
)?;
let mut host = CpuBackend::new();
let outputs = host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.eig_read(TensorRead::from_view(TensorView::F64(input.as_view())))
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
assert_eq!(outputs.len(), 2);§Errors
The default implementation returns Error::Unsupported because the
backend does not accept tensor read targets; implementations may return
validation or typed backend-source errors.
Sourcefn solve_read(
&mut self,
_a: TensorRead<'_>,
_b: TensorRead<'_>,
) -> Result<Tensor>
fn solve_read( &mut self, _a: TensorRead<'_>, _b: TensorRead<'_>, ) -> Result<Tensor>
Solve a linear system from tensor read targets.
Backends may canonicalize the inputs inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_linalg::LinalgBackend;
use tenferro_tensor::{BackendSessionHost, Tensor, TensorRead};
let a = Tensor::from_vec_col_major(vec![2, 2], vec![2.0_f64, 0.0, 0.0, 3.0])?;
let b = Tensor::from_vec_col_major(vec![2, 1], vec![4.0_f64, 9.0])?;
let mut host = CpuBackend::new();
let x = host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.solve_read(
TensorRead::from_tensor(&a),
TensorRead::from_tensor(&b),
)
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
let Tensor::F64(x) = x else { unreachable!("F64 inputs return F64 output") };
assert_eq!(x.host_data()?, &[2.0, 3.0]);§Errors
The default implementation returns Error::Unsupported because the
backend does not accept tensor read targets. Implementations may return
Error::Validation for incompatible shapes or dtypes,
Error::RuntimeState for invalid placement, Error::Extension for a
singular system, or a typed backend-source error.
Sourcefn solve_read_into(
&mut self,
a: TensorRead<'_>,
b: TensorRead<'_>,
out: TensorWrite<'_>,
) -> Result<()>
fn solve_read_into( &mut self, a: TensorRead<'_>, b: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<()>
Solve into a caller-owned destination.
The default preserves the ordinary read path and copies its result into
out. Backends with a native destination path may override this method,
but must validate the destination before the first write and preserve
the same shape, dtype, placement, aliasing, and error contracts.
§Errors
Returns tenferro_tensor_core::ShapeMismatch or
tenferro_tensor_core::ValidationError::DTypeMismatch for incompatible
destination metadata, tenferro_tensor_core::ValidationError::InvalidArgument
for aliasing or placement violations, Error::Unsupported when the
provider is unavailable, and Error::Singular for a singular system.
§Examples
use tenferro_cpu::{with_cpu_exec_session, CpuBackend};
use tenferro_linalg::LinalgBackend;
use tenferro_tensor::{BackendSessionHost, Tensor, TensorRead, TensorWrite};
let a = Tensor::from_vec_col_major(vec![2, 2], vec![2.0_f64, 0.0, 0.0, 4.0])?;
let b = Tensor::from_vec_col_major(vec![2, 1], vec![4.0_f64, 8.0])?;
let mut out = Tensor::from_vec_col_major(vec![2, 1], vec![0.0_f64; 2])?;
let mut host = CpuBackend::new();
host.with_backend_session(|session| {
with_cpu_exec_session(session, |backend| {
backend.solve_read_into(
TensorRead::from_tensor(&a),
TensorRead::from_tensor(&b),
TensorWrite::from_tensor(&mut out),
)
})
.expect("CpuBackend must expose a CpuExecSession")
})?;
assert_eq!(out.as_slice::<f64>()?, &[2.0, 2.0]);