BLAS-Impl.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_BLAS_IMPL_HPP
12 #define CUBBYFLOW_BLAS_IMPL_HPP
13 
14 #include <cmath>
15 
16 namespace CubbyFlow
17 {
18 template <typename ScalarType, typename VectorType, typename MatrixType>
20  VectorType* result)
21 {
22  result->Fill(s);
23 }
24 
25 template <typename ScalarType, typename VectorType, typename MatrixType>
27  VectorType* result)
28 {
29  result->CopyFrom(v);
30 }
31 
32 template <typename ScalarType, typename VectorType, typename MatrixType>
34  MatrixType* result)
35 {
36  result->Fill(s);
37 }
38 
39 template <typename ScalarType, typename VectorType, typename MatrixType>
41  MatrixType* result)
42 {
43  result->CopyFrom(m);
44 }
45 
46 template <typename ScalarType, typename VectorType, typename MatrixType>
48  const VectorType& b)
49 {
50  return a.Dot(b);
51 }
52 
53 template <typename ScalarType, typename VectorType, typename MatrixType>
55  const VectorType& x,
56  const VectorType& y,
57  VectorType* result)
58 {
59  *result = a * x + y;
60 }
61 
62 template <typename ScalarType, typename VectorType, typename MatrixType>
64  const VectorType& v,
65  VectorType* result)
66 {
67  *result = m * v;
68 }
69 
70 template <typename ScalarType, typename VectorType, typename MatrixType>
72  const VectorType& x,
73  const VectorType& b,
74  VectorType* result)
75 {
76  *result = b - a * x;
77 }
78 
79 template <typename ScalarType, typename VectorType, typename MatrixType>
81 {
82  return std::sqrt(v.Dot(v));
83 }
84 
85 template <typename ScalarType, typename VectorType, typename MatrixType>
87  const VectorType& v)
88 {
89  return std::fabs(v.AbsMax());
90 }
91 } // namespace CubbyFlow
92 
93 #endif
static ScalarType L2Norm(const VectorType &v)
Returns L2-norm of the given vector v.
Definition: BLAS-Impl.hpp:80
static void Residual(const MatrixType &a, const VectorType &x, const VectorType &b, VectorType *result)
Computes residual vector (b - ax).
Definition: BLAS-Impl.hpp:71
static ScalarType LInfNorm(const VectorType &v)
Returns L-inf-norm of the given vector v.
Definition: BLAS-Impl.hpp:86
Definition: pybind11Utils.hpp:20
static void MVM(const MatrixType &m, const VectorType &v, VectorType *result)
Performs matrix-vector multiplication.
Definition: BLAS-Impl.hpp:63
static void Set(ScalarType s, VectorType *result)
Sets entire element of given vector result with scalar s.
Definition: BLAS-Impl.hpp:19
M MatrixType
Definition: BLAS.hpp:32
V VectorType
Definition: BLAS.hpp:31
S ScalarType
Definition: BLAS.hpp:30
static void AXPlusY(ScalarType a, const VectorType &x, const VectorType &y, VectorType *result)
Definition: BLAS-Impl.hpp:54
static ScalarType Dot(const VectorType &a, const VectorType &b)
Performs dot product with vector a and b.
Definition: BLAS-Impl.hpp:47