37 #ifndef VIGRA_TINYVECTOR_HXX 38 #define VIGRA_TINYVECTOR_HXX 52 #include "metaprogramming.hxx" 53 #include "numerictraits.hxx" 55 #include "mathutil.hxx" 58 #ifdef VIGRA_CHECK_BOUNDS 59 #define VIGRA_ASSERT_INSIDE(diff) \ 60 vigra_precondition(diff >= 0, "Index out of bounds");\ 61 vigra_precondition(diff < SIZE, "Index out of bounds"); 63 #define VIGRA_ASSERT_INSIDE(diff) 70 #pragma warning( push ) 71 #pragma warning( disable : 4503 ) 80 template <
class V1,
int SIZE,
class D1,
class D2>
83 template <
class V1,
int SIZE,
class D1,
class D2>
91 #define VIGRA_EXEC_LOOP(NAME, OPER) \ 92 template <class T1, class T2> \ 93 static void NAME(T1 * left, T2 const * right) \ 95 for(int i=0; i<LEVEL; ++i) \ 96 (left[i]) OPER (right[i]); \ 99 #define VIGRA_EXEC_LOOP_MINMAX(NAME, OPER) \ 100 template <class T1, class T2> \ 101 static void NAME(T1 * left, T2 const * right) \ 103 for(int i=0; i<LEVEL; ++i) \ 104 if(left[i] OPER right[i]) \ 105 left[i] = right[i]; \ 108 #define VIGRA_EXEC_LOOP_SCALAR(NAME, OPER) \ 109 template <class T1, class T2> \ 110 static void NAME(T1 * left, T2 right) \ 112 for(int i=0; i<LEVEL; ++i) \ 113 (left[i]) = detail::RequiresExplicitCast<T1>::cast((left[i]) OPER (right)); \ 119 template <
class T1,
class T2>
120 static void assignCast(T1 * left, T2
const * right)
122 for(
int i=0; i<LEVEL; ++i)
123 left[i] = detail::RequiresExplicitCast<T1>::cast(right[i]);
126 template <
class T1,
class T2>
127 static void reverseAssign(T1 * left, T2
const * right)
129 for(
int i=0; i<LEVEL; ++i)
133 template <
class T1,
class T2>
134 static void assignScalar(T1 * left, T2 right)
136 for(
int i=0; i<LEVEL; ++i)
137 left[i] = detail::RequiresExplicitCast<T1>::cast(right);
140 template <
class T1,
class T2>
141 static void power(T1 * left, T2 right)
143 for(
int i=0; i<LEVEL; ++i)
144 left[i] = detail::RequiresExplicitCast<T1>::cast(
pow(left, right));
147 VIGRA_EXEC_LOOP(assign, =)
148 VIGRA_EXEC_LOOP(
add, +=)
149 VIGRA_EXEC_LOOP(
sub, -=)
150 VIGRA_EXEC_LOOP(
mul, *=)
151 VIGRA_EXEC_LOOP(
div, /=)
152 VIGRA_EXEC_LOOP(mod, %=)
153 VIGRA_EXEC_LOOP(neg, = -)
159 VIGRA_EXEC_LOOP(fromPromote, = NumericTraits<T1>::fromPromote)
160 VIGRA_EXEC_LOOP(fromRealPromote, = NumericTraits<T1>::fromRealPromote)
161 VIGRA_EXEC_LOOP_SCALAR(mulScalar, *)
162 VIGRA_EXEC_LOOP_SCALAR(divScalar, /)
164 VIGRA_EXEC_LOOP_MINMAX(
min, >)
165 VIGRA_EXEC_LOOP_MINMAX(
max, <)
168 static T const & minimum(T const * p)
170 return *std::min_element(p, p+LEVEL);
174 static T
const & maximum(T
const * p)
176 return *std::max_element(p, p+LEVEL);
180 static bool all(T
const * p, T
const & zero)
182 for(
int i=0; i<LEVEL; ++i)
189 static bool any(T
const * p, T
const & zero)
191 for(
int i=0; i<LEVEL; ++i)
197 template <
class T1,
class T2>
198 static bool notEqual(T1
const * left, T2
const * right)
200 for(
int i=0; i<LEVEL; ++i)
201 if(left[i] != right[i])
206 template <
class T1,
class T2>
207 static bool less(T1
const * left, T2
const * right)
209 for(
int i=0; i<LEVEL; ++i)
211 if(left[i] < right[i])
213 if(right[i] < left[i])
220 static bool closeAtTolerance(T
const * left, T
const * right, T epsilon)
223 for(
int i=0; i<LEVEL; ++i)
225 res = res && vigra::closeAtTolerance(left[i], right[i], epsilon);
231 static typename NumericTraits<T>::Promote
234 typename NumericTraits<T>::Promote res(*d * *d);
235 for(
int i=1; i<LEVEL; ++i)
240 template <
class T1,
class T2>
241 static typename PromoteTraits<T1, T2>::Promote
242 dot(T1
const * left, T2
const * right)
244 typename PromoteTraits<T1, T2>::Promote res(*left * *right);
245 for(
int i=1; i<LEVEL; ++i)
246 res += left[i] * right[i];
251 static typename NormTraits<T>::SquaredNormType
255 for(
int i=1; i<LEVEL; ++i)
262 struct UnrollScalarResult
265 static typename NumericTraits<T>::Promote
271 template <
class T1,
class T2>
272 static typename PromoteTraits<T1, T2>::Promote
273 dot(T1
const * left, T2
const * right)
279 static typename NormTraits<T>::SquaredNormType
285 static std::ptrdiff_t
292 static T
const & minimum(T
const * p)
294 T
const & m = UnrollScalarResult<LEVEL - 1>::minimum(p+1);
301 static T
const & maximum(T
const * p)
303 T
const & m = UnrollScalarResult<LEVEL - 1>::maximum(p+1);
310 static bool all(T
const * p, T
const & zero)
312 return *p != zero && UnrollScalarResult<LEVEL - 1>::all(p+1, zero);
316 static bool any(T
const * p, T
const & zero)
318 return *p != zero || UnrollScalarResult<LEVEL - 1>::any(p+1, zero);
323 struct UnrollScalarResult<1>
326 static typename NumericTraits<T>::Promote
332 template <
class T1,
class T2>
333 static typename PromoteTraits<T1, T2>::Promote
334 dot(T1
const * left, T2
const * right)
336 return *left * *right;
340 static typename NormTraits<T>::SquaredNormType
346 static std::ptrdiff_t
353 static T
const & minimum(T
const * p)
359 static T
const & maximum(T
const * p)
365 static bool all(T
const * p, T
const & zero)
371 static bool any(T
const * p, T
const & zero)
377 #undef VIGRA_EXEC_LOOP 378 #undef VIGRA_EXEC_LOOP_MINMAX 379 #undef VIGRA_EXEC_LOOP_SCALAR 381 #define VIGRA_UNROLL_LOOP(NAME, OPER) \ 382 template <class T1, class T2> \ 383 static void NAME(T1 * left, T2 const * right) \ 385 (*left) OPER (*right); \ 386 UnrollLoop<LEVEL-1>::NAME(left+1, right+1); \ 389 #define VIGRA_UNROLL_LOOP_MINMAX(NAME, OPER) \ 390 template <class T1, class T2> \ 391 static void NAME(T1 * left, T2 const * right) \ 393 if(*left OPER *right) \ 395 UnrollLoop<LEVEL-1>::NAME(left+1, right+1); \ 398 #define VIGRA_UNROLL_LOOP_SCALAR(NAME, OPER) \ 399 template <class T1, class T2> \ 400 static void NAME(T1 * left, T2 right) \ 402 (*left) = detail::RequiresExplicitCast<T1>::cast((*left) OPER (right)); \ 403 UnrollLoop<LEVEL-1>::NAME(left+1, right); \ 410 template <
class T1,
class T2>
411 static void reverseAssign(T1 * left, T2
const * right)
414 UnrollLoop<LEVEL-1>::reverseAssign(left+1, right-1);
417 template <
class T1,
class T2>
418 static void assignCast(T1 * left, T2
const * right)
420 *left = detail::RequiresExplicitCast<T1>::cast(*right);
421 UnrollLoop<LEVEL-1>::assignCast(left+1, right+1);
424 template <
class T1,
class T2>
425 static void assignScalar(T1 * left, T2 right)
427 *left = detail::RequiresExplicitCast<T1>::cast(right);
428 UnrollLoop<LEVEL-1>::assignScalar(left+1, right);
431 template <
class T1,
class T2>
432 static void power(T1 * left, T2 right)
434 *left = detail::RequiresExplicitCast<T1>::cast(
pow(*left, right));
438 VIGRA_UNROLL_LOOP(assign, =)
439 VIGRA_UNROLL_LOOP(
add, +=)
440 VIGRA_UNROLL_LOOP(
sub, -=)
441 VIGRA_UNROLL_LOOP(
mul, *=)
442 VIGRA_UNROLL_LOOP(
div, /=)
443 VIGRA_UNROLL_LOOP(mod, %=)
444 VIGRA_UNROLL_LOOP(neg, = -)
445 VIGRA_UNROLL_LOOP(
abs, =
vigra::abs)
450 VIGRA_UNROLL_LOOP(fromPromote, = NumericTraits<T1>::fromPromote)
451 VIGRA_UNROLL_LOOP(fromRealPromote, = NumericTraits<T1>::fromRealPromote)
452 VIGRA_UNROLL_LOOP_SCALAR(mulScalar, *)
453 VIGRA_UNROLL_LOOP_SCALAR(divScalar, /)
455 VIGRA_UNROLL_LOOP_MINMAX(
min, >)
456 VIGRA_UNROLL_LOOP_MINMAX(
max, <)
459 static T const & minimum(T const * p)
461 return UnrollScalarResult<LEVEL>::minimum(p);
465 static T
const & maximum(T
const * p)
467 return UnrollScalarResult<LEVEL>::maximum(p);
471 static bool all(T
const * p, T
const & zero)
473 return UnrollScalarResult<LEVEL>::all(p, zero);
477 static bool any(T
const * p, T
const & zero)
479 return UnrollScalarResult<LEVEL>::any(p, zero);
482 template <
class T1,
class T2>
483 static bool notEqual(T1
const * left, T2
const * right)
485 return (*left != *right) || UnrollLoop<LEVEL - 1>::notEqual(left+1, right+1);
488 template <
class T1,
class T2>
489 static bool less(T1
const * left, T2
const * right)
495 return UnrollLoop<LEVEL - 1>::less(left+1, right+1);
499 static bool closeAtTolerance(T
const * left, T
const * right, T epsilon)
501 return vigra::closeAtTolerance(*left, *right, epsilon) &&
502 UnrollLoop<LEVEL - 1>::closeAtTolerance(left+1, right+1, epsilon);
506 static typename NumericTraits<T>::Promote
512 template <
class T1,
class T2>
513 static typename PromoteTraits<T1, T2>::Promote
514 dot(T1
const * left, T2
const * right)
520 static typename NormTraits<T>::SquaredNormType
527 #undef VIGRA_UNROLL_LOOP 528 #undef VIGRA_UNROLL_LOOP_MINMAX 529 #undef VIGRA_UNROLL_LOOP_SCALAR 534 template <
class T1,
class T2>
535 static void reverseAssign(T1, T2) {}
536 template <
class T1,
class T2>
537 static void assignCast(T1, T2) {}
538 template <
class T1,
class T2>
539 static void assign(T1, T2) {}
540 template <
class T1,
class T2>
541 static void assignScalar(T1, T2) {}
542 template <
class T1,
class T2>
543 static void power(T1, T2) {}
544 template <
class T1,
class T2>
545 static void add(T1, T2) {}
546 template <
class T1,
class T2>
547 static void sub(T1, T2) {}
548 template <
class T1,
class T2>
549 static void mul(T1, T2) {}
550 template <
class T1,
class T2>
551 static void mulScalar(T1, T2) {}
552 template <
class T1,
class T2>
553 static void div(T1, T2) {}
554 template <
class T1,
class T2>
555 static void mod(T1, T2) {}
556 template <
class T1,
class T2>
557 static void divScalar(T1, T2) {}
558 template <
class T1,
class T2>
559 static void fromPromote(T1, T2) {}
560 template <
class T1,
class T2>
561 static void fromRealPromote(T1, T2) {}
562 template <
class T1,
class T2>
563 static void neg(T1, T2) {}
564 template <
class T1,
class T2>
565 static void abs(T1, T2) {}
566 template <
class T1,
class T2>
567 static void floor(T1, T2) {}
568 template <
class T1,
class T2>
569 static void ceil(T1, T2) {}
570 template <
class T1,
class T2>
571 static void round(T1, T2) {}
572 template <
class T1,
class T2>
573 static void sqrt(T1, T2) {}
574 template <
class T1,
class T2>
575 static bool notEqual(T1, T2) {
return false; }
576 template <
class T1,
class T2>
577 static bool less(T1, T2) {
return false; }
578 template <
class T1,
class T2>
579 static void min(T1, T2) {}
580 template <
class T1,
class T2>
581 static void max(T1, T2) {}
587 static bool all(T
const *, T
const &) {
return true; }
589 static bool any(T
const *, T
const &) {
return false; }
591 static bool closeAtTolerance(T
const *, T
const *, T) {
return true; }
597 static const int MaxUnrollSize = 5;
598 typedef typename IfBool<(SIZE <= MaxUnrollSize), UnrollLoop<SIZE>, ExecLoop<SIZE> >::type type;
604 inline DontInit dontInit() {
return DontInit(); }
608 template <
class T,
int SIZE>
611 template <
class T,
int SIZE>
629 template <
class VALUETYPE,
int SIZE,
class DATA,
class DERIVED>
638 typedef typename detail::LoopType<SIZE>::type Loop;
690 typedef typename SquareRootTraits<SquaredNormType>::SquareRootResult
NormType;
694 enum { static_size = SIZE };
698 template <
class Iterator>
699 void init(Iterator i, Iterator end)
701 vigra_precondition(end-i == SIZE,
702 "TinyVector::init(): Sequence has wrong size.");
703 Loop::assignCast(data_, i);
710 Loop::assignScalar(data_, initial);
715 template <
class T1,
class D1,
class D2>
719 return static_cast<DERIVED &
>(*this);
724 template <
class T1,
class D1,
class D2>
728 return static_cast<DERIVED &
>(*this);
733 template <
class T1,
class D1,
class D2>
737 return static_cast<DERIVED &
>(*this);
742 template <
class T1,
class D1,
class D2>
746 return static_cast<DERIVED &
>(*this);
751 template <
class T1,
class D1,
class D2>
754 Loop::mod(data_, r.
begin());
755 return static_cast<DERIVED &
>(*this);
762 Loop::mulScalar(data_, r);
763 return static_cast<DERIVED &
>(*this);
770 Loop::divScalar(data_, r);
771 return static_cast<DERIVED &
>(*this);
778 return sqrt(
static_cast<typename
779 SquareRootTraits<SquaredNormType>::SquareRootArgument
>(squaredMagnitude()));
793 return Loop::minimum(data_);
800 return Loop::maximum(data_);
807 return Loop::all(data_, VALUETYPE());
814 return Loop::any(data_, VALUETYPE());
821 VIGRA_ASSERT_INSIDE(i);
829 VIGRA_ASSERT_INSIDE(i);
838 iterator
end() {
return data_ + SIZE; }
842 const_iterator
begin()
const {
return data_; }
846 const_iterator
end()
const {
return data_ + SIZE; }
852 template <
int FROM,
int TO>
855 #ifdef VIGRA_CHECK_BOUNDS 856 vigra_precondition(FROM >= 0,
"Index out of bounds");
857 vigra_precondition(FROM < TO,
"Index out of bounds");
858 vigra_precondition(TO <=SIZE,
"Index out of bounds");
865 size_type
size()
const {
return SIZE; }
867 pointer data() {
return data_; }
869 const_pointer data()
const {
return data_; }
873 VIGRA_ASSERT_INSIDE(k);
912 template <
class T,
int SIZE>
917 typedef typename BaseType::Loop Loop;
921 typedef typename BaseType::value_type
value_type;
922 typedef typename BaseType::reference
reference;
924 typedef typename BaseType::pointer
pointer;
926 typedef typename BaseType::iterator
iterator;
928 typedef typename BaseType::size_type
size_type;
932 typedef typename BaseType::NormType
NormType;
934 enum ReverseCopyTag { ReverseCopy };
943 Loop::assignScalar(BaseType::begin(), initial);
953 Loop::assignScalar(BaseType::begin(), -1);
963 BaseType::data_[0] = detail::RequiresExplicitCast<T>::cast(initial.
x);
964 BaseType::data_[1] = detail::RequiresExplicitCast<T>::cast(initial.
y);
973 BaseType::data_[0] = i1;
974 BaseType::data_[1] = i2;
980 TinyVector(value_type
const & i1, value_type
const & i2, value_type
const & i3)
983 BaseType::data_[0] = i1;
984 BaseType::data_[1] = i2;
985 BaseType::data_[2] = i3;
992 value_type
const & i3, value_type
const & i4)
995 BaseType::data_[0] = i1;
996 BaseType::data_[1] = i2;
997 BaseType::data_[2] = i3;
998 BaseType::data_[3] = i4;
1005 value_type
const & i3, value_type
const & i4,
1006 value_type
const & i5)
1009 BaseType::data_[0] = i1;
1010 BaseType::data_[1] = i2;
1011 BaseType::data_[2] = i3;
1012 BaseType::data_[3] = i4;
1013 BaseType::data_[4] = i5;
1021 Loop::assignScalar(BaseType::data_, value_type());
1039 Loop::assign(BaseType::data_, r.data_);
1048 Loop::assign(BaseType::data_, data);
1062 Loop::reverseAssign(BaseType::data_, data+SIZE-1);
1067 template <
class U,
class DATA,
class DERIVED>
1071 Loop::assignCast(BaseType::data_, r.
begin());
1078 Loop::assign(BaseType::data_, r.data_);
1084 template <
class U,
class DATA,
class DERIVED>
1087 Loop::assignCast(BaseType::data_, r.
begin());
1097 BaseType::data_[0] = detail::RequiresExplicitCast<T>::cast(r.
x);
1098 BaseType::data_[1] = detail::RequiresExplicitCast<T>::cast(r.
y);
1106 Loop::assignScalar(BaseType::begin(), v);
1114 template <
class U,
int USIZE,
class DATA,
class DERIVED>
1117 static const int minSize = USIZE < SIZE
1121 typedef typename detail::LoopType<minSize>::type MinLoop;
1122 MinLoop::assignCast(BaseType::data_, r.
begin());
1156 template <
class T,
int SIZE>
1161 typedef typename BaseType::Loop Loop;
1184 BaseType::data_ = 0;
1192 BaseType::data_ =
const_cast<pointer
>(data);
1200 BaseType::data_ =
const_cast<pointer
>(other.data_);
1205 template <
class DATA,
class DERIVED>
1209 BaseType::data_ =
const_cast<pointer
>(other.data());
1216 Loop::assign(BaseType::data_, r.
begin());
1222 template <
class U,
class DATA,
class DERIVED>
1225 Loop::assignCast(BaseType::data_, r.
begin());
1248 template <
class V1,
int SIZE,
class D1,
class D2,
class V2,
class D3,
class D4>
1257 template <
class V1,
int SIZE,
class D1,
class D2,
class V2,
class D3,
class D4>
1262 typedef typename detail::LoopType<SIZE>::type ltype;
1263 return ltype::notEqual(l.
begin(), r.
begin());
1267 template <
class V1,
int SIZE,
class D1,
class D2,
class V2,
class D3,
class D4>
1269 operator<(TinyVectorBase<V1, SIZE, D1, D2>
const & l,
1272 typedef typename detail::LoopType<SIZE>::type ltype;
1273 return ltype::less(l.begin(), r.begin());
1276 template <
class V,
int SIZE,
class D1,
class D2,
class D3,
class D4>
1280 V epsilon = NumericTraits<V>::epsilon())
1282 typedef typename detail::LoopType<SIZE>::type ltype;
1283 return ltype::closeAtTolerance(l.
begin(), r.
begin(), epsilon);
1286 template <
class V,
int SIZE>
1290 V epsilon = NumericTraits<V>::epsilon())
1292 typedef typename detail::LoopType<SIZE>::type ltype;
1293 return ltype::closeAtTolerance(l.
begin(), r.
begin(), epsilon);
1303 template <
class V1,
int SIZE,
class DATA,
class DERIVED>
1305 operator<<(std::ostream & out, TinyVectorBase<V1, SIZE, DATA, DERIVED>
const & l)
1309 for(i=0; i<SIZE-1; ++i)
1310 out << l[i] <<
", ";
1368 #if !defined(NO_PARTIAL_TEMPLATE_SPECIALIZATION) 1370 template <
class T,
int SIZE>
1371 struct NumericTraits<TinyVector<T, SIZE> >
1377 typedef T ValueType;
1379 typedef typename NumericTraits<T>::isIntegral isIntegral;
1380 typedef VigraFalseType isScalar;
1381 typedef typename NumericTraits<T>::isSigned isSigned;
1382 typedef VigraTrueType isOrdered;
1383 typedef VigraFalseType isComplex;
1407 template <
class D1,
class D2>
1413 template <
class D1,
class D2>
1416 return RealPromote(v);
1419 template <
class D1,
class D2>
1421 fromPromote(
TinyVectorBase<
typename NumericTraits<T>::Promote, SIZE, D1, D2>
const & v)
1424 typedef typename detail::LoopType<SIZE>::type ltype;
1429 template <
class D1,
class D2>
1431 fromRealPromote(
TinyVectorBase<
typename NumericTraits<T>::RealPromote, SIZE, D1, D2>
const & v)
1434 typedef typename detail::LoopType<SIZE>::type ltype;
1435 ltype::fromRealPromote(res.
begin(), v.
begin());
1440 template <
class T,
int SIZE>
1441 struct NumericTraits<TinyVectorView<T, SIZE> >
1442 :
public NumericTraits<TinyVector<T, SIZE> >
1448 typedef T ValueType;
1450 typedef typename NumericTraits<T>::isIntegral isIntegral;
1451 typedef VigraFalseType isScalar;
1452 typedef typename NumericTraits<T>::isSigned isSigned;
1453 typedef VigraFalseType isOrdered;
1454 typedef VigraFalseType isComplex;
1457 template <
class T,
int SIZE>
1458 struct NormTraits<TinyVector<T, SIZE> >
1461 typedef typename Type::SquaredNormType SquaredNormType;
1462 typedef typename Type::NormType NormType;
1465 template <
class T,
int SIZE>
1466 struct NormTraits<TinyVectorView<T, SIZE> >
1469 typedef typename Type::SquaredNormType SquaredNormType;
1470 typedef typename Type::NormType NormType;
1473 template <
class T1,
class T2,
int SIZE>
1474 struct PromoteTraits<TinyVector<T1, SIZE>, TinyVector<T2, SIZE> >
1479 template <
class T1,
class T2,
int SIZE>
1480 struct PromoteTraits<TinyVectorView<T1, SIZE>, TinyVectorView<T2, SIZE> >
1485 template <
class T1,
class T2,
int SIZE>
1486 struct PromoteTraits<TinyVectorView<T1, SIZE>, TinyVector<T2, SIZE> >
1491 template <
class T1,
class T2,
int SIZE>
1492 struct PromoteTraits<TinyVector<T1, SIZE>, TinyVectorView<T2, SIZE> >
1497 template <
class T,
int SIZE>
1498 struct PromoteTraits<TinyVector<T, SIZE>, double >
1503 template <
class T,
int SIZE>
1504 struct PromoteTraits<double, TinyVector<T, SIZE> >
1509 template <
class T,
int SIZE>
1510 struct PromoteTraits<TinyVectorView<T, SIZE>, double >
1515 template <
class T,
int SIZE>
1516 struct PromoteTraits<double, TinyVectorView<T, SIZE> >
1521 template<
class T,
int SIZE>
1522 struct CanSkipInitialization<TinyVectorView<T, SIZE> >
1524 typedef typename CanSkipInitialization<T>::type type;
1525 static const bool value = type::asBool;
1528 template<
class T,
int SIZE>
1529 struct CanSkipInitialization<TinyVector<T, SIZE> >
1531 typedef typename CanSkipInitialization<T>::type type;
1532 static const bool value = type::asBool;
1537 #else // NO_PARTIAL_TEMPLATE_SPECIALIZATION 1540 #define TINYVECTOR_NUMTRAITS(T, SIZE) \ 1542 struct NumericTraits<TinyVector<T, SIZE> >\ 1544 typedef TinyVector<T, SIZE> Type;\ 1545 typedef TinyVector<NumericTraits<T>::Promote, SIZE> Promote;\ 1546 typedef TinyVector<NumericTraits<T>::RealPromote, SIZE> RealPromote;\ 1547 typedef TinyVector<NumericTraits<T>::ComplexPromote, SIZE> ComplexPromote;\ 1548 typedef T ValueType; \ 1549 typedef NumericTraits<T>::isIntegral isIntegral;\ 1550 typedef VigraFalseType isScalar;\ 1551 typedef NumericTraits<T>::isSigned isSigned; \ 1552 typedef VigraFalseType isOrdered;\ 1553 typedef VigraFalseType isComplex;\ 1555 static TinyVector<T, SIZE> zero() { \ 1556 return TinyVector<T, SIZE>(NumericTraits<T>::zero()); \ 1558 static TinyVector<T, SIZE> one() { \ 1559 return TinyVector<T, SIZE>(NumericTraits<T>::one()); \ 1561 static TinyVector<T, SIZE> nonZero() { \ 1562 return TinyVector<T, SIZE>(NumericTraits<T>::nonZero()); \ 1565 static Promote toPromote(TinyVector<T, SIZE> const & v) { \ 1566 return Promote(v); \ 1568 static RealPromote toRealPromote(TinyVector<T, SIZE> const & v) { \ 1569 return RealPromote(v); \ 1571 static TinyVector<T, SIZE> fromPromote(Promote const & v) { \ 1572 TinyVector<T, SIZE> res;\ 1573 TinyVector<T, SIZE>::iterator d = res.begin(), dend = res.end();\ 1574 Promote::const_iterator s = v.begin();\ 1575 for(; d != dend; ++d, ++s)\ 1576 *d = NumericTraits<T>::fromPromote(*s);\ 1579 static TinyVector<T, SIZE> fromRealPromote(RealPromote const & v) {\ 1580 TinyVector<T, SIZE> res;\ 1581 TinyVector<T, SIZE>::iterator d = res.begin(), dend = res.end();\ 1582 RealPromote::const_iterator s = v.begin();\ 1583 for(; d != dend; ++d, ++s)\ 1584 *d = NumericTraits<T>::fromRealPromote(*s);\ 1589 struct NormTraits<TinyVector<T, SIZE> >\ 1591 typedef TinyVector<T, SIZE> Type;\ 1592 typedef Type::SquaredNormType SquaredNormType; \ 1593 typedef Type::NormType NormType; \ 1596 #define TINYVECTOR_PROMTRAITS1(type1, SIZE) \ 1598 struct PromoteTraits<TinyVector<type1, SIZE>, TinyVector<type1, SIZE> > \ 1600 typedef TinyVector<PromoteTraits<type1, type1>::Promote, SIZE> Promote; \ 1601 static Promote toPromote(TinyVector<type1, SIZE> const & v) { \ 1602 return static_cast<Promote>(v); } \ 1605 #define TINYVECTOR_PROMTRAITS2(type1, type2, SIZE) \ 1607 struct PromoteTraits<TinyVector<type1, SIZE>, TinyVector<type2, SIZE> > \ 1609 typedef TinyVector<PromoteTraits<type1, type2>::Promote, SIZE> Promote; \ 1610 static Promote toPromote(TinyVector<type1, SIZE> const & v) { \ 1611 return static_cast<Promote>(v); } \ 1612 static Promote toPromote(TinyVector<type2, SIZE> const & v) { \ 1613 return static_cast<Promote>(v); } \ 1616 #define TINYVECTOR_TRAITS(SIZE) \ 1617 TINYVECTOR_NUMTRAITS(unsigned char, SIZE)\ 1618 TINYVECTOR_NUMTRAITS(int, SIZE)\ 1619 TINYVECTOR_NUMTRAITS(float, SIZE)\ 1620 TINYVECTOR_NUMTRAITS(double, SIZE)\ 1621 TINYVECTOR_PROMTRAITS1(unsigned char, SIZE)\ 1622 TINYVECTOR_PROMTRAITS1(int, SIZE)\ 1623 TINYVECTOR_PROMTRAITS1(float, SIZE)\ 1624 TINYVECTOR_PROMTRAITS1(double, SIZE)\ 1625 TINYVECTOR_PROMTRAITS2(float, unsigned char, SIZE)\ 1626 TINYVECTOR_PROMTRAITS2(unsigned char, float, SIZE)\ 1627 TINYVECTOR_PROMTRAITS2(int, unsigned char, SIZE)\ 1628 TINYVECTOR_PROMTRAITS2(unsigned char, int, SIZE)\ 1629 TINYVECTOR_PROMTRAITS2(int, float, SIZE)\ 1630 TINYVECTOR_PROMTRAITS2(float, int, SIZE)\ 1631 TINYVECTOR_PROMTRAITS2(double, unsigned char, SIZE)\ 1632 TINYVECTOR_PROMTRAITS2(unsigned char, double, SIZE)\ 1633 TINYVECTOR_PROMTRAITS2(int, double, SIZE)\ 1634 TINYVECTOR_PROMTRAITS2(double, int, SIZE)\ 1635 TINYVECTOR_PROMTRAITS2(double, float, SIZE)\ 1636 TINYVECTOR_PROMTRAITS2(float, double, SIZE) 1638 TINYVECTOR_TRAITS(2)
1639 TINYVECTOR_TRAITS(3)
1640 TINYVECTOR_TRAITS(4)
1642 #undef TINYVECTOR_NUMTRAITS 1643 #undef TINYVECTOR_PROMTRAITS1 1644 #undef TINYVECTOR_PROMTRAITS2 1645 #undef TINYVECTOR_TRAITS 1647 #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION 1661 template <
class V1,
int SIZE,
class D1,
class D2,
class V2,
class D3,
class D4>
1671 template <
class V1,
int SIZE,
class D1,
class D2,
class V2,
class D3,
class D4>
1681 template <
class V1,
int SIZE,
class D1,
class D2,
class V2,
class D3,
class D4>
1691 template <
class V1,
int SIZE,
class D1,
class D2,
class V2,
class D3,
class D4>
1701 template <
class V1,
int SIZE,
class D1,
class D2,
class V2,
class D3,
class D4>
1711 template <
class V,
int SIZE,
class D1,
class D2>
1713 typename NumericTraits<TinyVector<V, SIZE> >::RealPromote
1716 return typename NumericTraits<TinyVector<V, SIZE> >::RealPromote(r) *= v;
1720 template <
class V,
int SIZE,
class D1,
class D2>
1722 typename NumericTraits<TinyVector<V, SIZE> >::RealPromote
1725 return typename NumericTraits<TinyVector<V, SIZE> >::RealPromote(l) *= v;
1729 template <
class V,
int SIZE,
class D1,
class D2>
1731 typename NumericTraits<TinyVector<V, SIZE> >::RealPromote
1734 return typename NumericTraits<TinyVector<V, SIZE> >::RealPromote(l) /= v;
1738 template <
class V,
int SIZE,
class D1,
class D2>
1744 typedef typename detail::LoopType<SIZE>::type Loop;
1745 Loop::divScalar(result.data(), v);
1752 template <
class V,
int SIZE,
class D1,
class D2>
1758 typedef typename detail::LoopType<SIZE>::type ltype;
1764 template <
class V,
int SIZE,
class D1,
class D2>
1770 typedef typename detail::LoopType<SIZE>::type ltype;
1777 template <
class V,
int SIZE,
class D1,
class D2>
1783 typedef typename detail::LoopType<SIZE>::type ltype;
1790 template <
class V,
int SIZE,
class D1,
class D2>
1796 typedef typename detail::LoopType<SIZE>::type ltype;
1803 template <
class V,
int SIZE,
class D1,
class D2>
1809 typedef typename detail::LoopType<SIZE>::type ltype;
1816 template <
class V,
int SIZE,
class D1,
class D2>
1822 typedef typename detail::LoopType<SIZE>::type ltype;
1831 template <
class V,
int SIZE,
class D1,
class D2,
class E>
1837 typedef typename detail::LoopType<SIZE>::type ltype;
1843 template <
class V1,
class D1,
class D2,
class V2,
class D3,
class D4>
1851 return Res(r1[1]*r2[2] - r1[2]*r2[1],
1852 r1[2]*r2[0] - r1[0]*r2[2],
1853 r1[0]*r2[1] - r1[1]*r2[0]);
1857 template <
class V1,
int SIZE,
class D1,
class D2,
class V2,
class D3,
class D4>
1859 typename PromoteTraits<V1, V2>::Promote
1863 typedef typename detail::LoopType<SIZE>::type ltype;
1868 template <
class V,
int SIZE,
class D1,
class D2>
1870 typename NumericTraits<V>::Promote
1873 typename NumericTraits<V>::Promote res = l[0];
1874 for(
int k=1; k<SIZE; ++k)
1880 template <
class V,
int SIZE,
class D1,
class D2>
1885 TinyVector<typename NumericTraits<V>::Promote, SIZE> res(l);
1886 for(
int k=1; k<SIZE; ++k)
1892 template <
class V,
int SIZE,
class D1,
class D2>
1894 typename NumericTraits<V>::Promote
1897 typename NumericTraits<V>::Promote res = l[0];
1898 for(
int k=1; k<SIZE; ++k)
1904 template <
class V,
int SIZE,
class D1,
class D2>
1906 TinyVector<typename NumericTraits<V>::Promote, SIZE>
1909 TinyVector<typename NumericTraits<V>::Promote, SIZE> res(l);
1910 for(
int k=1; k<SIZE; ++k)
1918 template <
class V1,
int SIZE,
class D1,
class D2,
class V2,
class D3,
class D4>
1924 typedef typename detail::LoopType<SIZE>::type ltype;
1925 TinyVector<typename PromoteTraits<V1, V2>::Promote, SIZE> res(l);
1931 template <
class V1,
int SIZE,
class D1,
class D2>
1937 typedef typename detail::LoopType<SIZE>::type ltype;
1943 template <
class V1,
int SIZE>
1949 typedef typename detail::LoopType<SIZE>::type ltype;
1956 template <
class V,
int SIZE,
class D1,
class D2>
1967 template <
class V1,
int SIZE,
class D1,
class D2,
class V2,
class D3,
class D4>
1969 TinyVector<typename PromoteTraits<V1, V2>::Promote, SIZE>
1973 typedef typename detail::LoopType<SIZE>::type ltype;
1974 TinyVector<typename PromoteTraits<V1, V2>::Promote, SIZE> res(l);
1980 template <
class V1,
int SIZE,
class D1,
class D2>
1986 typedef typename detail::LoopType<SIZE>::type ltype;
1992 template <
class V1,
int SIZE>
1998 typedef typename detail::LoopType<SIZE>::type ltype;
2005 template <
class V,
int SIZE,
class D1,
class D2>
2014 template <
class V1,
int SIZE,
class D1,
class D2>
2023 template <
class V,
int SIZE>
2025 typename TinyVector<V, SIZE>::SquaredNormType
2034 template <
class V,
int SIZE>
2045 #if defined(_MSC_VER) 2046 #pragma warning( pop ) 2050 #undef VIGRA_ASSERT_INSIDE 2051 #endif // VIGRA_TINYVECTOR_HXX NormType magnitude() const
Definition: tinyvector.hxx:776
const_reference operator[](difference_type i) const
Definition: tinyvector.hxx:827
DERIVED & operator/=(double r)
Definition: tinyvector.hxx:768
TinyVector< V, SIZE > operator-(TinyVectorBase< V, SIZE, D1, D2 > const &v)
Definition: tinyvector.hxx:1755
TinyVectorView & operator=(TinyVectorView const &r)
Definition: tinyvector.hxx:1214
bool all() const
Definition: tinyvector.hxx:805
TinyVector(value_type const &initial)
Definition: tinyvector.hxx:940
int y
Definition: diff2d.hxx:392
VALUETYPE * pointer
Definition: tinyvector.hxx:658
value_type const * const_iterator
Definition: tinyvector.hxx:670
double scalar_multiplier
Definition: tinyvector.hxx:682
VALUETYPE const * const_pointer
Definition: tinyvector.hxx:662
TinyVector(TinyVector const &r)
Definition: tinyvector.hxx:1036
TinyVector< V, SIZE > round(TinyVectorBase< V, SIZE, D1, D2 > const &v)
Definition: tinyvector.hxx:1806
DERIVED & operator+=(TinyVectorBase< T1, SIZE, D1, D2 > const &r)
Definition: tinyvector.hxx:716
TinyVector(TinyVectorBase< U, SIZE, DATA, DERIVED > const &r)
Definition: tinyvector.hxx:1068
void sub(FixedPoint< IntBits1, FracBits1 > l, FixedPoint< IntBits2, FracBits2 > r, FixedPoint< IntBits3, FracBits3 > &result)
subtraction with enforced result type.
Definition: fixedpoint.hxx:583
TinyVector< V, SIZE > div(TinyVectorBase< V, SIZE, D1, D2 > const &l, V v)
component-wise scalar division without type promotion
Definition: tinyvector.hxx:1741
TinyVector(value_type const &i1, value_type const &i2, value_type const &i3, value_type const &i4, value_type const &i5)
Definition: tinyvector.hxx:1004
int x
Definition: diff2d.hxx:385
bool operator!=(TinyVectorBase< V1, SIZE, D1, D2 > const &l, TinyVectorBase< V2, SIZE, D3, D4 > const &r)
component-wise not equal
Definition: tinyvector.hxx:1259
V power(const V &x)
Exponentiation to a positive integer power by squaring.
Definition: mathutil.hxx:389
const_iterator begin() const
Definition: tinyvector.hxx:842
const_iterator end() const
Definition: tinyvector.hxx:846
iterator end()
Definition: tinyvector.hxx:838
Two dimensional difference vector.
Definition: diff2d.hxx:185
NumericTraits< TinyVector< V, SIZE > >::RealPromote operator*(TinyVectorBase< V, SIZE, D1, D2 > const &l, double v)
component-wise right scalar multiplication
Definition: tinyvector.hxx:1723
void add(FixedPoint< IntBits1, FracBits1 > l, FixedPoint< IntBits2, FracBits2 > r, FixedPoint< IntBits3, FracBits3 > &result)
addition with enforced result type.
Definition: fixedpoint.hxx:561
TinyVector< V, SIZE > ceil(TinyVectorBase< V, SIZE, D1, D2 > const &v)
Definition: tinyvector.hxx:1780
SquaredNormType squaredMagnitude() const
Definition: tinyvector.hxx:784
TinyVector(Diff2D const &initial)
Definition: tinyvector.hxx:960
Definition: accessor.hxx:43
TinyVector(const_pointer data, ReverseCopyTag)
Definition: tinyvector.hxx:1059
DERIVED & operator/=(TinyVectorBase< T1, SIZE, D1, D2 > const &r)
Definition: tinyvector.hxx:743
TinyVector< V, SIZE > sqrt(TinyVectorBase< V, SIZE, D1, D2 > const &v)
Definition: tinyvector.hxx:1819
TinyVector & copy(TinyVectorBase< U, USIZE, DATA, DERIVED > const &r)
Definition: tinyvector.hxx:1115
value_type * iterator
Definition: tinyvector.hxx:666
PromoteTraits< TinyVector< V1, SIZE >, TinyVector< V2, SIZE > >::Promote operator+(TinyVectorBase< V1, SIZE, D1, D2 > const &l, TinyVectorBase< V2, SIZE, D3, D4 > const &r)
component-wise addition
Definition: tinyvector.hxx:1664
DERIVED & operator*=(double r)
Definition: tinyvector.hxx:760
Definition: graphs.hxx:226
DERIVED & operator-=(TinyVectorBase< T1, SIZE, D1, D2 > const &r)
Definition: tinyvector.hxx:725
TinyVector & operator=(TinyVector const &r)
Definition: tinyvector.hxx:1076
TinyVector()
Definition: tinyvector.hxx:1018
VALUETYPE value_type
Definition: tinyvector.hxx:646
void mul(FixedPoint< IntBits1, FracBits1 > l, FixedPoint< IntBits2, FracBits2 > r, FixedPoint< IntBits3, FracBits3 > &result)
multiplication with enforced result type.
Definition: fixedpoint.hxx:605
NumericTraits< V >::Promote prod(TinyVectorBase< V, SIZE, D1, D2 > const &l)
product of the vector's elements
Definition: tinyvector.hxx:1895
TinyVectorView(TinyVectorBase< T, SIZE, DATA, DERIVED > const &other)
Definition: tinyvector.hxx:1206
NumericTraits< V >::Promote sum(TinyVectorBase< V, SIZE, D1, D2 > const &l)
sum of the vector's elements
Definition: tinyvector.hxx:1871
TinyVector(value_type const &i1, value_type const &i2, value_type const &i3, value_type const &i4)
Definition: tinyvector.hxx:991
TinyVectorView()
Definition: tinyvector.hxx:1181
void init(value_type initial)
Definition: tinyvector.hxx:708
NumericTraits< TinyVector< V, SIZE > >::RealPromote operator/(TinyVectorBase< V, SIZE, D1, D2 > const &l, double v)
component-wise scalar division
Definition: tinyvector.hxx:1732
VALUETYPE & reference
Definition: tinyvector.hxx:650
iterator begin()
Definition: tinyvector.hxx:835
size_type size() const
Definition: tinyvector.hxx:865
TinyVector< V, SIZE > pow(TinyVectorBase< V, SIZE, D1, D2 > const &v, E exponent)
Definition: tinyvector.hxx:1834
VALUETYPE const & const_reference
Definition: tinyvector.hxx:654
TinyVector & operator=(value_type const &v)
Definition: tinyvector.hxx:1104
TinyVector< V, SIZE >::SquaredNormType squaredNorm(TinyVector< V, SIZE > const &t)
squared norm
Definition: tinyvector.hxx:2026
TinyVector(value_type const &i1, value_type const &i2, value_type const &i3)
Definition: tinyvector.hxx:980
TinyVector(SkipInitializationTag)
Definition: tinyvector.hxx:1026
TinyVectorView & operator=(TinyVectorBase< U, SIZE, DATA, DERIVED > const &r)
Definition: tinyvector.hxx:1223
V const & max(TinyVectorBase< V, SIZE, D1, D2 > const &l)
maximum element
Definition: tinyvector.hxx:2008
TinyVector< typename NumericTraits< V >::Promote, SIZE > cumsum(TinyVectorBase< V, SIZE, D1, D2 > const &l)
cumulative sum of the vector's elements
Definition: tinyvector.hxx:1883
Wrapper for fixed size vectors.
Definition: tinyvector.hxx:612
Class for fixed size vectors.This class contains an array of size SIZE of the specified VALUETYPE...
Definition: accessor.hxx:940
unsigned int size_type
Definition: tinyvector.hxx:674
TinyVectorView< VALUETYPE, TO-FROM > subarray() const
Definition: tinyvector.hxx:853
TinyVectorView(TinyVectorView const &other)
Definition: tinyvector.hxx:1197
Base class for fixed size vectors.
Definition: tinyvector.hxx:81
TinyVector< V, SIZE > floor(TinyVectorBase< V, SIZE, D1, D2 > const &v)
Definition: tinyvector.hxx:1793
TinyVector(U const *data)
Definition: tinyvector.hxx:1045
SquareRootTraits< SquaredNormType >::SquareRootResult NormType
Definition: tinyvector.hxx:690
VALUETYPE const & maximum() const
Definition: tinyvector.hxx:798
std::ptrdiff_t difference_type
Definition: tinyvector.hxx:678
TinyVector< typename PromoteTraits< V1, V2 >::Promote, 3 > cross(TinyVectorBase< V1, 3, D1, D2 > const &r1, TinyVectorBase< V2, 3, D3, D4 > const &r2)
cross product
Definition: tinyvector.hxx:1846
bool any() const
Definition: tinyvector.hxx:812
TinyVector(value_type const &i1, value_type const &i2)
Definition: tinyvector.hxx:970
TinyVector< V, SIZE > reverse(TinyVector< V, SIZE > const &t)
reversed copy
Definition: tinyvector.hxx:2037
TinyVectorView(const_pointer data)
Definition: tinyvector.hxx:1189
TinyVector & operator=(TinyVectorBase< U, SIZE, DATA, DERIVED > const &r)
Definition: tinyvector.hxx:1085
TinyVector< typename NumericTraits< V >::Promote, SIZE > cumprod(TinyVectorBase< V, SIZE, D1, D2 > const &l)
cumulative product of the vector's elements
Definition: tinyvector.hxx:1907
VALUETYPE const & minimum() const
Definition: tinyvector.hxx:791
DERIVED & operator%=(TinyVectorBase< T1, SIZE, D1, D2 > const &r)
Definition: tinyvector.hxx:752
void init(Iterator i, Iterator end)
Definition: tinyvector.hxx:699
TinyVector< V, SIZE > abs(TinyVectorBase< V, SIZE, D1, D2 > const &v)
component-wise absolute value
Definition: tinyvector.hxx:1767
NormTraits< VALUETYPE >::SquaredNormType SquaredNormType
Definition: tinyvector.hxx:686
DERIVED & operator*=(TinyVectorBase< T1, SIZE, D1, D2 > const &r)
Definition: tinyvector.hxx:734
TinyVector & operator=(Diff2D const &r)
Definition: tinyvector.hxx:1095
reference operator[](difference_type i)
Definition: tinyvector.hxx:819
PromoteTraits< TinyVector< V1, SIZE >, TinyVector< V2, SIZE > >::Promote operator%(TinyVectorBase< V1, SIZE, D1, D2 > const &l, TinyVectorBase< V2, SIZE, D3, D4 > const &r)
component-wise modulo
Definition: tinyvector.hxx:1704
TinyVector(lemon::Invalid const &)
Definition: tinyvector.hxx:950
V const & min(TinyVectorBase< V, SIZE, D1, D2 > const &l)
minimum element
Definition: tinyvector.hxx:1959
bool operator==(TinyVectorBase< V1, SIZE, D1, D2 > const &l, TinyVectorBase< V2, SIZE, D3, D4 > const &r)
component-wise equal
Definition: tinyvector.hxx:1250
PromoteTraits< V1, V2 >::Promote dot(TinyVectorBase< V1, SIZE, D1, D2 > const &l, TinyVectorBase< V2, SIZE, D3, D4 > const &r)
dot product
Definition: tinyvector.hxx:1860