Skip to content

Commit 00357a0

Browse files
fix(test): remove the undefined behaviour if the type is not FP
The standard does not define the complex class other than float, double, and long double. It leaves the implementation on the hands of vendors, and it could lead to the portability issue or undefined behaviour, which is not warranted.
1 parent bc0afbd commit 00357a0

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

test/tensor/functions/test_functions_real_imag_conj.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ BOOST_TEST_DECORATOR(
4747
)
4848
BOOST_FIXTURE_TEST_CASE_TEMPLATE(test_tensor_dynamic,
4949
TestTupleType,
50-
boost::numeric::ublas::cpp_basic_std_types,
50+
boost::numeric::ublas::cpp_basic_std_floating_types,
5151
boost::numeric::ublas::tuple_fixture_tensor_dynamic<TestTupleType>
5252
)
5353
{
@@ -72,15 +72,15 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(test_tensor_dynamic,
7272
auto r00 = complex_tensor_t(n);
7373

7474
tensor_type b = (a+a) / value_type{2};
75-
tensor_type r1 = ublas::real( (a+a) / value_type{2} );
75+
tensor_type r1 = ublas::real( (a+a) / value_type{2} );
7676
std::transform( b.begin(), b.end(), r0.begin(), [](auto const& l){ return std::real( l ); } );
7777
BOOST_CHECK_EQUAL_COLLECTIONS(r0.begin(), r0.end(), r1.begin(), r1.end());
7878

79-
tensor_type r2 = ublas::imag( (a+a) / value_type{2} );
79+
tensor_type r2 = ublas::imag( (a+a) / value_type{2} );
8080
std::transform( b.begin(), b.end(), r0.begin(), [](auto const& l){ return std::imag( l ); } );
8181
BOOST_CHECK_EQUAL_COLLECTIONS(r0.begin(), r0.end(), r2.begin(), r2.end());
8282

83-
complex_tensor_t r3 = ublas::conj( (a+a) / value_type{2} );
83+
complex_tensor_t r3 = ublas::conj( (a+a) / value_type{2} );
8484
std::transform( b.begin(), b.end(), r00.begin(), [](auto const& l){ return std::conj( l ); } );
8585
BOOST_CHECK_EQUAL_COLLECTIONS(r00.begin(), r00.end(), r3.begin(), r3.end());
8686

@@ -118,7 +118,7 @@ BOOST_TEST_DECORATOR(
118118
)
119119
BOOST_FIXTURE_TEST_CASE_TEMPLATE(test_tensor_static_rank,
120120
TestTupleType,
121-
boost::numeric::ublas::cpp_basic_std_types,
121+
boost::numeric::ublas::cpp_basic_std_floating_types,
122122
boost::numeric::ublas::tuple_fixture_tensor_static_rank<TestTupleType>
123123
)
124124
{
@@ -194,7 +194,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(test_tensor_static_rank,
194194
// )
195195
// BOOST_FIXTURE_TEST_CASE_TEMPLATE(test_tensor_static,
196196
// TestTupleType,
197-
// boost::numeric::ublas::cpp_basic_std_types,
197+
// boost::numeric::ublas::cpp_basic_std_floating_types,
198198
// boost::numeric::ublas::tuple_fixture_tensor_static<TestTupleType>
199199
// )
200200
// {

test/tensor/utility.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ namespace boost::numeric::ublas{
115115
// using cpp_std_types = zip<int,float,std::complex<float>>::with_t<layout::first_order, layout::last_order>;
116116
using cpp_std_types = zip<int,float>::with_t<layout::first_order, layout::last_order>;
117117

118+
// CPP Standard: The effect of instantiating the template complex for any other type than float, double, and long double is unspecified.
119+
// Implementations may forbid instantiation of such specializations.
120+
using cpp_basic_std_floating_types = zip<float>::with_t<layout::first_order, layout::last_order>;
121+
118122
using cpp_basic_std_types = zip<int,float>::with_t<layout::first_order, layout::last_order>;
119123
using layout_test_types = std::tuple<layout::first_order, layout::last_order>;
120124

0 commit comments

Comments
 (0)