Loading src/TNL/Containers/ArrayView.h +6 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,12 @@ public: __cuda_callable__ ArrayView( const ArrayView& ) = default; // "Templated copy-constructor" accepting any cv-qualification of Element template< typename Element_ > __cuda_callable__ ArrayView( ArrayView< Element_, Device, Index >& array ) : data(array.getData()), size(array.getSize()) {} // default move-constructor __cuda_callable__ ArrayView( ArrayView&& ) = default; Loading src/TNL/Containers/VectorView.h +12 −3 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ template< typename Real = double, class VectorView : public ArrayView< Real, Device, Index > { using BaseType = ArrayView< Real, Device, Index >; using NonConstReal = typename std::remove_const< Real >::type; public: using RealType = Real; Loading @@ -38,7 +39,18 @@ public: using CudaType = VectorView< Real, Devices::Cuda, Index >; // inherit all ArrayView's constructors #ifndef __NVCC__ using BaseType::ArrayView; #else // workaround for a bug in nvcc 8.0 (seems to be fixed in 9.0) using ArrayView< Real, Device, Index >::ArrayView; #endif // initialization by base class is not a copy constructor so it has to be explicit template< typename Element_ > // template catches both const and non-const qualified Element __cuda_callable__ VectorView( const ArrayView< Element_, Device, Index >& view ) : BaseType::ArrayView( view ) {} static String getType(); Loading @@ -51,9 +63,6 @@ public: RealType value, RealType thisElementMultiplicator ); using ArrayView< Real, Device, Index >::operator==; using ArrayView< Real, Device, Index >::operator!=; template< typename Vector > VectorView& operator-=( const Vector& vector ); Loading src/UnitTests/Containers/ArrayViewTest.h +3 −0 Original line number Diff line number Diff line Loading @@ -160,6 +160,9 @@ TYPED_TEST( ArrayViewTest, constructors ) const ArrayType& b = a; ConstViewType b_view( b ); ConstViewType const_a_view( a ); // test initialization of cons view by non-const view ConstViewType const_b_view( b_view ); } TYPED_TEST( ArrayViewTest, bind ) Loading src/UnitTests/Containers/VectorTest.h +15 −0 Original line number Diff line number Diff line Loading @@ -740,6 +740,21 @@ TEST( VectorSpecialCasesTest, operationsOnConstView ) EXPECT_EQ( u_view.scalarProduct( 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 ); } #endif // HAVE_GTEST Loading Loading
src/TNL/Containers/ArrayView.h +6 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,12 @@ public: __cuda_callable__ ArrayView( const ArrayView& ) = default; // "Templated copy-constructor" accepting any cv-qualification of Element template< typename Element_ > __cuda_callable__ ArrayView( ArrayView< Element_, Device, Index >& array ) : data(array.getData()), size(array.getSize()) {} // default move-constructor __cuda_callable__ ArrayView( ArrayView&& ) = default; Loading
src/TNL/Containers/VectorView.h +12 −3 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ template< typename Real = double, class VectorView : public ArrayView< Real, Device, Index > { using BaseType = ArrayView< Real, Device, Index >; using NonConstReal = typename std::remove_const< Real >::type; public: using RealType = Real; Loading @@ -38,7 +39,18 @@ public: using CudaType = VectorView< Real, Devices::Cuda, Index >; // inherit all ArrayView's constructors #ifndef __NVCC__ using BaseType::ArrayView; #else // workaround for a bug in nvcc 8.0 (seems to be fixed in 9.0) using ArrayView< Real, Device, Index >::ArrayView; #endif // initialization by base class is not a copy constructor so it has to be explicit template< typename Element_ > // template catches both const and non-const qualified Element __cuda_callable__ VectorView( const ArrayView< Element_, Device, Index >& view ) : BaseType::ArrayView( view ) {} static String getType(); Loading @@ -51,9 +63,6 @@ public: RealType value, RealType thisElementMultiplicator ); using ArrayView< Real, Device, Index >::operator==; using ArrayView< Real, Device, Index >::operator!=; template< typename Vector > VectorView& operator-=( const Vector& vector ); Loading
src/UnitTests/Containers/ArrayViewTest.h +3 −0 Original line number Diff line number Diff line Loading @@ -160,6 +160,9 @@ TYPED_TEST( ArrayViewTest, constructors ) const ArrayType& b = a; ConstViewType b_view( b ); ConstViewType const_a_view( a ); // test initialization of cons view by non-const view ConstViewType const_b_view( b_view ); } TYPED_TEST( ArrayViewTest, bind ) Loading
src/UnitTests/Containers/VectorTest.h +15 −0 Original line number Diff line number Diff line Loading @@ -740,6 +740,21 @@ TEST( VectorSpecialCasesTest, operationsOnConstView ) EXPECT_EQ( u_view.scalarProduct( 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 ); } #endif // HAVE_GTEST Loading