9 #ifndef CUBBYFLOW_VECTORN_IMPL_H 10 #define CUBBYFLOW_VECTORN_IMPL_H 53 (*this) = std::move(other);
59 m_elements.resize(n, val);
88 const E& expression = other();
89 ParallelForEachIndex([&](
size_t i) { m_elements[i] = expression[i]; });
95 m_elements.push_back(val);
101 std::swap(other.m_elements, m_elements);
104 template <
typename T>
110 template <
typename T>
116 template <
typename T>
119 return m_elements.
size();
122 template <
typename T>
125 return m_elements.
data();
128 template <
typename T>
131 return m_elements.
data();
134 template <
typename T>
137 return m_elements.
begin();
140 template <
typename T>
143 return m_elements.cbegin();
146 template <
typename T>
149 return m_elements.
end();
152 template <
typename T>
155 return m_elements.cend();
158 template <
typename T>
164 template <
typename T>
170 template <
typename T>
173 return m_elements[i];
176 template <
typename T>
179 return m_elements[i];
182 template <
typename T>
186 [&](
size_t start,
size_t end, T init)
190 for (
size_t i = start; i < end; ++i)
192 result += m_elements[i];
199 template <
typename T>
202 return Sum() /
static_cast<T
>(size());
205 template <
typename T>
208 const T& (*_min)(
const T&,
const T&) = std::min<T>;
211 [&](
size_t start,
size_t end, T init)
215 for (
size_t i = start; i < end; ++i)
217 result = std::min(result, m_elements[i]);
224 template <
typename T>
227 const T& (*_max)(
const T&,
const T&) = std::max<T>;
230 [&](
size_t start,
size_t end, T init)
234 for (
size_t i = start; i < end; ++i)
236 result = std::max(result, m_elements[i]);
243 template <
typename T>
247 [&](
size_t start,
size_t end, T init)
251 for (
size_t i = start; i < end; ++i)
257 }, CubbyFlow::AbsMin<T>);
260 template <
typename T>
264 [&](
size_t start,
size_t end, T init)
268 for (
size_t i = start; i < end; ++i)
274 }, CubbyFlow::AbsMax<T>);
277 template <
typename T>
280 auto iter = std::max_element(begin(), end(), [](
const T& a,
const T& b)
282 return std::fabs(a) < std::fabs(b);
285 return iter - begin();
288 template <
typename T>
291 auto iter = std::max_element(begin(), end(), [](
const T& a,
const T& b)
293 return std::fabs(a) > std::fabs(b);
296 return iter - begin();
299 template <
typename T>
306 template <
typename T>
309 return std::sqrt(LengthSquared());
312 template <
typename T>
318 template <
typename T>
319 template <
typename E>
322 return std::sqrt(DistanceSquaredTo(other));
325 template <
typename T>
326 template <
typename E>
329 assert(size() == other.size());
332 [&](
size_t start,
size_t end, T init)
336 for (
size_t i = start; i < end; ++i)
338 T diff = (m_elements[i] - other[i]);
339 result += diff * diff;
346 template <
typename T>
347 template <
typename U>
353 template <
typename T>
354 template <
typename E>
357 if (size() != other.size())
362 for (
size_t i = 0; i < size(); ++i)
364 if (At(i) != other[i])
373 template <
typename T>
374 template <
typename E>
377 if (size() != other.size())
382 for (
size_t i = 0; i < size(); ++i)
384 if (std::fabs(At(i) - other[i]) > epsilon)
393 template <
typename T>
394 template <
typename E>
400 template <
typename T>
406 template <
typename T>
407 template <
typename E>
413 template <
typename T>
419 template <
typename T>
420 template <
typename E>
426 template <
typename T>
432 template <
typename T>
433 template <
typename E>
439 template <
typename T>
445 template <
typename T>
446 template <
typename E>
449 assert(size() == v.size());
452 [&](
size_t start,
size_t end, T init)
456 for (
size_t i = start; i < end; ++i)
458 result += m_elements[i] * v[i];
465 template <
typename T>
471 template <
typename T>
472 template <
typename E>
478 template <
typename T>
484 template <
typename T>
485 template <
typename E>
491 template <
typename T>
497 template <
typename T>
498 template <
typename E>
504 template <
typename T>
510 template <
typename T>
511 template <
typename E>
517 template <
typename T>
523 template <
typename T>
524 template <
typename E>
530 template <
typename T>
536 template <
typename T>
537 template <
typename E>
543 template <
typename T>
544 template <
typename Callback>
550 template <
typename T>
551 template <
typename Callback>
557 template <
typename T>
558 template <
typename Callback>
564 template <
typename T>
565 template <
typename Callback>
571 template <
typename T>
574 return m_elements[i];
577 template <
typename T>
580 return m_elements[i];
583 template <
typename T>
584 template <
typename U>
591 template <
typename T>
592 template <
typename E>
599 template <
typename T>
606 template <
typename T>
609 m_elements = std::move(other.m_elements);
613 template <
typename T>
620 template <
typename T>
621 template <
typename E>
628 template <
typename T>
635 template <
typename T>
636 template <
typename E>
643 template <
typename T>
650 template <
typename T>
651 template <
typename E>
658 template <
typename T>
665 template <
typename T>
666 template <
typename E>
673 template <
typename T>
674 template <
typename E>
680 template <
typename T>
681 template <
typename E>
T * data()
Returns the raw pointer to the vector data.
Definition: VectorN-Impl.h:123
void ForEach(Callback func) const
Iterates the vector and invoke given func for each element.
Definition: VectorN-Impl.h:545
T AbsMin(T x, T y)
Returns the absolute minimum value among the two inputs.
Definition: MathUtils-Impl.h:39
void ParallelForEachIndex(Callback func) const
Iterates the vector and invoke given func for each index in parallel using multi-threading.
Definition: VectorN-Impl.h:566
void ForEachIndex(Callback func) const
Iterates the vector and invoke given func for each index.
Definition: VectorN-Impl.h:552
VectorN()
Constructs empty vector.
Definition: VectorN-Impl.h:19
Base class for vector expression.
Definition: VectorExpression.h:28
Vector expression for unary operation.
Definition: VectorExpression.h:50
General purpose dynamically-sizedN-D vector class.
Definition: VectorN.h:27
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
Vector expression for binary operation.
Definition: VectorExpression.h:85
void ParallelForEach(Callback func)
Iterates the vector and invoke given func for each element in parallel using multi-threading.
Definition: VectorN-Impl.h:559
Definition: pybind11Utils.h:24
ContainerType::iterator end()
Returns the end iterator of the vector.
Definition: VectorN-Impl.h:147
size_t size() const
Returns the size of the vector.
Definition: VectorN-Impl.h:117
size_t size() const
Size of the vector.
Definition: VectorExpression-Impl.h:18
constexpr size_t ZERO_SIZE
Zero size_t.
Definition: Constants.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
ContainerType::iterator begin()
Returns the begin iterator of the vector.
Definition: VectorN-Impl.h:135
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
void ParallelFill(const RandomIterator &begin, const RandomIterator &end, const T &value, ExecutionPolicy policy)
Fills from begin to end with value in parallel.
Definition: Parallel-Impl.h:182
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
Value ParallelReduce(IndexType beginIndex, IndexType endIndex, const Value &identity, const Function &function, const Reduce &reduce, ExecutionPolicy policy)
Performs reduce operation in parallel.
Definition: Parallel-Impl.h:407
Vector expression for matrix-scalar binary operation.
Definition: VectorExpression.h:114