Extended complex tests
Extended complex tests
MODIFY
test/CMakeLists.txt
test/CMakeLists.txt
@@ -57,6 +57,8 @@ endfunction()
# ****************************************************************************
add_hipthrust_test("thrust.hip.allocator" test_allocator.cpp)
+# add_hipthrust_test("thrust.hip.complex_transform" test_complex_transform.cpp)
+# add_hipthrust_test("thrust.hip.complex" test_complex.cpp)
add_hipthrust_test("thrust.hip.copy_n" test_copy_n.cpp)
add_hipthrust_test("thrust.hip.copy" test_copy.cpp)
add_hipthrust_test("thrust.hip.counting_iterator" test_counting_iterator.cpp)

MODIFY
test/test_complex.cpp
test/test_complex.cpp
@@ -100,4 +100,227 @@ TYPED_TEST(ComplexTests, TestComplexConstructors)
ASSERT_NEAR_COMPLEX(a, b);
}
+TYPED_TEST(ComplexTests, TestComplexGetters)
+{
+ using T = typename TestFixture::input_type;
+
+ thrust::host_vector<T> data = get_random_data<T>(2,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max());
+
+ thrust::complex<T> z(data[0], data[1]);
+
+ ASSERT_EQ(data[0], z.real());
+ ASSERT_EQ(data[1], z.imag());
+
+ z.real(data[1]);
+ z.imag(data[0]);
+ ASSERT_EQ(data[1], z.real());
+ ASSERT_EQ(data[0], z.imag());
+
+ volatile thrust::complex<T> v(data[0], data[1]);
+
+ ASSERT_EQ(data[0], v.real());
+ ASSERT_EQ(data[1], v.imag());
+
+ v.real(data[1]);
+ v.imag(data[0]);
+ ASSERT_EQ(data[1], v.real());
+ ASSERT_EQ(data[0], v.imag());
+}
+
+TYPED_TEST(ComplexTests, TestComplexMemberOperators)
+{
+ using T = typename TestFixture::input_type;
+
+ thrust::host_vector<T> data_a = get_random_data<T>(2,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max());
+
+ thrust::host_vector<T> data_b = get_random_data<T>(2,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max());
+
+ thrust::complex<T> a(data_a[0], data_a[1]);
+ thrust::complex<T> b(data_b[0], data_b[1]);
+
+ std::complex<T> c(a);
+ std::complex<T> d(b);
+
+ a += b;
+ c += d;
+ ASSERT_NEAR_COMPLEX(a,c);
+
+ a -= b;
+ c -= d;
+ ASSERT_NEAR_COMPLEX(a,c);
+
+ a *= b;
+ c *= d;
+ ASSERT_NEAR_COMPLEX(a,c);
+
+ a /= b;
+ c /= d;
+ ASSERT_NEAR_COMPLEX(a,c);
+
+ // casting operator
+ c = (std::complex<T>)a;
+}
+
+TYPED_TEST(ComplexTests, TestComplexBasicArithmetic)
+{
+ using T = typename TestFixture::input_type;
+
+
+ thrust::host_vector<T> data = get_random_data<T>(2,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max());
+
+ thrust::complex<T> a(data[0], data[1]);
+ std::complex<T> b(a);
+
+ // Test the basic arithmetic functions against std
+
+ ASSERT_NEAR_COMPLEX(abs(a),abs(b));
+
+ ASSERT_NEAR_COMPLEX(arg(a),arg(b));
+
+ ASSERT_NEAR_COMPLEX(norm(a),norm(b));
+
+ ASSERT_EQ(conj(a),conj(b));
+
+ ASSERT_NEAR_COMPLEX(thrust::polar(data[0],data[1]),std::polar(data[0],data[1]));
+
+ // random_samples does not seem to produce infinities so proj(z) == z
+ ASSERT_EQ(proj(a),a);
+}
+
+TYPED_TEST(ComplexTests, TestComplexBinaryArithmetic)
+{
+ using T = typename TestFixture::input_type;
+
+ thrust::host_vector<T> data_a = get_random_data<T>(2,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max());
+
+ thrust::host_vector<T> data_b = get_random_data<T>(2,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max());
+
+ thrust::complex<T> a(data_a[0], data_a[1]);
+ thrust::complex<T> b(data_b[0], data_b[1]);
+
+ ASSERT_NEAR_COMPLEX(a*b,std::complex<T>(a) * std::complex<T>(b));
+ ASSERT_NEAR_COMPLEX(a*data_b[0],std::complex<T>(a) * data_b[0]);
+ ASSERT_NEAR_COMPLEX(data_a[0]*b,data_b[0] * std::complex<T>(b));
+
+ ASSERT_NEAR_COMPLEX(a / b, std::complex<T>(a) / std::complex<T>(b));
+ ASSERT_NEAR_COMPLEX(a / data_b[0], std::complex<T>(a) / data_b[0]);
+ ASSERT_NEAR_COMPLEX(data_a[0] / b, data_b[0] / std::complex<T>(b));
+
+ ASSERT_EQ(a + b, std::complex<T>(a) + std::complex<T>(b));
+ ASSERT_EQ(a + data_b[0], std::complex<T>(a) + data_b[0]);
+ ASSERT_EQ(data_a[0] + b, data_b[0] + std::complex<T>(b));
+
+ ASSERT_EQ(a - b, std::complex<T>(a) - std::complex<T>(b));
+ ASSERT_EQ(a - data_b[0], std::complex<T>(a) - data_b[0]);
+ ASSERT_EQ(data_a[0] - b, data_b[0] - std::complex<T>(b));
+}
+
+TYPED_TEST(ComplexTests, TestComplexUnaryArithmetic)
+{
+ using T = typename TestFixture::input_type;
+
+ thrust::host_vector<T> data_a = get_random_data<T>(2,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max());
+
+ thrust::complex<T> a(data_a[0], data_a[1]);
+
+ ASSERT_EQ(+a,+std::complex<T>(a));
+ ASSERT_EQ(-a,-std::complex<T>(a));
+}
+
+TYPED_TEST(ComplexTests, TestComplexExponentialFunctions)
+{
+ using T = typename TestFixture::input_type;
+
+ thrust::host_vector<T> data_a = get_random_data<T>(2,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max());
+
+ thrust::complex<T> a(data_a[0], data_a[1]);
+ std::complex<T> b(a);
+
+ ASSERT_NEAR_COMPLEX(exp(a),exp(b));
+ ASSERT_NEAR_COMPLEX(log(a),log(b));
+ ASSERT_NEAR_COMPLEX(log10(a),log10(b));
+}
+
+TYPED_TEST(ComplexTests, TestComplexPowerFunctions)
+{
+ using T = typename TestFixture::input_type;
+
+ thrust::host_vector<T> data_a = get_random_data<T>(2,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max());
+
+ thrust::host_vector<T> data_b = get_random_data<T>(2,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max());
+
+ thrust::complex<T> a(data_a[0], data_a[1]);
+ thrust::complex<T> b(data_b[0], data_b[1]);
+ std::complex<T> c(a);
+ std::complex<T> d(b);
+
+ ASSERT_NEAR_COMPLEX(pow(a,b),pow(c,d));
+ ASSERT_NEAR_COMPLEX(pow(a,b.real()),pow(c,d.real()));
+ ASSERT_NEAR_COMPLEX(pow(a.real(),b),pow(c.real(),d));
+
+ ASSERT_NEAR_COMPLEX(sqrt(a),sqrt(c));
+}
+
+TYPED_TEST(ComplexTests, TestComplexTrigonometricFunctions)
+{
+ using T = typename TestFixture::input_type;
+
+ thrust::host_vector<T> data_a = get_random_data<T>(2,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max());
+
+ thrust::complex<T> a(data_a[0], data_a[1]);
+ std::complex<T> c(a);
+
+ ASSERT_NEAR_COMPLEX(cos(a),cos(c));
+ ASSERT_NEAR_COMPLEX(sin(a),sin(c));
+ ASSERT_NEAR_COMPLEX(tan(a),tan(c));
+ ASSERT_NEAR_COMPLEX(cosh(a),cosh(c));
+ ASSERT_NEAR_COMPLEX(sinh(a),sinh(c));
+ ASSERT_NEAR_COMPLEX(tanh(a),tanh(c));
+
+ ASSERT_NEAR_COMPLEX(acos(a),acos(c));
+ ASSERT_NEAR_COMPLEX(asin(a),asin(c));
+ ASSERT_NEAR_COMPLEX(atan(a),atan(c));
+ ASSERT_NEAR_COMPLEX(acosh(a),acosh(c));
+ ASSERT_NEAR_COMPLEX(asinh(a),asinh(c));
+ ASSERT_NEAR_COMPLEX(atanh(a),atanh(c));
+}
+
+TYPED_TEST(ComplexTests, TestComplexStreamOperators)
+{
+ using T = typename TestFixture::input_type;
+
+ thrust::host_vector<T> data_a = get_random_data<T>(2,
+ std::numeric_limits<T>::min(),
+ std::numeric_limits<T>::max());
+
+ thrust::complex<T> a(data_a[0], data_a[1]);
+ std::stringstream out;
+ out << a;
+ thrust::complex<T> b;
+ out >> b;
+ ASSERT_NEAR_COMPLEX(a,b);
+}
+
#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC

MODIFY
test/test_complex_transform.cpp
test/test_complex_transform.cpp
// HIP API
#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
#include <hip/hip_runtime_api.h>
-
-#define HIP_CHECK(condition) ASSERT_EQ(condition, hipSuccess)
#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HCC
#include "test_utils.hpp"
@@ -303,7 +301,7 @@ TYPED_TEST(ComplexTransformTests, TestComplexArithmeticTransform)
thrust::transform(h_p1.begin(), h_p1.end(), h_p2.begin(), h_result.begin(), basic_arithmetic_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_p2.begin(), d_result.begin(), basic_arithmetic_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
}
}
@@ -323,7 +321,7 @@ TYPED_TEST(ComplexTransformTests, TestComplexPlaneTransform)
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), complex_plane_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), complex_plane_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
}
}
@@ -352,7 +350,7 @@ TYPED_TEST(ComplexTransformTests, TestComplexPowerTransform)
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), sqrt_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), sqrt_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
}
}
@@ -372,15 +370,15 @@ TYPED_TEST(ComplexTransformTests, TestComplexExponentialTransform)
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), exp_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), exp_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), log_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), log_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), log10_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), log10_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
}
}
@@ -401,55 +399,55 @@ TYPED_TEST(ComplexTransformTests, TestComplexTrigonometricTransform)
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), sin_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), sin_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), cos_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), cos_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), tan_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), tan_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), sinh_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), sinh_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), cosh_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), cosh_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), tanh_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), tanh_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), asin_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), asin_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), acos_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), acos_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), atan_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), atan_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), asinh_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), asinh_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), acosh_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), acosh_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
thrust::transform(h_p1.begin(), h_p1.end(), h_result.begin(), atanh_functor());
thrust::transform(d_p1.begin(), d_p1.end(), d_result.begin(), atanh_functor());
- ASSERT_EQ(h_result, d_result);
+ ASSERT_NEAR_COMPLEX(h_result, d_result);
}
}

Extended complex tests

Extended complex tests