VectorExpression-Impl.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: VectorExpression-Impl.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Base class for vector expression.
6 > Created Time: 2017/09/27
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_VECTOR_EXPRESSION_IMPL_H
10 #define CUBBYFLOW_VECTOR_EXPRESSION_IMPL_H
11 
12 #include <cassert>
13 
14 namespace CubbyFlow
15 {
16  // MARK: VectorExpression
17  template <typename T, typename E>
19  {
20  return static_cast<const E&>(*this).size();
21  }
22 
23  template <typename T, typename E>
25  {
26  return static_cast<const E&>(*this);
27  }
28 
29  // MARK: VectorUnaryOp
30  template <typename T, typename E, typename Op>
32  {
33  // Do nothing
34  }
35 
36  template <typename T, typename E, typename Op>
38  {
39  return m_u.size();
40  }
41 
42  template <typename T, typename E, typename Op>
44  {
45  return m_op(m_u[i]);
46  }
47 
48  // MARK: VectorBinaryOp
49  template <typename T, typename E1, typename E2, typename Op>
50  VectorBinaryOp<T, E1, E2, Op>::VectorBinaryOp(const E1& u, const E2& v) : m_u(u), m_v(v)
51  {
52  assert(u.size() == v.size());
53  }
54 
55  template <typename T, typename E1, typename E2, typename Op>
57  {
58  return m_v.size();
59  }
60 
61  template <typename T, typename E1, typename E2, typename Op>
63  {
64  return m_op(m_u[i], m_v[i]);
65  }
66 
67  template <typename T, typename E, typename Op>
68  VectorScalarBinaryOp<T, E, Op>::VectorScalarBinaryOp(const E& u, const T& v) : m_u(u), m_v(v)
69  {
70  // Do nothing
71  }
72 
73  template <typename T, typename E, typename Op>
75  {
76  return m_u.size();
77  }
78 
79  template <typename T, typename E, typename Op>
81  {
82  return m_op(m_u[i], m_v);
83  }
84 
85  // MARK: Global Functions
86  template <typename T, typename E>
88  {
89  return VectorScalarAdd<T, E>(b(), a);
90  }
91 
92  template <typename T, typename E>
94  {
95  return VectorScalarAdd<T, E>(a(), b);
96  }
97 
98  template <typename T, typename E1, typename E2>
100  {
101  return VectorAdd<T, E1, E2>(a(), b());
102  }
103 
104  template <typename T, typename E>
106  {
107  return VectorScalarRSub<T, E>(b(), a);
108  }
109 
110  template <typename T, typename E>
112  return VectorScalarSub<T, E>(a(), b);
113  }
114 
115  template <typename T, typename E1, typename E2>
117  {
118  return VectorSub<T, E1, E2>(a(), b());
119  }
120 
121  template <typename T, typename E>
123  {
124  return VectorScalarMul<T, E>(b(), a);
125  }
126 
127  template <typename T, typename E>
129  {
130  return VectorScalarMul<T, E>(a(), b);
131  }
132 
133  template <typename T, typename E1, typename E2>
135  {
136  return VectorMul<T, E1, E2>(a(), b());
137  }
138 
139  template <typename T, typename E>
141  {
142  return VectorScalarRDiv<T, E>(b(), a);
143  }
144 
145  template <typename T, typename E>
147  {
148  return VectorScalarDiv<T, E>(a(), b);
149  }
150 
151  template <typename T, typename E1, typename E2>
153  {
154  return VectorDiv<T, E1, E2>(a(), b());
155  }
156 }
157 
158 #endif
const E & operator()() const
Returns actual implementation (the subclass).
Definition: VectorExpression-Impl.h:24
T operator[](size_t i) const
Returns vector element at i.
Definition: VectorExpression-Impl.h:43
T operator[](size_t i) const
Returns vector element at i.
Definition: VectorExpression-Impl.h:62
Matrix< T, 2, 2 > operator+(const Matrix< T, 2, 2 > &a, const Matrix< T, 2, 2 > &b)
Returns a + b (element-size).
Definition: Matrix2x2-Impl.h:660
size_t size() const
Size of the matrix.
Definition: VectorExpression-Impl.h:56
T operator[](size_t i) const
Returns vector element at i.
Definition: VectorExpression-Impl.h:80
Base class for vector expression.
Definition: VectorExpression.h:28
size_t size() const
Size of the matrix.
Definition: VectorExpression-Impl.h:37
VectorBinaryOp(const E1 &u, const E2 &v)
Constructs binary operation expression for given input vector expressions.
Definition: VectorExpression-Impl.h:50
Vector expression for binary operation.
Definition: VectorExpression.h:85
VectorUnaryOp(const E &u)
Constructs unary operation expression for given input expression.
Definition: VectorExpression-Impl.h:31
Matrix< T, 2, 2 > operator/(const Matrix< T, 2, 2 > &a, T b)
Definition: Matrix2x2-Impl.h:720
Definition: pybind11Utils.h:24
size_t size() const
Size of the matrix.
Definition: VectorExpression-Impl.h:74
Matrix< T, 2, 2 > operator-(const Matrix< T, 2, 2 > &a)
Returns a matrix with opposite sign.
Definition: Matrix2x2-Impl.h:654
size_t size() const
Size of the vector.
Definition: VectorExpression-Impl.h:18
VectorScalarBinaryOp(const E &u, const T &v)
Constructs a binary expression for given vector and scalar.
Definition: VectorExpression-Impl.h:68
Vector< T, 3 > operator*(const Quaternion< T > &q, const Vector< T, 3 > &v)
Returns quaternion q * vector v.
Definition: Quaternion-Impl.h:481
Vector expression for matrix-scalar binary operation.
Definition: VectorExpression.h:114