[linalg.algs.blas2.trsv]

# 29 Numerics library [[numerics]](./#numerics)

## 29.9 Basic linear algebra algorithms [[linalg]](linalg#algs.blas2.trsv)

### 29.9.14 BLAS 2 algorithms [[linalg.algs.blas2]](linalg.algs.blas2#trsv)

#### 29.9.14.5 Solve a triangular linear system [linalg.algs.blas2.trsv]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14640)

[*Note [1](#note-1)*:

These functions correspond to the BLAS functionsxTRSV and xTPSV[[bib]](bibliography#bib:blas2 "Bibliography")[.](#1.sentence-1)

â *end note*]

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14646)

The following elements apply to all functions in [linalg.algs.blas2.trsv][.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14649)

*Mandates*: 

- [(3.1)](#3.1)

If InMat has layout_blas_packed layout,
then the layout's Triangle template argument has
the same type as the function's Triangle template argument;

- [(3.2)](#3.2)

*compatible-static-extents*<decltype(A), decltype(A)>(0, 1) is true;

- [(3.3)](#3.3)

*compatible-static-extents*<decltype(A), decltype(b)>(0, 0) is true; and

- [(3.4)](#3.4)

*compatible-static-extents*<decltype(A), decltype(x)>(0, 0) is true for those overloads that take an x parameter[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14667)

*Preconditions*: 

- [(4.1)](#4.1)

A.extent(0) equals A.extent(1),

- [(4.2)](#4.2)

A.extent(0) equals b.extent(0), and

- [(4.3)](#4.3)

A.extent(0) equals x.extent(0) for those overloads that take an x parameter[.](#4.sentence-1)

[ð](#lib:triangular_matrix_vector_solve)

`  template<[in-matrix](linalg.helpers.concepts#concept:in-matrix "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InMat, class Triangle, class DiagonalStorage,
           [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InVec, [out-vector](linalg.helpers.concepts#concept:out-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") OutVec, class BinaryDivideOp>
    void triangular_matrix_vector_solve(InMat A, Triangle t, DiagonalStorage d,
                                        InVec b, OutVec x, BinaryDivideOp divide);
  template<class ExecutionPolicy, [in-matrix](linalg.helpers.concepts#concept:in-matrix "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InMat, class Triangle, class DiagonalStorage,
           [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InVec, [out-vector](linalg.helpers.concepts#concept:out-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") OutVec, class BinaryDivideOp>
    void triangular_matrix_vector_solve(ExecutionPolicy&& exec,
                                        InMat A, Triangle t, DiagonalStorage d,
                                        InVec b, OutVec x, BinaryDivideOp divide);
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14694)

These functions perform
a triangular solve,
taking into account the Triangle and DiagonalStorage parameters
that apply to the triangular matrix A ([[linalg.general]](linalg.general "29.9.3 General"))[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14700)

*Effects*: Computes a vector xâ² such that b=Axâ²,
and assigns each element of xâ² to the corresponding element of x[.](#6.sentence-1)

If no such xâ² exists,
then the elements of x are valid but unspecified[.](#6.sentence-2)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14707)

*Complexity*: O(A.extent(1)Ãb.extent(0))[.](#7.sentence-1)

[ð](#lib:triangular_matrix_vector_solve_)

`template<[in-matrix](linalg.helpers.concepts#concept:in-matrix "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InMat, class Triangle, class DiagonalStorage,
         [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InVec, [out-vector](linalg.helpers.concepts#concept:out-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") OutVec>
  void triangular_matrix_vector_solve(InMat A, Triangle t, DiagonalStorage d, InVec b, OutVec x);
`

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14720)

*Effects*: Equivalent to:triangular_matrix_vector_solve(A, t, d, b, x, divides<void>{});

[ð](#lib:triangular_matrix_vector_solve__)

`template<class ExecutionPolicy, [in-matrix](linalg.helpers.concepts#concept:in-matrix "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InMat, class Triangle, class DiagonalStorage,
         [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InVec, [out-vector](linalg.helpers.concepts#concept:out-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") OutVec>
  void triangular_matrix_vector_solve(ExecutionPolicy&& exec,
                                      InMat A, Triangle t, DiagonalStorage d, InVec b, OutVec x);
`

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14737)

*Effects*: Equivalent to:triangular_matrix_vector_solve(std::forward<ExecutionPolicy>(exec),
 A, t, d, b, x, divides<void>{});

[ð](#lib:triangular_matrix_vector_solve___)

`template<[in-matrix](linalg.helpers.concepts#concept:in-matrix "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InMat, class Triangle, class DiagonalStorage,
         [inout-vector](linalg.helpers.concepts#concept:inout-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InOutVec, class BinaryDivideOp>
  void triangular_matrix_vector_solve(InMat A, Triangle t, DiagonalStorage d,
                                      InOutVec b, BinaryDivideOp divide);
template<class ExecutionPolicy, [in-matrix](linalg.helpers.concepts#concept:in-matrix "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InMat, class Triangle, class DiagonalStorage,
         [inout-vector](linalg.helpers.concepts#concept:inout-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InOutVec, class BinaryDivideOp>
  void triangular_matrix_vector_solve(ExecutionPolicy&& exec,
                                      InMat A, Triangle t, DiagonalStorage d,
                                      InOutVec b, BinaryDivideOp divide);
`

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14760)

These functions perform an in-place triangular solve,
taking into account the Triangle and DiagonalStorage parameters
that apply to the triangular matrix A ([[linalg.general]](linalg.general "29.9.3 General"))[.](#10.sentence-1)

[*Note [2](#note-2)*:

Performing triangular solve in place hinders parallelization[.](#10.sentence-2)

However, other ExecutionPolicy specific optimizations,
such as vectorization, are still possible[.](#10.sentence-3)

â *end note*]

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14770)

*Effects*: Computes a vector xâ² such that b=Axâ²,
and assigns each element of xâ² to the corresponding element of b[.](#11.sentence-1)

If no such xâ² exists,
then the elements of b are valid but unspecified[.](#11.sentence-2)

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14777)

*Complexity*: O(A.extent(1)Ãb.extent(0))[.](#12.sentence-1)

[ð](#lib:triangular_matrix_vector_solve____)

`template<[in-matrix](linalg.helpers.concepts#concept:in-matrix "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InMat, class Triangle, class DiagonalStorage, [inout-vector](linalg.helpers.concepts#concept:inout-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InOutVec>
  void triangular_matrix_vector_solve(InMat A, Triangle t, DiagonalStorage d, InOutVec b);
`

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14789)

*Effects*: Equivalent to:triangular_matrix_vector_solve(A, t, d, b, divides<void>{});

[ð](#lib:triangular_matrix_vector_solve_____)

`template<class ExecutionPolicy,
         [in-matrix](linalg.helpers.concepts#concept:in-matrix "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InMat, class Triangle, class DiagonalStorage, [inout-vector](linalg.helpers.concepts#concept:inout-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InOutVec>
  void triangular_matrix_vector_solve(ExecutionPolicy&& exec,
                                      InMat A, Triangle t, DiagonalStorage d, InOutVec b);
`

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L14806)

*Effects*: Equivalent to:triangular_matrix_vector_solve(std::forward<ExecutionPolicy>(exec),
 A, t, d, b, divides<void>{});
