21 #include <type_traits>
201 #if (VTKM_SIZE_LONG_LONG == 8) || defined(VTKM_DOXYGEN_ONLY)
202 using Int64 =
signed long long;
208 #define VTKM_UNUSED_INT_TYPE long
209 #elif VTKM_SIZE_LONG == 8
210 using Int64 =
signed long;
215 using UInt64 =
unsigned long;
216 #define VTKM_UNUSED_INT_TYPE long long
218 #error Could not find a 64-bit integer.
226 #ifdef VTKM_USE_64BIT_IDS
233 #ifdef VTKM_USE_DOUBLE_PRECISION
256 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
257 #pragma GCC diagnostic push
258 #pragma GCC diagnostic ignored "-Wconversion"
259 #endif // gcc || clang
262 template <
typename T,
typename U>
271 template <
typename T>
273 typename std::enable_if<std::is_integral<T>::value &&
sizeof(T) <
sizeof(
int), T>::type
276 return static_cast<T
>(a + b);
282 template <
typename T,
typename U>
291 template <
typename T>
293 typename std::enable_if<std::is_integral<T>::value &&
sizeof(T) <
sizeof(
int), T>::type
296 return static_cast<T
>(a - b);
302 template <
typename T,
typename U>
311 template <
typename T>
313 typename std::enable_if<std::is_integral<T>::value &&
sizeof(T) <
sizeof(
int), T>::type
316 return static_cast<T
>(a * b);
322 template <
typename T,
typename U>
331 template <
typename T>
333 typename std::enable_if<std::is_integral<T>::value &&
sizeof(T) <
sizeof(
int), T>::type
336 return static_cast<T
>(a / b);
342 template <
typename T>
349 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
350 #pragma GCC diagnostic pop
351 #endif // gcc || clang
356 template <
typename T, vtkm::IdComponent Size>
359 template <
typename T>
362 template <
typename T>
380 #if (defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8))
381 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
382 #pragma GCC diagnostic push
383 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
384 #pragma GCC diagnostic ignored "-Wpragmas"
385 #pragma GCC diagnostic ignored "-Wconversion"
386 #pragma GCC diagnostic ignored "-Wfloat-conversion"
387 #endif // gcc || clang
388 #endif // use cuda < 8
389 template <
typename T,
typename DerivedClass>
396 constexpr VecBaseCommon() =
default;
399 constexpr
const DerivedClass& Derived()
const {
return *
static_cast<const DerivedClass*
>(
this); }
402 constexpr DerivedClass& Derived() {
return *
static_cast<DerivedClass*
>(
this); }
409 return this->Derived().GetNumberOfComponents();
414 constexpr
const T& Component(
vtkm::IdComponent index)
const {
return this->Derived()[index]; }
418 constexpr T& Component(
vtkm::IdComponent index) {
return this->Derived()[index]; }
421 template <vtkm::IdComponent OtherSize>
424 for (
vtkm::IdComponent index = 0; (index < this->NumComponents()) && (index < OtherSize);
427 dest[index] = this->Component(index);
432 template <
typename OtherVecType>
435 VTKM_ASSERT(this->NumComponents() == src.GetNumberOfComponents());
438 this->Component(i) = src[i];
440 return this->Derived();
444 bool operator==(
const DerivedClass& other)
const
449 equal = (this->Component(i) == other[i]);
455 bool operator<(
const DerivedClass& other)
const
460 if (this->Component(i) < other[i])
464 else if (other[i] < this->Component(i))
476 #if (!(defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8)))
477 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
478 #pragma GCC diagnostic push
479 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
480 #pragma GCC diagnostic ignored "-Wpragmas"
481 #pragma GCC diagnostic ignored "-Wconversion"
482 #pragma GCC diagnostic ignored "-Wfloat-conversion"
483 #endif // gcc || clang
484 #endif // not using cuda < 8
486 template <vtkm::IdComponent Size>
494 result[i] = this->Component(i) + other[i];
499 template <
typename OtherClass>
500 inline VTKM_EXEC_CONT DerivedClass& operator+=(
const OtherClass& other)
502 VTKM_ASSERT(this->NumComponents() == other.GetNumberOfComponents());
505 this->Component(i) += other[i];
507 return this->Derived();
510 template <vtkm::IdComponent Size>
518 result[i] = this->Component(i) - other[i];
523 template <
typename OtherClass>
524 inline VTKM_EXEC_CONT DerivedClass& operator-=(
const OtherClass& other)
526 VTKM_ASSERT(this->NumComponents() == other.GetNumberOfComponents());
529 this->Component(i) -= other[i];
531 return this->Derived();
534 template <vtkm::IdComponent Size>
541 result[i] = this->Component(i) * other[i];
546 template <
typename OtherClass>
547 inline VTKM_EXEC_CONT DerivedClass& operator*=(
const OtherClass& other)
549 VTKM_ASSERT(this->NumComponents() == other.GetNumberOfComponents());
552 this->Component(i) *= other[i];
554 return this->Derived();
557 template <vtkm::IdComponent Size>
564 result[i] = this->Component(i) / other[i];
569 template <
typename OtherClass>
572 VTKM_ASSERT(this->NumComponents() == other.GetNumberOfComponents());
575 this->Component(i) /= other[i];
577 return this->Derived();
580 #if (!(defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8)))
581 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
582 #pragma GCC diagnostic pop
583 #endif // gcc || clang
584 #endif // not using cuda < 8
587 constexpr ComponentType* GetPointer() {
return &this->Component(0); }
590 constexpr
const ComponentType* GetPointer()
const {
return &this->Component(0); }
596 template <
typename T, vtkm::IdComponent Size,
typename DerivedClass>
597 class VTKM_ALWAYS_EXPORT VecBase :
public vtkm::detail::VecBaseCommon<T, DerivedClass>
600 using ComponentType = T;
608 template <vtkm::IdComponent Size2 = Size, typename std::enable_if<Size2 != 1, int>::type = 0>
613 this->Components[i] = value;
618 template <
typename... Ts>
619 VTKM_EXEC_CONT constexpr VecBase(ComponentType value0, Ts&&... values)
620 : Components{ value0, values... }
627 VecBase(std::initializer_list<ComponentType> values)
629 ComponentType* dest = this->Components;
630 auto src = values.begin();
631 if (values.size() == 1)
635 this->Components[i] = *src;
642 "Vec object initialized wrong number of components.");
643 for (; src != values.end(); ++src)
651 #if (!(defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8)))
652 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
653 #pragma GCC diagnostic push
654 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
655 #pragma GCC diagnostic ignored "-Wpragmas"
656 #pragma GCC diagnostic ignored "-Wconversion"
657 #pragma GCC diagnostic ignored "-Wfloat-conversion"
658 #endif // gcc || clang
659 #endif //not using cuda < 8
660 #if defined(VTKM_MSVC)
661 #pragma warning(push)
662 #pragma warning(disable : 4244)
666 template <
typename OtherValueType,
typename OtherDerivedType>
667 VTKM_EXEC_CONT explicit VecBase(
const VecBase<OtherValueType, Size, OtherDerivedType>& src)
673 this->Components[i] = src[i];
680 return NUM_COMPONENTS;
685 return this->Components[idx];
692 return this->Components[idx];
696 template <
typename OtherComponentType,
typename OtherClass>
698 operator+(
const VecBaseCommon<OtherComponentType, OtherClass>& other)
const
700 const OtherClass& other_derived =
static_cast<const OtherClass&
>(other);
701 VTKM_ASSERT(NUM_COMPONENTS == other_derived.GetNumberOfComponents());
706 result[i] = this->Components[i] +
static_cast<ComponentType
>(other_derived[i]);
712 template <
typename OtherComponentType,
typename OtherClass>
714 operator-(
const VecBaseCommon<OtherComponentType, OtherClass>& other)
const
716 const OtherClass& other_derived =
static_cast<const OtherClass&
>(other);
717 VTKM_ASSERT(NUM_COMPONENTS == other_derived.GetNumberOfComponents());
722 result[i] = this->Components[i] -
static_cast<ComponentType
>(other_derived[i]);
728 template <
typename OtherComponentType,
typename OtherClass>
730 operator*(
const VecBaseCommon<OtherComponentType, OtherClass>& other)
const
732 const OtherClass& other_derived =
static_cast<const OtherClass&
>(other);
733 VTKM_ASSERT(NUM_COMPONENTS == other_derived.GetNumberOfComponents());
738 result[i] = this->Components[i] *
static_cast<ComponentType
>(other_derived[i]);
744 template <
typename OtherComponentType,
typename OtherClass>
746 operator/(
const VecBaseCommon<OtherComponentType, OtherClass>& other)
const
748 const OtherClass& other_derived =
static_cast<const OtherClass&
>(other);
749 VTKM_ASSERT(NUM_COMPONENTS == other_derived.GetNumberOfComponents());
754 result[i] = this->Components[i] /
static_cast<ComponentType
>(other_derived[i]);
759 #if (!(defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8)))
760 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
761 #pragma GCC diagnostic pop
762 #endif // gcc || clang
763 #endif // not using cuda < 8
764 #if defined(VTKM_MSVC)
769 ComponentType Components[NUM_COMPONENTS];
772 #if (defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8))
773 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
774 #pragma GCC diagnostic pop
775 #endif // gcc || clang
776 #endif // use cuda < 8
780 template <
typename T,
typename DerivedClass>
781 class VTKM_ALWAYS_EXPORT VecCBase :
public vtkm::detail::VecBaseCommon<T, DerivedClass>
785 constexpr VecCBase() {}
807 template <
typename T, vtkm::IdComponent Size>
813 #ifdef VTKM_DOXYGEN_ONLY
818 using Superclass::Superclass;
819 constexpr
Vec() =
default;
820 #if defined(_MSC_VER) && _MSC_VER < 1910
821 template <
typename... Ts>
822 constexpr
Vec(T value, Ts&&... values)
823 :
Superclass(value, std::forward<Ts>(values)...)
837 template <
typename T>
844 constexpr
Vec() =
default;
847 template <
typename OtherType>
860 return NUM_COMPONENTS;
877 template <
typename T>
889 template <
typename OtherType>
899 template <
typename T>
905 constexpr
Vec() =
default;
911 template <
typename OtherType>
918 constexpr
Vec(
const T& x,
const T& y)
985 #ifdef VTKM_USE_64BIT_IDS
1015 template <
typename T>
1021 constexpr
Vec() =
default;
1027 template <
typename OtherType>
1034 constexpr
Vec(
const T& x,
const T& y,
const T& z)
1103 #ifdef VTKM_USE_64BIT_IDS
1133 template <
typename T>
1139 constexpr
Vec() =
default;
1145 template <
typename OtherType>
1152 constexpr
Vec(
const T& x,
const T& y,
const T& z,
const T& w)
1219 #ifdef VTKM_USE_64BIT_IDS
1252 template <
typename T,
typename... Ts>
1277 template <
typename T>
1283 "You cannot use VecC with a const type as its template argument. "
1284 "Use either const VecC or VecCConst.");
1287 #ifdef VTKM_DOXYGEN_ONLY
1293 : Components(nullptr)
1294 , NumberOfComponents(0)
1301 , NumberOfComponents(size)
1305 template <vtkm::IdComponent Size>
1307 : Components(src.GetPointer())
1308 , NumberOfComponents(Size)
1315 , NumberOfComponents(1)
1321 : Components(src.Components)
1322 , NumberOfComponents(src.NumberOfComponents)
1330 return this->Components[index];
1337 return this->Components[index];
1342 return this->NumberOfComponents;
1351 (*this)[index] = src[index];
1371 template <
typename T>
1377 "You cannot use VecCConst with a const type as its template argument. "
1378 "Remove the const from the type.");
1381 #ifdef VTKM_DOXYGEN_ONLY
1387 : Components(nullptr)
1388 , NumberOfComponents(0)
1395 , NumberOfComponents(size)
1399 template <vtkm::IdComponent Size>
1401 : Components(src.GetPointer())
1402 , NumberOfComponents(Size)
1409 , NumberOfComponents(1)
1415 : Components(src.Components)
1416 , NumberOfComponents(src.NumberOfComponents)
1422 : Components(src.Components)
1423 , NumberOfComponents(src.NumberOfComponents)
1431 return this->Components[index];
1436 return this->NumberOfComponents;
1454 template <
typename T>
1462 template <
typename T>
1472 template <
typename T>
1473 static inline VTKM_EXEC_CONT auto vec_dot(
const T& a,
const T& b)
1475 auto result = a[0] * b[0];
1478 result = result + a[i] * b[i];
1482 template <
typename T, vtkm::IdComponent Size>
1485 auto result = a[0] * b[0];
1488 result = result + a[i] * b[i];
1495 template <
typename T>
1498 return detail::vec_dot(a, b);
1501 template <
typename T>
1504 return (a[0] * b[0]) + (a[1] * b[1]);
1506 template <
typename T>
1509 return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]);
1511 template <
typename T>
1514 return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]) + (a[3] * b[3]);
1518 #define VTK_M_SCALAR_DOT(stype) \
1519 static inline VTKM_EXEC_CONT auto dot(stype a, stype b) { return a * b; } \
1520 static inline VTKM_EXEC_CONT auto Dot(stype a, stype b) { return a * b; }
1533 template <
typename T>
1534 static inline VTKM_EXEC_CONT auto dot(
const T& a,
const T& b) -> decltype(detail::vec_dot(a, b))
1536 return vtkm::Dot(a, b);
1538 template <
typename T>
1541 return vtkm::Dot(a, b);
1543 template <
typename T>
1546 return vtkm::Dot(a, b);
1548 template <
typename T>
1551 return vtkm::Dot(a, b);
1555 template <
typename T, vtkm::IdComponent Size>
1566 template <
typename T>
1572 template <
typename T>
1575 return a[0] + a[1] + a[2];
1578 template <
typename T>
1581 return a[0] + a[1] + a[2] + a[3];
1584 template <
typename T, vtkm::IdComponent Size>
1595 template <
typename T>
1601 template <
typename T>
1604 return a[0] * a[1] * a[2];
1607 template <
typename T>
1610 return a[0] * a[1] * a[2] * a[3];
1615 template <
typename U,
typename V>
1620 template <
typename T, vtkm::IdComponent Size>
1626 stream << vec[component] <<
",";
1628 return stream << vec[Size - 1] <<
"]";
1633 template <
typename T,
typename U>
1636 return stream <<
"[" << vec.
first <<
"," << vec.
second <<
"]";
1643 #endif //vtk_m_Types_h