From f00c3bba11bff60f32e6c37ec62529c3f8f9ae10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkjak@fjfi.cvut.cz> Date: Sat, 27 Jul 2019 09:45:35 +0100 Subject: [PATCH] Removed duplicated vector tests (appeared after bad rebase) --- src/UnitTests/Containers/VectorTest-1.h | 22 ---- src/UnitTests/Containers/VectorTest-6.h | 158 ++++-------------------- src/UnitTests/Containers/VectorTest-7.h | 2 - 3 files changed, 22 insertions(+), 160 deletions(-) diff --git a/src/UnitTests/Containers/VectorTest-1.h b/src/UnitTests/Containers/VectorTest-1.h index e12ed8ad6d..ced6051ab2 100644 --- a/src/UnitTests/Containers/VectorTest-1.h +++ b/src/UnitTests/Containers/VectorTest-1.h @@ -406,28 +406,6 @@ TYPED_TEST( VectorTest, comparisonOnDifferentDevices ) #endif } -TYPED_TEST( VectorTest, horizontalOperations ) -{ - using VectorType = typename TestFixture::VectorType; - using ViewType = typename TestFixture::ViewType; - using RealType = typename VectorType::RealType; - using IndexType = typename VectorType::IndexType; - const int size = VECTOR_TEST_SIZE; - - VectorType _u( size ), _v( size ), _w( size ); - ViewType u( _u ), v( _v ), w( _w ); - EXPECT_EQ( u.getSize(), size ); - u = 0; - v = 1; - w = 2; - - u = u + 4 * TNL::max( v, 0 ); - EXPECT_TRUE( u.containsOnlyValue( 4.0 ) ); - - u = u + 3 * w + 4 * TNL::max( v, 0 ); - EXPECT_TRUE( u.containsOnlyValue( 14.0 ) ); -} - #endif // HAVE_GTEST #include "../main.h" diff --git a/src/UnitTests/Containers/VectorTest-6.h b/src/UnitTests/Containers/VectorTest-6.h index 1706138405..889b349bc0 100644 --- a/src/UnitTests/Containers/VectorTest-6.h +++ b/src/UnitTests/Containers/VectorTest-6.h @@ -19,6 +19,28 @@ // and large enough to require multiple CUDA blocks for reduction constexpr int VECTOR_TEST_SIZE = 500; +TYPED_TEST( VectorTest, horizontalOperations ) +{ + using VectorType = typename TestFixture::VectorType; + using ViewType = typename TestFixture::ViewType; + using RealType = typename VectorType::RealType; + using IndexType = typename VectorType::IndexType; + const int size = VECTOR_TEST_SIZE; + + VectorType _u( size ), _v( size ), _w( size ); + ViewType u( _u ), v( _v ), w( _w ); + EXPECT_EQ( u.getSize(), size ); + u = 0; + v = 1; + w = 2; + + u = u + 4 * TNL::max( v, 0 ); + EXPECT_TRUE( u.containsOnlyValue( 4.0 ) ); + + u = u + 3 * w + 4 * TNL::max( v, 0 ); + EXPECT_TRUE( u.containsOnlyValue( 14.0 ) ); +} + TYPED_TEST( VectorTest, verticalOperations ) { using VectorType = typename TestFixture::VectorType; @@ -85,142 +107,6 @@ TYPED_TEST( VectorTest, verticalOperations ) EXPECT_NEAR( sign( u ).getElement( i ), sign( u.getElement( i ) ), 1.0e-6 ); } -// TODO: test prefix sum with custom begin and end parameters - -TEST( VectorSpecialCasesTest, sumOfBoolVector ) -{ - using VectorType = Containers::Vector< bool, Devices::Host >; - using ViewType = VectorView< bool, Devices::Host >; - const float epsilon = 64 * std::numeric_limits< float >::epsilon(); - - VectorType v( 512 ), w( 512 ); - ViewType v_view( v ), w_view( w ); - v.setValue( true ); - w.setValue( false ); - - const int sum = TNL::sum( v ); - const int l1norm = lpNorm( v, 1.0 ); - const float l2norm = lpNorm( v, 2.0 ); - const float l3norm = lpNorm( v, 3.0 ); - EXPECT_EQ( sum, 512 ); - EXPECT_EQ( l1norm, 512 ); - EXPECT_NEAR( l2norm, std::sqrt( 512 ), epsilon ); - EXPECT_NEAR( l3norm, std::cbrt( 512 ), epsilon ); - - const int diff_sum = TNL::sum( v - w ); //v.differenceSum< int >( w ); - const int diff_l1norm = lpNorm( v - w, 1.0 );//v.differenceLpNorm< int >( w, 1.0 ); - const float diff_l2norm = lpNorm( v - w, 2.0 );//v.differenceLpNorm< float >( w, 2.0 ); - const float diff_l3norm = lpNorm( v - w, 3.0 );//v.differenceLpNorm< float >( w, 3.0 ); - EXPECT_EQ( diff_sum, 512 ); - EXPECT_EQ( diff_l1norm, 512 ); - EXPECT_NEAR( diff_l2norm, std::sqrt( 512 ), epsilon ); - EXPECT_NEAR( diff_l3norm, std::cbrt( 512 ), epsilon ); - - // test views - const int sum_view = v_view.sum< int >(); - const int l1norm_view = lpNorm( v_view, 1.0 ); - const float l2norm_view = lpNorm( v_view, 2.0 ); - const float l3norm_view = lpNorm( v_view, 3.0 ); - EXPECT_EQ( sum_view, 512 ); - EXPECT_EQ( l1norm_view, 512 ); - EXPECT_NEAR( l2norm_view, std::sqrt( 512 ), epsilon ); - EXPECT_NEAR( l3norm_view, std::cbrt( 512 ), epsilon ); - - const int diff_sum_view = TNL::sum( v_view - w_view ); - const int diff_l1norm_view = lpNorm( v_view - w_view, 1.0 ); - const float diff_l2norm_view = lpNorm( v_view - w_view, 2.0 ); - const float diff_l3norm_view = lpNorm( v_view - w_view, 3.0 ); - EXPECT_EQ( diff_sum_view, 512 ); - EXPECT_EQ( diff_l1norm_view, 512 ); - EXPECT_NEAR( diff_l2norm_view, std::sqrt( 512 ), epsilon ); - EXPECT_NEAR( diff_l3norm_view, std::cbrt( 512 ), epsilon ); -} - -TEST( VectorSpecialCasesTest, assignmentThroughView ) -{ - using VectorType = Containers::Vector< int, Devices::Host >; - using ViewType = VectorView< int, Devices::Host >; - - static_assert( Containers::Algorithms::detail::HasSubscriptOperator< VectorType >::value, "Subscript operator detection by SFINAE does not work for Vector." ); - static_assert( Containers::Algorithms::detail::HasSubscriptOperator< ViewType >::value, "Subscript operator detection by SFINAE does not work for VectorView." ); - - VectorType u( 100 ), v( 100 ); - ViewType u_view( u ), v_view( v ); - - u.setValue( 42 ); - v.setValue( 0 ); - v_view = u_view; - EXPECT_EQ( u_view.getData(), u.getData() ); - EXPECT_EQ( v_view.getData(), v.getData() ); - for( int i = 0; i < 100; i++ ) - EXPECT_EQ( v_view[ i ], 42 ); - - u.setValue( 42 ); - v.setValue( 0 ); - v_view = u; - EXPECT_EQ( u_view.getData(), u.getData() ); - EXPECT_EQ( v_view.getData(), v.getData() ); - for( int i = 0; i < 100; i++ ) - EXPECT_EQ( v_view[ i ], 42 ); -} - -TEST( VectorSpecialCasesTest, operationsOnConstView ) -{ - using VectorType = Containers::Vector< int, Devices::Host >; - using ViewType = VectorView< const int, Devices::Host >; - - VectorType u( 100 ), v( 100 ); - ViewType u_view( u ), v_view( v ); - - u.setValue( 1 ); - v.setValue( 1 ); - - EXPECT_EQ( max( u_view ), 1 ); - EXPECT_EQ( min( u_view ), 1 ); - EXPECT_EQ( max( abs( u_view ) ), 1 ); - EXPECT_EQ( min( abs( u_view ) ), 1 ); - EXPECT_EQ( lpNorm( u_view, 1 ), 100 ); - EXPECT_EQ( max( u_view - v_view ), 0 ); - EXPECT_EQ( min( u_view - v_view ), 0 ); - EXPECT_EQ( max( abs( u_view - v_view ) ), 0 ); - EXPECT_EQ( min( abs( u_view - v_view ) ), 0 ); - EXPECT_EQ( lpNorm( u_view - v_view, 1.0 ), 0 ); - EXPECT_EQ( sum( u_view - v_view ), 0 ); - EXPECT_EQ( dot( u_view, v_view ), 100 ); -} - -TEST( VectorSpecialCasesTest, initializationOfVectorViewByArrayView ) -{ - using ArrayType = Containers::Array< int, Devices::Host >; - using VectorViewType = VectorView< const int, Devices::Host >; - using ArrayViewType = ArrayView< int, Devices::Host >; - - ArrayType a( 100 ); - a.setValue( 0 ); - ArrayViewType a_view( a ); - - VectorViewType v_view( a_view ); - EXPECT_EQ( v_view.getData(), a_view.getData() ); - EXPECT_EQ( v_view.sum(), 0 ); -} - -TEST( VectorSpecialCasesTest, defaultConstructors ) -{ - using ArrayType = Containers::Array< int, Devices::Host >; - using VectorViewType = VectorView< int, Devices::Host >; - using ArrayViewType = ArrayView< int, Devices::Host >; - - ArrayType a( 100 ); - a.setValue( 0 ); - - ArrayViewType a_view; - a_view.bind( a ); - - VectorViewType v_view; - v_view.bind( a ); - EXPECT_EQ( v_view.getData(), a_view.getData() ); -} - #endif // HAVE_GTEST #include "../main.h" diff --git a/src/UnitTests/Containers/VectorTest-7.h b/src/UnitTests/Containers/VectorTest-7.h index a6d45d8599..6bae125687 100644 --- a/src/UnitTests/Containers/VectorTest-7.h +++ b/src/UnitTests/Containers/VectorTest-7.h @@ -15,8 +15,6 @@ #ifdef HAVE_GTEST #include "VectorTestSetup.h" -// should be small enough to have fast tests, but larger than minGPUReductionDataSize -// and large enough to require multiple CUDA blocks for reduction constexpr int VECTOR_TEST_SIZE = 100; TYPED_TEST( VectorTest, sin ) -- GitLab