Loading src/Examples/Containers/ArrayExample.cpp +1 −12 Original line number Diff line number Diff line Loading @@ -46,21 +46,10 @@ void arrayExample() if( a1.containsOnlyValue( 0 ) ) std::cout << "a2 contains only value 0." << std::endl; /*** * More efficient way of array elements manipulation is with the lambda functions */ ArrayType a3( size ); auto f1 = [] __cuda_callable__ ( IndexType i ) -> int { return 2 * i;}; a3.evaluate( f1 ); for( int i = 0; i < size; i++ ) if( a3.getElement( i ) != 2 * i ) std::cerr << "Something is wrong!!!" << std::endl; /*** * You may swap array data with the swap method. */ a1.swap( a3 ); a1.swap( a2 ); /*** * Of course, you may save it to file and load again Loading src/Examples/Containers/ArrayViewExample.cpp +11 −15 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ #include <list> #include <vector> #include <TNL/Containers/Array.h> #include <TNL/Containers/ArrayView.h> using namespace TNL; using namespace std; Loading @@ -15,29 +16,23 @@ void arrayViewExample() const int size = 10; using ArrayType = Containers::Array< int, Device >; using IndexType = typename ArrayType::IndexType; ArrayType a1( size ), a2( size ); using ViewType = Containers::ArrayView< int, Device >; ArrayType _a1( size ), _a2( size ); ViewType a1( _a1 ), a2( _a2 ); /*** * You may initiate the array using setElement * You may initiate the array view using setElement */ for( int i = 0; i< size; i++ ) a1.setElement( i, i ); /*** * You may also assign value to all array elements ... * You may also assign value to all array view elements ... */ a2 = 0.0; /*** * ... or assign STL list and vector. */ std::list< float > l = { 1.0, 2.0, 3.0 }; std::vector< float > v = { 5.0, 6.0, 7.0 }; a1 = v; a1 = l; /*** * Simple array values checks can be done as follows ... * Simple array view values checks can be done as follows ... */ if( a1.containsValue( 1 ) ) std::cout << "a1 contains value 1." << std::endl; Loading @@ -47,9 +42,10 @@ void arrayViewExample() std::cout << "a2 contains only value 0." << std::endl; /*** * More efficient way of array elements manipulation is with the lambda functions * More efficient way of array view elements manipulation is with the lambda functions */ ArrayType a3( size ); ArrayType _a3( size ); ViewType a3( _a3 ); auto f1 = [] __cuda_callable__ ( IndexType i ) -> int { return 2 * i;}; a3.evaluate( f1 ); Loading @@ -58,7 +54,7 @@ void arrayViewExample() std::cerr << "Something is wrong!!!" << std::endl; /*** * You may swap array data with the swap method. * You may swap array view data with the swap method. */ a1.swap( a3 ); Loading src/Examples/Containers/CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ ENDIF() IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( ArrayViewExampleCuda ArrayViewExample.cu ) ADD_CUSTOM_COMMAND( COMMAND ArrayExampleCuda > ArrayViewExampleCuda.out OUTPUT ArrayViewExampleCuda.out ) ADD_CUSTOM_COMMAND( COMMAND ArrayViewExampleCuda > ArrayViewExampleCuda.out OUTPUT ArrayViewExampleCuda.out ) ELSE() ADD_EXECUTABLE( ArrayViewExample ArrayViewExample.cpp ) ADD_CUSTOM_COMMAND( COMMAND ArrayViewExample > ArrayViewExample.out OUTPUT ArrayViewExample.out ) Loading src/TNL/Containers/Algorithms/ArrayAssignment.h +10 −0 Original line number Diff line number Diff line Loading @@ -50,8 +50,14 @@ template< typename Array, typename T > struct ArrayAssignment< Array, T, true > { static void resize( Array& a, const T& t ) { a.setSize( t.getSize() ); } static void assign( Array& a, const T& t ) { TNL_ASSERT_EQ( a.getSize(), t.getSize(), "The sizes of the arrays must be equal." ); ArrayOperations< typename Array::DeviceType, typename T::DeviceType >::template copyMemory< typename Array::ValueType, typename T::ValueType, typename Array::IndexType > ( a.getArrayData(), t.getArrayData(), t.getSize() ); Loading @@ -66,6 +72,10 @@ template< typename Array, typename T > struct ArrayAssignment< Array, T, false > { static void resize( Array& a, const T& t ) { TNL_ASSERT_TRUE( !a.empty(), "Cannot assign value to empty array." ); }; static void assign( Array& a, const T& t ) { ArrayOperations< typename Array::DeviceType >::template Loading src/TNL/Containers/Array.h +66 −64 Original line number Diff line number Diff line Loading @@ -519,6 +519,8 @@ class Array : public Object * If the array was not initialize yet, common load is * performed. Otherwise, the array size must fit with * the size of array being loaded. * * This method is deprecated - use ArrayView instead. */ void boundLoad( File& file ); Loading Loading
src/Examples/Containers/ArrayExample.cpp +1 −12 Original line number Diff line number Diff line Loading @@ -46,21 +46,10 @@ void arrayExample() if( a1.containsOnlyValue( 0 ) ) std::cout << "a2 contains only value 0." << std::endl; /*** * More efficient way of array elements manipulation is with the lambda functions */ ArrayType a3( size ); auto f1 = [] __cuda_callable__ ( IndexType i ) -> int { return 2 * i;}; a3.evaluate( f1 ); for( int i = 0; i < size; i++ ) if( a3.getElement( i ) != 2 * i ) std::cerr << "Something is wrong!!!" << std::endl; /*** * You may swap array data with the swap method. */ a1.swap( a3 ); a1.swap( a2 ); /*** * Of course, you may save it to file and load again Loading
src/Examples/Containers/ArrayViewExample.cpp +11 −15 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ #include <list> #include <vector> #include <TNL/Containers/Array.h> #include <TNL/Containers/ArrayView.h> using namespace TNL; using namespace std; Loading @@ -15,29 +16,23 @@ void arrayViewExample() const int size = 10; using ArrayType = Containers::Array< int, Device >; using IndexType = typename ArrayType::IndexType; ArrayType a1( size ), a2( size ); using ViewType = Containers::ArrayView< int, Device >; ArrayType _a1( size ), _a2( size ); ViewType a1( _a1 ), a2( _a2 ); /*** * You may initiate the array using setElement * You may initiate the array view using setElement */ for( int i = 0; i< size; i++ ) a1.setElement( i, i ); /*** * You may also assign value to all array elements ... * You may also assign value to all array view elements ... */ a2 = 0.0; /*** * ... or assign STL list and vector. */ std::list< float > l = { 1.0, 2.0, 3.0 }; std::vector< float > v = { 5.0, 6.0, 7.0 }; a1 = v; a1 = l; /*** * Simple array values checks can be done as follows ... * Simple array view values checks can be done as follows ... */ if( a1.containsValue( 1 ) ) std::cout << "a1 contains value 1." << std::endl; Loading @@ -47,9 +42,10 @@ void arrayViewExample() std::cout << "a2 contains only value 0." << std::endl; /*** * More efficient way of array elements manipulation is with the lambda functions * More efficient way of array view elements manipulation is with the lambda functions */ ArrayType a3( size ); ArrayType _a3( size ); ViewType a3( _a3 ); auto f1 = [] __cuda_callable__ ( IndexType i ) -> int { return 2 * i;}; a3.evaluate( f1 ); Loading @@ -58,7 +54,7 @@ void arrayViewExample() std::cerr << "Something is wrong!!!" << std::endl; /*** * You may swap array data with the swap method. * You may swap array view data with the swap method. */ a1.swap( a3 ); Loading
src/Examples/Containers/CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ ENDIF() IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( ArrayViewExampleCuda ArrayViewExample.cu ) ADD_CUSTOM_COMMAND( COMMAND ArrayExampleCuda > ArrayViewExampleCuda.out OUTPUT ArrayViewExampleCuda.out ) ADD_CUSTOM_COMMAND( COMMAND ArrayViewExampleCuda > ArrayViewExampleCuda.out OUTPUT ArrayViewExampleCuda.out ) ELSE() ADD_EXECUTABLE( ArrayViewExample ArrayViewExample.cpp ) ADD_CUSTOM_COMMAND( COMMAND ArrayViewExample > ArrayViewExample.out OUTPUT ArrayViewExample.out ) Loading
src/TNL/Containers/Algorithms/ArrayAssignment.h +10 −0 Original line number Diff line number Diff line Loading @@ -50,8 +50,14 @@ template< typename Array, typename T > struct ArrayAssignment< Array, T, true > { static void resize( Array& a, const T& t ) { a.setSize( t.getSize() ); } static void assign( Array& a, const T& t ) { TNL_ASSERT_EQ( a.getSize(), t.getSize(), "The sizes of the arrays must be equal." ); ArrayOperations< typename Array::DeviceType, typename T::DeviceType >::template copyMemory< typename Array::ValueType, typename T::ValueType, typename Array::IndexType > ( a.getArrayData(), t.getArrayData(), t.getSize() ); Loading @@ -66,6 +72,10 @@ template< typename Array, typename T > struct ArrayAssignment< Array, T, false > { static void resize( Array& a, const T& t ) { TNL_ASSERT_TRUE( !a.empty(), "Cannot assign value to empty array." ); }; static void assign( Array& a, const T& t ) { ArrayOperations< typename Array::DeviceType >::template Loading
src/TNL/Containers/Array.h +66 −64 Original line number Diff line number Diff line Loading @@ -519,6 +519,8 @@ class Array : public Object * If the array was not initialize yet, common load is * performed. Otherwise, the array size must fit with * the size of array being loaded. * * This method is deprecated - use ArrayView instead. */ void boundLoad( File& file ); Loading