BLAS-Impl.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: BLAS-Impl.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Generic BLAS operator wrapper class.
6 > Created Time: 2017/08/13
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_BLAS_IMPL_H
10 #define CUBBYFLOW_BLAS_IMPL_H
11 
12 #include <algorithm>
13 #include <cmath>
14 
15 namespace CubbyFlow
16 {
17  template <typename ScalarType, typename VectorType, typename MatrixType>
19  {
20  result->Set(s);
21  }
22 
23  template <typename ScalarType, typename VectorType, typename MatrixType>
25  {
26  result->Set(v);
27  }
28 
29  template <typename ScalarType, typename VectorType, typename MatrixType>
31  {
32  result->Set(s);
33  }
34 
35  template <typename ScalarType, typename VectorType, typename MatrixType>
37  {
38  result->Set(m);
39  }
40 
41  template <typename ScalarType, typename VectorType, typename MatrixType>
43  {
44  return a.Dot(b);
45  }
46 
47  template <typename ScalarType, typename VectorType, typename MatrixType>
49  {
50  *result = a * x + y;
51  }
52 
53  template <typename ScalarType, typename VectorType, typename MatrixType>
55  {
56  *result = m * v;
57  }
58 
59  template <typename ScalarType, typename VectorType, typename MatrixType>
61  {
62  *result = b - a * x;
63  }
64 
65  template <typename ScalarType, typename VectorType, typename MatrixType>
67  {
68  return std::sqrt(v.Dot(v));
69  }
70 
71  template <typename ScalarType, typename VectorType, typename MatrixType>
73  {
74  return std::fabs(v.AbsMax());
75  }
76 }
77 
78 #endif
static ScalarType L2Norm(const VectorType &v)
Returns L2-norm of the given vector v.
Definition: BLAS-Impl.h:66
static void Residual(const MatrixType &a, const VectorType &x, const VectorType &b, VectorType *result)
Computes residual vector (b - ax).
Definition: BLAS-Impl.h:60
static ScalarType LInfNorm(const VectorType &v)
Returns L-inf-norm of the given vector v.
Definition: BLAS-Impl.h:72
Definition: pybind11Utils.h:24
static void MVM(const MatrixType &m, const VectorType &v, VectorType *result)
Performs matrix-vector multiplication.
Definition: BLAS-Impl.h:54
static void Set(ScalarType s, VectorType *result)
Sets entire element of given vector result with scalar s.
Definition: BLAS-Impl.h:18
M MatrixType
Definition: BLAS.h:30
V VectorType
Definition: BLAS.h:29
S ScalarType
Definition: BLAS.h:28
static void AXPlusY(ScalarType a, const VectorType &x, const VectorType &y, VectorType *result)
Performs ax + y operation where a is a matrix and x and y are vectors.
Definition: BLAS-Impl.h:48
static ScalarType Dot(const VectorType &a, const VectorType &b)
Performs dot product with vector a and b.
Definition: BLAS-Impl.h:42