5#include <uni20/config.hpp>
53 result[
row, col] = matrix[
row, col];
70 result[
row, col] = matrix[
row, col];
121 throw std::invalid_argument(
"dense real LAPACK operation received an unknown norm selector");
124inline blas_int gelsd_iwork_size(blas_int m, blas_int n)
126 blas_int
const minmn = std::min(m, n);
134 std::size_t levels = 0;
135 for (std::size_t size =
static_cast<std::size_t
>(minmn) / 2;
size > 0;
size /= 2)
139 std::size_t
const minmn_size =
static_cast<std::size_t
>(minmn);
140 std::size_t
const required = 3 * minmn_size * levels + 11 * minmn_size;
144template <
typename Scalar>
constexpr Scalar conjugate_if_complex(Scalar
const&
value)
146 if constexpr (uni20::is_complex_v<Scalar>)
148 return std::conj(
value);
156template <
typename Scalar>
void check_same_size(std::span<Scalar const> source, std::span<Scalar> destination)
158 if (source.size() != destination.size())
160 throw std::invalid_argument(
"dense vector sizes do not agree");
164template <
typename Scalar>
bool in_selected_region(std::size_t
row, std::size_t col,
MatrixFill fill)
168 case MatrixFill::All:
170 case MatrixFill::Upper:
172 case MatrixFill::Lower:
183template <
typename Scalar>
void copy(std::span<Scalar> destination, std::span<Scalar const> source)
185 detail::check_same_size(source, destination);
186 std::ranges::copy(source, destination.begin());
193template <
typename Scalar>
void scal(
Scalar const& alpha, std::span<Scalar> vector)
206template <
typename Scalar>
void axpy(std::span<Scalar> y,
Scalar const& alpha, std::span<Scalar const> x)
208 detail::check_same_size(x, y);
209 for (std::size_t i = 0; i < x.size(); ++i)
211 y[i] += alpha * x[i];
220template <
typename Scalar>
Scalar dotu(std::span<Scalar const> x, std::span<Scalar const> y)
222 if (x.size() != y.size())
224 throw std::invalid_argument(
"dense vector sizes do not agree");
228 for (std::size_t i = 0; i < x.size(); ++i)
230 result += x[i] * y[i];
240template <uni20::Real Scalar>
Scalar dot(std::span<Scalar const> x, std::span<Scalar const> y) {
return dotu(x, y); }
247template <
typename Scalar>
Scalar dotc(std::span<Scalar const> x, std::span<Scalar const> y)
249 if (x.size() != y.size())
251 throw std::invalid_argument(
"dense vector sizes do not agree");
255 for (std::size_t i = 0; i < x.size(); ++i)
257 result += detail::conjugate_if_complex(x[i]) * y[i];
267template <
typename Scalar>
270 if (source.
rows() != destination.
rows() || source.
cols() != destination.
cols())
272 throw std::invalid_argument(
"dense matrix sizes do not agree");
279 if (detail::in_selected_region<Scalar>(
row, col,
fill))
281 destination[
row, col] = source[
row, col];
293template <
typename Scalar>
307template <
typename Scalar>
313 if (x.size() != input_size || y.size() != output_size)
315 throw std::invalid_argument(
"dense matrix-vector sizes do not agree");
320 std::fill(y.begin(), y.end(),
Scalar{});
332 Scalar const factor = alpha * x[col];
335 y[
row] += factor * matrix[
row, col];
349 entry = detail::conjugate_if_complex(entry);
353 y[col] += alpha *
sum;
363template <
typename Scalar>
366 if (x.size() !=
static_cast<std::size_t
>(matrix.
rows()) || y.size() !=
static_cast<std::size_t
>(matrix.
cols()))
368 throw std::invalid_argument(
"dense rank-one update sizes do not agree");
373 Scalar const factor = alpha * y[col];
376 matrix[
row, col] += x[
row] * factor;
387template <
typename Scalar>
390 if (x.size() !=
static_cast<std::size_t
>(matrix.
rows()) || y.size() !=
static_cast<std::size_t
>(matrix.
cols()))
392 throw std::invalid_argument(
"dense rank-one update sizes do not agree");
397 Scalar const factor = alpha * detail::conjugate_if_complex(y[col]);
400 matrix[
row, col] += x[
row] * factor;
CPU dense matrix exponential interface and dispatch adapter.
Safe conversion helpers for the configured signed BLAS integer ABI.
General-purpose owning tensor with immediate or deferred mdspan metadata.
Definition basic_tensor.hpp:109
auto rows() const noexcept
Return the matrix row count for rank-two tensors.
Definition basic_tensor.hpp:768
auto mdspan() noexcept -> mdspan_type
Resolve a writable mdspan over the owned storage.
Definition basic_tensor.hpp:609
auto cols() const noexcept
Return the matrix column count for rank-two tensors.
Definition basic_tensor.hpp:776
Concept for numeric scalar types (integer, real, or complex).
Definition scalar_concepts.hpp:81
locale_t value
Definition data_table.cpp:49
Checked LAPACK wrappers over provider-specific unchecked overloads.
Scalar math helper utilities.
Configured gateway to Uni20's mdspan implementation.
std::pair< int, int > size(std::FILE *stream)
Return the terminal size associated with a C stream.
Definition terminal.cpp:504
blas_int checked_blas_int(std::size_t value)
Convert a dense dimension to blas_int or throw on overflow.
Definition blas_int.hpp:40
Definition block_tensor_vector.hpp:23
void gerc(uni20::DenseMatrix< Scalar > &matrix, Scalar const &alpha, std::span< Scalar const > x, std::span< Scalar const > y)
Apply a conjugated dense rank-one update.
Definition dense_linalg.hpp:388
void scal(Scalar const &alpha, std::span< Scalar > vector)
Scale a local dense vector in place.
Definition dense_linalg.hpp:193
void laset(uni20::DenseMatrix< Scalar > &matrix, Scalar const &diagonal, Scalar const &off_diagonal, MatrixFill fill)
Set a selected region of a local dense matrix.
Definition dense_linalg.hpp:294
uni20::DenseMatrix< Scalar > copy_right_to_left(RightMatrix< Scalar > const &matrix)
Copy a row-major matrix into a column-major DenseMatrix.
Definition dense_linalg.hpp:63
Scalar dot(std::span< Scalar const > x, std::span< Scalar const > y)
Compute a BLAS-style real dot product.
Definition dense_linalg.hpp:240
void axpy(std::span< Scalar > y, Scalar const &alpha, std::span< Scalar const > x)
Add a scaled local dense vector to another vector.
Definition dense_linalg.hpp:206
Scalar dotc(std::span< Scalar const > x, std::span< Scalar const > y)
Compute a conjugated dot product.
Definition dense_linalg.hpp:247
MatrixTranspose
Matrix transpose mode for local dense Krylov operations.
Definition dense_linalg.hpp:78
void lacpy(uni20::DenseMatrix< Scalar > &destination, uni20::DenseMatrix< Scalar > const &source, MatrixFill fill)
Copy a selected region of a local dense matrix.
Definition dense_linalg.hpp:268
auto right_mdspan(RightMatrix< Scalar > &matrix)
Return a mutable layout-right mdspan view of a prototype right-layout matrix.
Definition dense_linalg.hpp:34
uni20::linalg::MatrixRegion MatrixFill
Matrix region selected by LAPACK-style copy and set operations.
Definition dense_linalg.hpp:92
MatrixSide
Matrix side selected by LAPACK-style multiply and solve operations.
Definition dense_linalg.hpp:86
void gemv(std::span< Scalar > y, Scalar const &alpha, uni20::DenseMatrix< Scalar > const &matrix, std::span< Scalar const > x, Scalar const &beta, MatrixTranspose transpose=MatrixTranspose::None)
Compute a dense matrix-vector product.
Definition dense_linalg.hpp:308
MatrixNorm
LAPACK-compatible dense matrix norm selector.
Definition dense_linalg.hpp:96
RightMatrix< Scalar > copy_left_to_right(uni20::DenseMatrix< Scalar > const &matrix)
Copy a column-major DenseMatrix into a row-major matrix.
Definition dense_linalg.hpp:46
void geru(uni20::DenseMatrix< Scalar > &matrix, Scalar const &alpha, std::span< Scalar const > x, std::span< Scalar const > y)
Apply a dense rank-one update.
Definition dense_linalg.hpp:364
Scalar dotu(std::span< Scalar const > x, std::span< Scalar const > y)
Compute an unconjugated dot product.
Definition dense_linalg.hpp:220
void copy(std::span< Scalar > destination, std::span< Scalar const > source)
Copy a local dense vector.
Definition dense_linalg.hpp:183
void set_matrix(BackendSelector selector, async::Async< MatrixTensor > &matrix, Diagonal &&diagonal, OffDiagonal &&off_diagonal, MatrixRegion region=MatrixRegion::All)
Schedule structured matrix initialization through an explicit selector.
Definition async/matrix_set.hpp:58
MatrixRegion
Matrix region selected by structured initialization operations.
Definition operation_tags.hpp:208
void sum(BackendSelector selector, async::Async< OutputTensor > &output, async::Async< InputTensor > const &input)
Schedule a full sum into an explicit async scalar tensor.
Definition linalg/async/reductions.hpp:309
mpreal norm(mpcomplex const &z)
Definition mpcomplex.hpp:494
void fill(BackendSelector selector, async::Async< OutputTensor > &output, Value &&value)
Fill an existing async Tensor without reading its old values.
Definition linalg/async/transform.hpp:205
std::ptrdiff_t index_type
Definition types.hpp:19
mpreal beta(mpreal const &a, mpreal const &x)
Real Beta function; positive rational/integer pairs retain exact values.
Definition mpreal_special.hpp:164
General-purpose owning tensors with runtime extents.