mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Remove overloads for scalar to Vec multiplications
Previously, the templated Vec classes had overloaded multiply operators to allow it to be multiplied by any basic type (float, double, int, long, char, etc.). This was there to make it easier to multiply a vector by a scalar without having to jump through introspection hoops for the component types. However, using them almost always resulted in a conversion warning on some type of compiler, so I think it is easier just to remove them.
This commit is contained in:
parent
f426b16daf
commit
b5398babc5
182
vtkm/Types.h
182
vtkm/Types.h
@ -701,6 +701,15 @@ struct Divide
|
||||
}
|
||||
};
|
||||
|
||||
struct Negate
|
||||
{
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT T operator()(const T &x) const
|
||||
{
|
||||
return -x;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -830,7 +839,7 @@ public:
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass operator*(vtkm::Int8 scalar) const
|
||||
DerivedClass operator*(ComponentType scalar) const
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
*reinterpret_cast<const DerivedClass*>(this),
|
||||
@ -838,86 +847,6 @@ public:
|
||||
ComponentType,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass operator*(vtkm::UInt8 scalar) const
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
*reinterpret_cast<const DerivedClass*>(this),
|
||||
vtkm::internal::BindRightBinaryOp<
|
||||
ComponentType,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass operator*(vtkm::Int16 scalar) const
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
*reinterpret_cast<const DerivedClass*>(this),
|
||||
vtkm::internal::BindRightBinaryOp<
|
||||
ComponentType,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass operator*(vtkm::UInt16 scalar) const
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
*reinterpret_cast<const DerivedClass*>(this),
|
||||
vtkm::internal::BindRightBinaryOp<
|
||||
ComponentType,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass operator*(vtkm::Int32 scalar) const
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
*reinterpret_cast<const DerivedClass*>(this),
|
||||
vtkm::internal::BindRightBinaryOp<
|
||||
ComponentType,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass operator*(vtkm::UInt32 scalar) const
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
*reinterpret_cast<const DerivedClass*>(this),
|
||||
vtkm::internal::BindRightBinaryOp<
|
||||
ComponentType,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass operator*(vtkm::Int64 scalar) const
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
*reinterpret_cast<const DerivedClass*>(this),
|
||||
vtkm::internal::BindRightBinaryOp<
|
||||
ComponentType,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass operator*(vtkm::UInt64 scalar) const
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
*reinterpret_cast<const DerivedClass*>(this),
|
||||
vtkm::internal::BindRightBinaryOp<
|
||||
ComponentType,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass operator*(vtkm::Float32 scalar) const
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
*reinterpret_cast<const DerivedClass*>(this),
|
||||
vtkm::internal::BindRightBinaryOp<
|
||||
ComponentType,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass operator*(vtkm::Float64 scalar) const
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
*reinterpret_cast<const DerivedClass*>(this),
|
||||
vtkm::internal::BindRightBinaryOp<
|
||||
ComponentType,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass operator/(const DerivedClass &other) const
|
||||
@ -928,6 +857,14 @@ public:
|
||||
vtkm::internal::Divide());
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
DerivedClass operator-() const
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
*reinterpret_cast<const DerivedClass*>(this),
|
||||
vtkm::internal::Negate());
|
||||
}
|
||||
|
||||
protected:
|
||||
ComponentType Components[NUM_COMPONENTS];
|
||||
};
|
||||
@ -1183,88 +1120,7 @@ struct not_default_constructor
|
||||
|
||||
template<typename T, vtkm::IdComponent Size>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T, Size> operator*(vtkm::Int8 scalar, const vtkm::Vec<T, Size> &vec)
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
vec,
|
||||
vtkm::internal::BindLeftBinaryOp<T,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
template<typename T, vtkm::IdComponent Size>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T, Size> operator*(vtkm::UInt8 scalar, const vtkm::Vec<T, Size> &vec)
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
vec,
|
||||
vtkm::internal::BindLeftBinaryOp<T,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
template<typename T, vtkm::IdComponent Size>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T, Size> operator*(vtkm::Int16 scalar, const vtkm::Vec<T, Size> &vec)
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
vec,
|
||||
vtkm::internal::BindLeftBinaryOp<T,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
template<typename T, vtkm::IdComponent Size>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T, Size> operator*(vtkm::UInt16 scalar, const vtkm::Vec<T, Size> &vec)
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
vec,
|
||||
vtkm::internal::BindLeftBinaryOp<T,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
template<typename T, vtkm::IdComponent Size>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T, Size> operator*(vtkm::Int32 scalar, const vtkm::Vec<T, Size> &vec)
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
vec,
|
||||
vtkm::internal::BindLeftBinaryOp<T,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
template<typename T, vtkm::IdComponent Size>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T, Size> operator*(vtkm::UInt32 scalar, const vtkm::Vec<T, Size> &vec)
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
vec,
|
||||
vtkm::internal::BindLeftBinaryOp<T,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
template<typename T, vtkm::IdComponent Size>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T, Size> operator*(vtkm::Int64 scalar, const vtkm::Vec<T, Size> &vec)
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
vec,
|
||||
vtkm::internal::BindLeftBinaryOp<T,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
template<typename T, vtkm::IdComponent Size>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T, Size> operator*(vtkm::UInt64 scalar, const vtkm::Vec<T, Size> &vec)
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
vec,
|
||||
vtkm::internal::BindLeftBinaryOp<T,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
template<typename T, vtkm::IdComponent Size>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T, Size> operator*(vtkm::Float32 scalar, const vtkm::Vec<T, Size> &vec)
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
vec,
|
||||
vtkm::internal::BindLeftBinaryOp<T,vtkm::internal::Multiply>(scalar));
|
||||
}
|
||||
|
||||
template<typename T, vtkm::IdComponent Size>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T, Size> operator*(vtkm::Float64 scalar, const vtkm::Vec<T, Size> &vec)
|
||||
vtkm::Vec<T, Size> operator*(T scalar, const vtkm::Vec<T, Size> &vec)
|
||||
{
|
||||
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
|
||||
vec,
|
||||
|
@ -367,6 +367,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
|
||||
// std::cout << "Testing hyperbolic trig functions." << std::endl;
|
||||
|
||||
const VectorType zero(0);
|
||||
const VectorType half(0.5);
|
||||
|
||||
for (vtkm::IdComponent index = 0;
|
||||
index < NUM_NUMBERS - NUM_COMPONENTS + 1;
|
||||
@ -386,10 +387,10 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
|
||||
const VectorType minusX = zero - x;
|
||||
|
||||
VTKM_MATH_ASSERT(test_equal(vtkm::SinH(x),
|
||||
0.5f*(vtkm::Exp(x) - vtkm::Exp(minusX))),
|
||||
half*(vtkm::Exp(x) - vtkm::Exp(minusX))),
|
||||
"SinH does not match definition.");
|
||||
VTKM_MATH_ASSERT(test_equal(vtkm::CosH(x),
|
||||
0.5f*(vtkm::Exp(x) + vtkm::Exp(minusX))),
|
||||
half*(vtkm::Exp(x) + vtkm::Exp(minusX))),
|
||||
"SinH does not match definition.");
|
||||
VTKM_MATH_ASSERT(test_equal(vtkm::TanH(x), vtkm::SinH(x)/vtkm::CosH(x)),
|
||||
"TanH does not match definition");
|
||||
@ -628,8 +629,8 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
|
||||
// Assuming all TestValues positive.
|
||||
VectorType positive1 = TestValue(1, VectorType());
|
||||
VectorType positive2 = TestValue(2, VectorType());
|
||||
VectorType negative1 = -1*positive1;
|
||||
VectorType negative2 = -1*positive2;
|
||||
VectorType negative1 = -positive1;
|
||||
VectorType negative2 = -positive2;
|
||||
|
||||
VTKM_MATH_ASSERT(test_equal(vtkm::CopySign(positive1, positive2), positive1),
|
||||
"CopySign failed.");
|
||||
@ -714,7 +715,7 @@ struct AbsTests : public vtkm::exec::FunctorBase
|
||||
void operator()(vtkm::Id index) const {
|
||||
// std::cout << "Testing Abs." << std::endl;
|
||||
T positive = TestValue(index, T()); // Assuming all TestValues positive.
|
||||
T negative = -1*positive;
|
||||
T negative = -positive;
|
||||
|
||||
VTKM_MATH_ASSERT(test_equal(vtkm::Abs(positive), positive),
|
||||
"Abs returned wrong value.");
|
||||
|
Loading…
Reference in New Issue
Block a user