29template <KernelBackendSelector Backend, RankedTensorView<2> A, RankedTensorView<2> B>
35 require_precision<S>(
p);
37 ERROR_IF(a.extent(0) < a.extent(1) || a.extent(0) != b.extent(0),
38 "least squares requires m >= n and matching RHS rows");
40 LeastSquaresResult<S> result;
41 result.solution.emplace(
uninitialized, a.extent(1), b.extent(1),
p);
42 result.residual_norms.resize(b.extent(1));
46 detail::dispatch_at_precision<S>(std::forward<Backend>(backend), least_squares_op{},
p, xd, ad, bd,
47 std::span(result.residual_norms), result.info, options);
48 if (!result.info.succeeded())
50 result.solution.reset();
51 result.residual_norms.clear();
57template <KernelBackendSelector Backend, RankedTensorView<2> A, RankedTensorView<2> B>
58 requires RealOrComplex<tensor_element_t<A>> && std::same_as<tensor_element_t<A>, tensor_element_t<B>>
66template <RankedTensorView<2> A, RankedTensorView<2> B>
67 requires RealOrComplex<tensor_element_t<A>> && std::same_as<tensor_element_t<A>, tensor_element_t<B>>
76template <RankedTensorView<2> A, RankedTensorView<2> B>
77 requires RealOrComplex<tensor_element_t<A>> && std::same_as<tensor_element_t<A>, tensor_element_t<B>>
85template <
class... Args>
90 ERROR_IF(!result.info.succeeded(),
"least squares failed",
static_cast<int>(result.info.status));
91 return std::move(*result.solution);
Exact arithmetic or an explicit binary working precision.
Definition core/precision.hpp:13
General-purpose owning tensor with immediate or deferred mdspan metadata.
Definition basic_tensor.hpp:109
Concept for types that are either real or complex.
Definition scalar_concepts.hpp:87
typename make_real< T >::type make_real_t
Alias for the underlying real-valued type of T.
Definition scalar_traits.hpp:168
void require_options(LeastSquaresOptions< R > const &options)
Definition least_squares_common.hpp:26
Definition linalg/async.hpp:28
constexpr auto select_backend_for(Operation const &operation)
Resolve the immutable backend selector for Tensor operand types.
Definition backend_selector.hpp:201
auto least_squares_with_info(Backend &&backend, A const &a, B const &b, Precision p, LeastSquaresOptions< make_real_t< tensor_element_t< A > > > const &options={})
Minimize each column's Euclidean residual for m-by-n A with m >= n.
Definition ops/least_squares.hpp:31
auto least_squares(Args &&... args)
Return a preserving least-squares solution; numerical failure uses the ordinary terminal error policy...
Definition ops/least_squares.hpp:87
Definition data_table.cpp:8
constexpr uninitialized_t uninitialized
Explicit allocation tag for overwrite outputs and scratch space.
Definition common/initialization.hpp:22
constexpr Precision common_default_precision(A const &a, B const &b)
Select a binary operation's default without inspecting element precisions.
Definition tensor/precision.hpp:43
constexpr decltype(auto) mdspec_of(Tensor &tensor) noexcept(noexcept(tensor.mdspec()))
Return a tensor's immediate or descriptor-backed multidimensional metadata.
Definition tensor/concepts.hpp:50
std::remove_cv_t< typename tensor_mdspec_t< T >::element_type > tensor_element_t
Scalar value type exposed by a tensor-level object.
Definition tensor/concepts.hpp:126
Completed numerical attempt; success does not certify rank or conditioning.
Definition least_squares_info.hpp:26
Full-rank QR rejection policy, independent of any physical convergence criterion.
Definition least_squares_info.hpp:37
Preserving least-squares result; solution and residuals are published only on success.
Definition ops/least_squares.hpp:15
std::vector< make_real_t< S > > residual_norms
Recomputed Euclidean residual norm per RHS, in working precision; not an error bound.
Definition ops/least_squares.hpp:19
LeastSquaresInfo info
Definition ops/least_squares.hpp:16
std::optional< DenseMatrix< S > > solution
Definition ops/least_squares.hpp:17
#define ERROR_IF(cond,...)
Definition trace.hpp:389