13 #include <vtkm/internal/Configure.h>
21 #include <type_traits>
175 #if VTKM_SIZE_LONG_LONG == 8
176 using Int64 =
signed long long;
177 using UInt64 =
unsigned long long;
178 #define VTKM_UNUSED_INT_TYPE long
179 #elif VTKM_SIZE_LONG == 8
180 using Int64 =
signed long;
181 using UInt64 =
unsigned long;
182 #define VTKM_UNUSED_INT_TYPE long long
184 #error Could not find a 64-bit integer.
188 #ifdef VTKM_USE_64BIT_IDS
189 using Id = vtkm::Int64;
195 #ifdef VTKM_USE_DOUBLE_PRECISION
218 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
219 #pragma GCC diagnostic push
220 #pragma GCC diagnostic ignored "-Wconversion"
221 #endif // gcc || clang
224 template <
typename T,
typename U>
233 template <
typename T>
235 typename std::enable_if<std::is_integral<T>::value &&
sizeof(T) <
sizeof(
int), T>::type
238 return static_cast<T
>(a + b);
244 template <
typename T,
typename U>
253 template <
typename T>
255 typename std::enable_if<std::is_integral<T>::value &&
sizeof(T) <
sizeof(
int), T>::type
258 return static_cast<T
>(a - b);
264 template <
typename T,
typename U>
273 template <
typename T>
275 typename std::enable_if<std::is_integral<T>::value &&
sizeof(T) <
sizeof(
int), T>::type
278 return static_cast<T
>(a * b);
284 template <
typename T,
typename U>
293 template <
typename T>
295 typename std::enable_if<std::is_integral<T>::value &&
sizeof(T) <
sizeof(
int), T>::type
298 return static_cast<T
>(a / b);
304 template <
typename T>
311 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
312 #pragma GCC diagnostic pop
313 #endif // gcc || clang
318 template <
typename T, vtkm::IdComponent Size>
321 template <
typename T>
324 template <
typename T>
342 #if (defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8))
343 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
344 #pragma GCC diagnostic push
345 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
346 #pragma GCC diagnostic ignored "-Wpragmas"
347 #pragma GCC diagnostic ignored "-Wconversion"
348 #pragma GCC diagnostic ignored "-Wfloat-conversion"
349 #endif // gcc || clang
350 #endif // use cuda < 8
351 template <
typename T,
typename DerivedClass>
355 using ComponentType = T;
358 VecBaseCommon() =
default;
361 const DerivedClass& Derived()
const {
return *
static_cast<const DerivedClass*
>(
this); }
364 DerivedClass& Derived() {
return *
static_cast<DerivedClass*
>(
this); }
369 inline vtkm::IdComponent NumComponents()
const {
return this->Derived().GetNumberOfComponents(); }
373 inline const T& Component(
vtkm::IdComponent index)
const {
return this->Derived()[index]; }
380 template <vtkm::IdComponent OtherSize>
383 for (
vtkm::IdComponent index = 0; (index < this->NumComponents()) && (index < OtherSize);
386 dest[index] = this->Component(index);
391 template <
typename OtherVecType>
394 VTKM_ASSERT(this->NumComponents() == src.GetNumberOfComponents());
397 this->Component(i) = src[i];
399 return this->Derived();
403 bool operator==(
const DerivedClass& other)
const
408 equal = (this->Component(i) == other[i]);
414 bool operator<(
const DerivedClass& other)
const
419 if (this->Component(i) < other[i])
423 else if (other[i] < this->Component(i))
435 #if (!(defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8)))
436 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
437 #pragma GCC diagnostic push
438 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
439 #pragma GCC diagnostic ignored "-Wpragmas"
440 #pragma GCC diagnostic ignored "-Wconversion"
441 #pragma GCC diagnostic ignored "-Wfloat-conversion"
442 #endif // gcc || clang
443 #endif // not using cuda < 8
445 template <vtkm::IdComponent Size>
453 result[i] = this->Component(i) + other[i];
458 template <
typename OtherClass>
459 inline VTKM_EXEC_CONT DerivedClass& operator+=(
const OtherClass& other)
461 VTKM_ASSERT(this->NumComponents() == other.GetNumberOfComponents());
464 this->Component(i) += other[i];
466 return this->Derived();
469 template <vtkm::IdComponent Size>
477 result[i] = this->Component(i) - other[i];
482 template <
typename OtherClass>
483 inline VTKM_EXEC_CONT DerivedClass& operator-=(
const OtherClass& other)
485 VTKM_ASSERT(this->NumComponents() == other.GetNumberOfComponents());
488 this->Component(i) -= other[i];
490 return this->Derived();
493 template <vtkm::IdComponent Size>
500 result[i] = this->Component(i) * other[i];
505 template <
typename OtherClass>
506 inline VTKM_EXEC_CONT DerivedClass& operator*=(
const OtherClass& other)
508 VTKM_ASSERT(this->NumComponents() == other.GetNumberOfComponents());
511 this->Component(i) *= other[i];
513 return this->Derived();
516 template <vtkm::IdComponent Size>
523 result[i] = this->Component(i) / other[i];
528 template <
typename OtherClass>
531 VTKM_ASSERT(this->NumComponents() == other.GetNumberOfComponents());
534 this->Component(i) /= other[i];
536 return this->Derived();
539 #if (!(defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8)))
540 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
541 #pragma GCC diagnostic pop
542 #endif // gcc || clang
543 #endif // not using cuda < 8
546 ComponentType* GetPointer() {
return &this->Component(0); }
549 const ComponentType* GetPointer()
const {
return &this->Component(0); }
555 template <
typename T, vtkm::IdComponent Size,
typename DerivedClass>
556 class VTKM_ALWAYS_EXPORT VecBase :
public vtkm::detail::VecBaseCommon<T, DerivedClass>
559 using ComponentType = T;
567 template <vtkm::IdComponent Size2 = Size, typename std::enable_if<Size2 != 1, int>::type = 0>
572 this->Components[i] = value;
577 template <
typename... Ts>
578 VTKM_EXEC_CONT constexpr VecBase(ComponentType value0, Ts&&... values)
579 : Components{ value0, values... }
586 VecBase(std::initializer_list<ComponentType> values)
588 ComponentType* dest = this->Components;
589 auto src = values.begin();
590 if (values.size() == 1)
594 this->Components[i] = *src;
601 "Vec object initialized wrong number of components.");
602 for (; src != values.end(); ++src)
610 #if (!(defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8)))
611 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
612 #pragma GCC diagnostic push
613 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
614 #pragma GCC diagnostic ignored "-Wpragmas"
615 #pragma GCC diagnostic ignored "-Wconversion"
616 #pragma GCC diagnostic ignored "-Wfloat-conversion"
617 #endif // gcc || clang
618 #endif //not using cuda < 8
619 #if defined(VTKM_MSVC)
620 #pragma warning(push)
621 #pragma warning(disable : 4244)
625 template <
typename OtherValueType,
typename OtherDerivedType>
626 VTKM_EXEC_CONT explicit VecBase(
const VecBase<OtherValueType, Size, OtherDerivedType>& src)
632 this->Components[i] = src[i];
639 return NUM_COMPONENTS;
644 return this->Components[idx];
651 return this->Components[idx];
655 template <
typename OtherComponentType,
typename OtherClass>
657 operator+(
const VecBaseCommon<OtherComponentType, OtherClass>& other)
const
659 const OtherClass& other_derived =
static_cast<const OtherClass&
>(other);
660 VTKM_ASSERT(NUM_COMPONENTS == other_derived.GetNumberOfComponents());
665 result[i] = this->Components[i] +
static_cast<ComponentType
>(other_derived[i]);
671 template <
typename OtherComponentType,
typename OtherClass>
673 operator-(
const VecBaseCommon<OtherComponentType, OtherClass>& other)
const
675 const OtherClass& other_derived =
static_cast<const OtherClass&
>(other);
676 VTKM_ASSERT(NUM_COMPONENTS == other_derived.GetNumberOfComponents());
681 result[i] = this->Components[i] -
static_cast<ComponentType
>(other_derived[i]);
687 template <
typename OtherComponentType,
typename OtherClass>
689 operator*(
const VecBaseCommon<OtherComponentType, OtherClass>& other)
const
691 const OtherClass& other_derived =
static_cast<const OtherClass&
>(other);
692 VTKM_ASSERT(NUM_COMPONENTS == other_derived.GetNumberOfComponents());
697 result[i] = this->Components[i] *
static_cast<ComponentType
>(other_derived[i]);
703 template <
typename OtherComponentType,
typename OtherClass>
705 operator/(
const VecBaseCommon<OtherComponentType, OtherClass>& other)
const
707 const OtherClass& other_derived =
static_cast<const OtherClass&
>(other);
708 VTKM_ASSERT(NUM_COMPONENTS == other_derived.GetNumberOfComponents());
713 result[i] = this->Components[i] /
static_cast<ComponentType
>(other_derived[i]);
718 #if (!(defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8)))
719 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
720 #pragma GCC diagnostic pop
721 #endif // gcc || clang
722 #endif // not using cuda < 8
723 #if defined(VTKM_MSVC)
728 ComponentType Components[NUM_COMPONENTS];
731 #if (defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8))
732 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
733 #pragma GCC diagnostic pop
734 #endif // gcc || clang
735 #endif // use cuda < 8
739 template <
typename T,
typename DerivedClass>
740 class VTKM_ALWAYS_EXPORT VecCBase :
public vtkm::detail::VecBaseCommon<T, DerivedClass>
766 template <
typename T, vtkm::IdComponent Size>
772 #ifdef VTKM_DOXYGEN_ONLY
777 using Superclass::Superclass;
779 #if defined(_MSC_VER) && _MSC_VER < 1910
780 template <
typename... Ts>
781 constexpr
Vec(T value, Ts&&... values)
782 :
Superclass(value, std::forward<Ts>(values)...)
796 template <
typename T>
806 template <
typename OtherType>
819 return NUM_COMPONENTS;
836 template <
typename T>
848 template <
typename OtherType>
858 template <
typename T>
870 template <
typename OtherType>
877 constexpr
Vec(
const T& x,
const T& y)
944 #ifdef VTKM_USE_64BIT_IDS
974 template <
typename T>
986 template <
typename OtherType>
993 constexpr
Vec(
const T& x,
const T& y,
const T& z)
1062 #ifdef VTKM_USE_64BIT_IDS
1092 template <
typename T>
1104 template <
typename OtherType>
1111 constexpr
Vec(
const T& x,
const T& y,
const T& z,
const T& w)
1178 #ifdef VTKM_USE_64BIT_IDS
1211 template <
typename T,
typename... Ts>
1236 template <
typename T>
1242 "You cannot use VecC with a const type as its template argument. "
1243 "Use either const VecC or VecCConst.");
1246 #ifdef VTKM_DOXYGEN_ONLY
1252 : Components(nullptr)
1253 , NumberOfComponents(0)
1260 , NumberOfComponents(size)
1264 template <vtkm::IdComponent Size>
1266 : Components(src.GetPointer())
1267 , NumberOfComponents(Size)
1274 , NumberOfComponents(1)
1280 : Components(src.Components)
1281 , NumberOfComponents(src.NumberOfComponents)
1289 return this->Components[index];
1296 return this->Components[index];
1301 return this->NumberOfComponents;
1310 (*this)[index] = src[index];
1330 template <
typename T>
1336 "You cannot use VecCConst with a const type as its template argument. "
1337 "Remove the const from the type.");
1340 #ifdef VTKM_DOXYGEN_ONLY
1346 : Components(nullptr)
1347 , NumberOfComponents(0)
1354 , NumberOfComponents(size)
1358 template <vtkm::IdComponent Size>
1360 : Components(src.GetPointer())
1361 , NumberOfComponents(Size)
1368 , NumberOfComponents(1)
1374 : Components(src.Components)
1375 , NumberOfComponents(src.NumberOfComponents)
1381 : Components(src.Components)
1382 , NumberOfComponents(src.NumberOfComponents)
1390 return this->Components[index];
1395 return this->NumberOfComponents;
1413 template <
typename T>
1421 template <
typename T>
1429 template <
typename T>
1435 using integer_type =
1437 using promote_type =
1438 typename std::conditional<std::is_integral<T>::value, integer_type, float_type>::type;
1440 typename std::conditional<(
sizeof(T) <
sizeof(
vtkm::Float32)), promote_type, T>::type;
1443 template <
typename T>
1444 static inline VTKM_EXEC_CONT typename DotType<typename T::ComponentType>::type vec_dot(
const T& a,
1447 using U =
typename DotType<typename T::ComponentType>::type;
1448 U result = a[0] * b[0];
1451 result = result + a[i] * b[i];
1455 template <
typename T, vtkm::IdComponent Size>
1459 using U =
typename DotType<T>::type;
1460 U result = a[0] * b[0];
1463 result = result + a[i] * b[i];
1469 template <
typename T>
1470 static inline VTKM_EXEC_CONT auto Dot(
const T& a,
const T& b) -> decltype(detail::vec_dot(a, b))
1472 return detail::vec_dot(a, b);
1474 template <
typename T>
1478 return (a[0] * b[0]) + (a[1] * b[1]);
1480 template <
typename T>
1484 return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]);
1486 template <
typename T>
1490 return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]) + (a[3] * b[3]);
1494 #define VTK_M_SCALAR_DOT(stype) \
1495 static inline VTKM_EXEC_CONT detail::DotType<stype>::type dot(stype a, stype b) \
1499 static inline VTKM_EXEC_CONT detail::DotType<stype>::type Dot(stype a, stype b) { return a * b; }
1512 template <
typename T>
1513 static inline VTKM_EXEC_CONT auto dot(
const T& a,
const T& b) -> decltype(detail::vec_dot(a, b))
1515 return vtkm::Dot(a, b);
1517 template <
typename T>
1521 return vtkm::Dot(a, b);
1523 template <
typename T>
1527 return vtkm::Dot(a, b);
1529 template <
typename T>
1533 return vtkm::Dot(a, b);
1537 template <
typename T, vtkm::IdComponent Size>
1548 template <
typename T>
1554 template <
typename T>
1557 return a[0] + a[1] + a[2];
1560 template <
typename T>
1563 return a[0] + a[1] + a[2] + a[3];
1566 template <
typename T, vtkm::IdComponent Size>
1577 template <
typename T>
1583 template <
typename T>
1586 return a[0] * a[1] * a[2];
1589 template <
typename T>
1592 return a[0] * a[1] * a[2] * a[3];
1597 template <
typename U,
typename V>
1602 template <
typename T, vtkm::IdComponent Size>
1608 stream << vec[component] <<
",";
1610 return stream << vec[Size - 1] <<
"]";
1615 template <
typename T,
typename U>
1618 return stream <<
"[" << vec.
first <<
"," << vec.
second <<
"]";
1625 #endif //vtk_m_Types_h