fml  0.1-0
Fused Matrix Library
linalgutils.hh
1 // This file is part of fml which is released under the Boost Software
2 // License, Version 1.0. See accompanying file LICENSE or copy at
3 // https://www.boost.org/LICENSE_1_0.txt
4 
5 #ifndef FML__INTERNALS_LINALGUTILS_H
6 #define FML__INTERNALS_LINALGUTILS_H
7 #pragma once
8 
9 
10 #include <stdexcept>
11 
12 #include "types.hh"
13 
14 
15 namespace fml
16 {
17  namespace linalgutils
18  {
19  inline void check_info(const int info, std::string fun)
20  {
21  if (info != 0)
22  {
23  std::string msg = "function " + fun + "() returned info=" + std::to_string(info);
24  throw std::runtime_error(msg);
25  }
26  }
27 
28 
29 
30  inline void matadd_params(const bool transx, const bool transy, const len_t mx, const len_t nx, const len_t my, const len_t ny, len_t *m, len_t *n)
31  {
32  if (!transx && !transy)
33  {
34  if (mx != my || nx != ny)
35  throw std::runtime_error("non-conformable arguments");
36 
37  *m = mx;
38  *n = nx;
39  }
40  else if (transx && transy)
41  {
42  if (mx != my || nx != ny)
43  throw std::runtime_error("non-conformable arguments");
44 
45  *m = nx;
46  *n = mx;
47  }
48  else if (transx && !transy)
49  {
50  if (mx != ny || nx != my)
51  throw std::runtime_error("non-conformable arguments");
52 
53  *m = nx;
54  *n = mx;
55  }
56  else if (!transx && transy)
57  {
58  if (mx != ny || nx != my)
59  throw std::runtime_error("non-conformable arguments");
60 
61  *m = mx;
62  *n = nx;
63  }
64  else
65  {
66  throw std::runtime_error("this should be impossible");
67  }
68  }
69 
70 
71 
72  inline void matmult_params(const bool transx, const bool transy, const len_t mx, const len_t nx, const len_t my, const len_t ny, len_t *m, len_t *n, len_t *k)
73  {
74  if (!transx && !transy)
75  {
76  if (nx != my)
77  throw std::runtime_error("non-conformable arguments");
78  }
79  else if (transx && transy)
80  {
81  if (mx != ny)
82  throw std::runtime_error("non-conformable arguments");
83  }
84  else if (transx && !transy)
85  {
86  if (mx != my)
87  throw std::runtime_error("non-conformable arguments");
88  }
89  else if (!transx && transy)
90  {
91  if (nx != ny)
92  throw std::runtime_error("non-conformable arguments");
93  }
94 
95  // m = # rows of op(x)
96  // n = # cols of op(y)
97  // k = # cols of op(x)
98 
99  if (transx)
100  {
101  *m = nx;
102  *k = mx;
103  }
104  else
105  {
106  *m = mx;
107  *k = nx;
108  }
109 
110  *n = transy ? my : ny;
111  }
112  }
113 }
114 
115 
116 #endif
fml
Core namespace.
Definition: dimops.hh:10