Files
cppdraft_translate/cppdraft/linalg/algs/blas2/gemv.md
2025-10-25 03:02:53 +03:00

5.5 KiB
Raw Blame History

[linalg.algs.blas2.gemv]

29 Numerics library [numerics]

29.9 Basic linear algebra algorithms [linalg]

29.9.14 BLAS 2 algorithms [linalg.algs.blas2]

29.9.14.1 General matrix-vector product [linalg.algs.blas2.gemv]

1

#

[Note 1:

These functions correspond to the BLAS function xGEMV.

— end note]

2

#

The following elements apply to all functions in [linalg.algs.blas2.gemv].

3

#

Mandates:

possibly-multipliable<decltype(A), decltype(x), decltype(y)>() is true, and

possibly-addable<decltype(x), decltype(y), decltype(z)>() is true for those overloads that take a z parameter.

4

#

Preconditions:

multipliable(A,x,y) is true, and

addable(x,y,z) is true for those overloads that take a z parameter.

5

#

Complexity: O(x.extent(0)×A.extent(1)).

🔗

template<[in-matrix](linalg.helpers.concepts#concept:in-matrix "29.9.7.5Argument concepts[linalg.helpers.concepts]") InMat, [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") InVec, [out-vector](linalg.helpers.concepts#concept:out-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") OutVec> void matrix_vector_product(InMat A, InVec x, OutVec y); template<class ExecutionPolicy, [in-matrix](linalg.helpers.concepts#concept:in-matrix "29.9.7.5Argument concepts[linalg.helpers.concepts]") InMat, [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") InVec, [out-vector](linalg.helpers.concepts#concept:out-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") OutVec> void matrix_vector_product(ExecutionPolicy&& exec, InMat A, InVec x, OutVec y);

6

#

These functions perform an overwriting matrix-vector product.

7

#

Effects: Computes y=Ax.

[Example 1: constexpr size_t num_rows = 5;constexpr size_t num_cols = 6;

// y = 3.0 * A * xvoid scaled_matvec_1(mdspan<double, extents<size_t, num_rows, num_cols>> A, mdspan<double, extents<size_t, num_cols>> x, mdspan<double, extents<size_t, num_rows>> y) { matrix_vector_product(scaled(3.0, A), x, y);}// z = 7.0 times the transpose of A, times yvoid scaled_transposed_matvec(mdspan<double, extents<size_t, num_rows, num_cols>> A, mdspan<double, extents<size_t, num_rows>> y, mdspan<double, extents<size_t, num_cols>> z) { matrix_vector_product(scaled(7.0, transposed(A)), y, z);} — end example]

🔗

template<[in-matrix](linalg.helpers.concepts#concept:in-matrix "29.9.7.5Argument concepts[linalg.helpers.concepts]") InMat, [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") InVec1, [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") InVec2, [out-vector](linalg.helpers.concepts#concept:out-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") OutVec> void matrix_vector_product(InMat A, InVec1 x, InVec2 y, OutVec z); template<class ExecutionPolicy, [in-matrix](linalg.helpers.concepts#concept:in-matrix "29.9.7.5Argument concepts[linalg.helpers.concepts]") InMat, [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") InVec1, [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") InVec2, [out-vector](linalg.helpers.concepts#concept:out-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") OutVec> void matrix_vector_product(ExecutionPolicy&& exec, InMat A, InVec1 x, InVec2 y, OutVec z);

8

#

These functions perform an updating matrix-vector product.

9

#

Effects: Computes z=y+Ax.

10

#

Remarks: z may alias y.

[Example 2: // y = 3.0 * A * x + 2.0 * yvoid scaled_matvec_2(mdspan<double, extents<size_t, num_rows, num_cols>> A, mdspan<double, extents<size_t, num_cols>> x, mdspan<double, extents<size_t, num_rows>> y) { matrix_vector_product(scaled(3.0, A), x, scaled(2.0, y), y);} — end example]