9 #ifndef CUBBYFLOW_VECTOR_IMPL_H 10 #define CUBBYFLOW_VECTOR_IMPL_H 16 template <
typename T,
size_t N>
19 for (
auto& elem : m_elements)
21 elem =
static_cast<T
>(0);
25 template <
typename T,
size_t N>
26 template <
typename... Params>
29 static_assert(
sizeof...(params) == N,
"Invalid number of parameters");
34 template <
typename T,
size_t N>
41 template <
typename T,
size_t N>
48 template <
typename T,
size_t N>
54 template <
typename T,
size_t N>
60 template <
typename T,
size_t N>
64 assert(list.size() >= N);
67 for (
const auto& inputElem : list)
69 m_elements[i] =
static_cast<T
>(inputElem);
74 template <
typename T,
size_t N>
78 assert(size() == other.
size());
81 const E& expression = other();
82 ForEachIndex([&](
size_t i) { m_elements[i] = expression[i]; });
85 template <
typename T,
size_t N>
88 m_elements = other.m_elements;
91 template <
typename T,
size_t N>
94 std::swap(other.m_elements, m_elements);
97 template <
typename T,
size_t N>
103 template <
typename T,
size_t N>
109 template <
typename T,
size_t N>
115 template <
typename T,
size_t N>
118 return m_elements.
data();
121 template <
typename T,
size_t N>
124 return m_elements.
data();
127 template <
typename T,
size_t N>
130 return m_elements.
begin();
133 template <
typename T,
size_t N>
136 return m_elements.cbegin();
139 template <
typename T,
size_t N>
142 return m_elements.
end();
145 template <
typename T,
size_t N>
148 return m_elements.cend();
151 template <
typename T,
size_t N>
157 template <
typename T,
size_t N>
163 template <
typename T,
size_t N>
166 return m_elements[i];
169 template <
typename T,
size_t N>
172 return m_elements[i];
175 template <
typename T,
size_t N>
180 for (T val : m_elements)
188 template <
typename T,
size_t N>
191 return Sum() /
static_cast<T
>(size());
194 template <
typename T,
size_t N>
197 T ret = m_elements.front();
199 for (T val : m_elements)
201 ret = std::min(ret, val);
207 template <
typename T,
size_t N>
210 T ret = m_elements.front();
212 for (T val : m_elements)
214 ret = std::max(ret, val);
220 template <
typename T,
size_t N>
223 T ret = m_elements.front();
225 for (T val : m_elements)
233 template <
typename T,
size_t N>
236 T ret = m_elements.front();
238 for (T val : m_elements)
246 template <
typename T,
size_t N>
249 auto iter = std::max_element(begin(), end(), [](
const T& a,
const T& b)
251 return std::fabs(a) < std::fabs(b);
254 return iter - begin();
257 template <
typename T,
size_t N>
260 auto iter = std::max_element(begin(), end(), [](
const T& a,
const T& b)
262 return std::fabs(a) > std::fabs(b);
265 return iter - begin();
268 template <
typename T,
size_t N>
275 template <
typename T,
size_t N>
278 return std::sqrt(LengthSquared());
281 template <
typename T,
size_t N>
287 template <
typename T,
size_t N>
288 template <
typename E>
291 return std::sqrt(DistanceSquaredTo(other));
294 template <
typename T,
size_t N>
295 template <
typename E>
298 assert(size() == other.size());
302 for (
size_t i = 0; i < N; ++i)
304 T diff = (m_elements[i] - other[i]);
311 template <
typename T,
size_t N>
312 template <
typename U>
318 template <
typename T,
size_t N>
319 template <
typename E>
322 if (size() != other.size())
327 for (
size_t i = 0; i < size(); ++i)
329 if (At(i) != other[i])
338 template <
typename T,
size_t N>
339 template <
typename E>
342 if (size() != other.size())
347 for (
size_t i = 0; i < size(); ++i)
349 if (std::fabs(At(i) - other[i]) > epsilon)
358 template <
typename T,
size_t N>
359 template <
typename E>
365 template <
typename T,
size_t N>
371 template <
typename T,
size_t N>
372 template <
typename E>
378 template <
typename T,
size_t N>
384 template <
typename T,
size_t N>
385 template <
typename E>
391 template <
typename T,
size_t N>
397 template <
typename T,
size_t N>
398 template <
typename E>
404 template <
typename T,
size_t N>
410 template <
typename T,
size_t N>
411 template <
typename E>
414 assert(size() == v.size());
418 for (
size_t i = 0; i < N; ++i)
420 ret += m_elements[i] * v[i];
426 template <
typename T,
size_t N>
432 template <
typename T,
size_t N>
433 template <
typename E>
439 template <
typename T,
size_t N>
445 template <
typename T,
size_t N>
446 template <
typename E>
452 template <
typename T,
size_t N>
458 template <
typename T,
size_t N>
459 template <
typename E>
465 template <
typename T,
size_t N>
471 template <
typename T,
size_t N>
472 template <
typename E>
478 template <
typename T,
size_t N>
484 template <
typename T,
size_t N>
485 template <
typename E>
491 template <
typename T,
size_t N>
497 template <
typename T,
size_t N>
498 template <
typename E>
504 template <
typename T,
size_t N>
505 template <
typename Callback>
511 template <
typename T,
size_t N>
512 template <
typename Callback>
518 template <
typename T,
size_t N>
521 return m_elements[i];
524 template <
typename T,
size_t N>
527 return m_elements[i];
530 template <
typename T,
size_t N>
531 template <
typename U>
538 template <
typename T,
size_t N>
539 template <
typename E>
546 template <
typename T,
size_t N>
553 template <
typename T,
size_t N>
554 template <
typename E>
561 template <
typename T,
size_t N>
568 template <
typename T,
size_t N>
569 template <
typename E>
576 template <
typename T,
size_t N>
583 template <
typename T,
size_t N>
584 template <
typename E>
591 template <
typename T,
size_t N>
598 template <
typename T,
size_t N>
599 template <
typename E>
606 template <
typename T,
size_t N>
607 template <
typename E>
613 template <
typename T,
size_t N>
614 template <
typename E>
620 template <
typename T,
size_t N>
621 template <
typename... Params>
626 SetAt(i + 1, params...);
629 template <
typename T,
size_t N>
630 void Vector<T, N>::SetAt(
size_t i, T v)
T AbsMin(T x, T y)
Returns the absolute minimum value among the two inputs.
Definition: MathUtils-Impl.h:39
ContainerType::iterator begin()
Returns the begin iterator of the vector.
Definition: Vector-Impl.h:128
void ForEachIndex(Callback func) const
Iterates the vector and invoke given func for each index.
Definition: Vector-Impl.h:513
Base class for vector expression.
Definition: VectorExpression.h:28
Generic statically-sized N-D vector class.
Definition: Vector.h:33
Vector expression for unary operation.
Definition: VectorExpression.h:50
Vector()
Constructs a vector with zeros.
Definition: Vector-Impl.h:17
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
Vector expression for binary operation.
Definition: VectorExpression.h:85
void ForEach(Callback func) const
Iterates the vector and invoke given func for each element.
Definition: Vector-Impl.h:506
Definition: pybind11Utils.h:24
ContainerType::iterator end()
Returns the end iterator of the vector.
Definition: Vector-Impl.h:140
T * data()
Returns the raw pointer to the vector data.
Definition: Vector-Impl.h:116
size_t size() const
Size of the vector.
Definition: VectorExpression-Impl.h:18
Point< T, 2 > Max(const Point< T, 2 > &a, const Point< T, 2 > &b)
Returns element-wise max point: (max(a.x, b.x), max(a.y, b.y)).
Definition: Point2-Impl.h:480
1-D array accessor class.
Definition: ArrayAccessor1.h:28
T AbsMax(T x, T y)
Returns the absolute maximum value among the two inputs.
Definition: MathUtils-Impl.h:45
Point< T, 2 > Min(const Point< T, 2 > &a, const Point< T, 2 > &b)
Returns element-wise min point: (min(a.x, b.x), min(a.y, b.y)).
Definition: Point2-Impl.h:474
Vector expression for matrix-scalar binary operation.
Definition: VectorExpression.h:114