Commit 3c7d5d42 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Minor changes to the Array, ArrayView, Vector and VectorView classes

- passing indices and array/vector values by reference is useless
- declaring arguments passed by value as "const" is useless
- using "IndexType" and "ValueType" is better than "Index" and "Value",
  because Doxygen creates an automatic link to the description of the
  type
- various other documentation and whitespace fixes
parent 562903aa
Loading
Loading
Loading
Loading
+41 −41
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ class Array
       * \param size The number of array elements to be allocated.
       * \param allocator The allocator to be associated with this array.
       */
      explicit Array( const IndexType& size, const AllocatorType& allocator = AllocatorType() );
      explicit Array( IndexType size, const AllocatorType& allocator = AllocatorType() );

      /**
       * \brief Constructs an array with given size and value.
@@ -145,7 +145,7 @@ class Array
       * \param value The value all elements will be set to.
       * \param allocator The allocator to be associated with this array.
       */
      explicit Array( const IndexType& size, const Value& value, const AllocatorType& allocator = AllocatorType() );
      explicit Array( IndexType size, ValueType value, const AllocatorType& allocator = AllocatorType() );

      /**
       * \brief Constructs an array with given size and copies data from given
@@ -155,8 +155,8 @@ class Array
       * \param size The number of array elements to be copied to the array.
       * \param allocator The allocator to be associated with this array.
       */
      Array( Value* data,
             const IndexType& size,
      Array( ValueType* data,
             IndexType size,
             const AllocatorType& allocator = AllocatorType() );

      /**
@@ -287,7 +287,7 @@ class Array
       *
       * \param size The new size of the array.
       */
      void resize( Index size );
      void resize( IndexType size );

      /**
       * \brief Method for resizing the array with an initial value.
@@ -306,7 +306,7 @@ class Array
       * \param size The new size of the array.
       * \param value The value to initialize new elements with.
       */
      void resize( Index size, const ValueType& value );
      void resize( IndexType size, ValueType value );

      /**
       * \brief Method for setting the array size.
@@ -318,14 +318,14 @@ class Array
       *
       * \param size The new size of the array.
       */
      void setSize( Index size );
      void setSize( IndexType size );

      /**
       * \brief Returns the current array size.
       *
       * This method can be called from device kernels.
       */
      __cuda_callable__ Index getSize() const;
      __cuda_callable__ IndexType getSize() const;

      /**
       * \brief Sets the same size as the size of an existing array.
@@ -448,10 +448,10 @@ class Array
       * where the array is allocated.
       *
       * \param i The index of the element to be set.
       * \param v The new value of the element.
       * \param value The new value of the element.
       */
      __cuda_callable__
      void setElement( const Index& i, const Value& v );
      void setElement( IndexType i, ValueType value );

      /**
       * \brief Returns the value of the \e i-th element.
@@ -462,7 +462,7 @@ class Array
       * \param i The index of the element to be returned.
       */
      __cuda_callable__
      Value getElement( const Index& i ) const;
      ValueType getElement( IndexType i ) const;

      /**
       * \brief Accesses the \e i-th element of the array.
@@ -479,7 +479,7 @@ class Array
       * \param i The index of the element to be accessed.
       * \return Reference to the \e i-th element.
       */
      __cuda_callable__ Value& operator[]( const Index& i );
      __cuda_callable__ Value& operator[]( IndexType i );

      /**
       * \brief Accesses the \e i-th element of the array.
@@ -496,7 +496,7 @@ class Array
       * \param i The index of the element to be accessed.
       * \return Constant reference to the \e i-th element.
       */
      __cuda_callable__ const Value& operator[]( const Index& i ) const;
      __cuda_callable__ const Value& operator[]( IndexType i ) const;

      /**
       * \brief Copy-assignment operator for copying data from another array.
@@ -557,7 +557,7 @@ class Array
       *         container, e.g. \ref Array, \ref ArrayView, \ref Vector,
       *         \ref VectorView, etc.
       * \param array Reference to the array-like container.
       * \return \ref True if both arrays are element-wise equal and \ref false
       * \return `true` if both arrays are element-wise equal and `false`
       *         otherwise.
       */
      template< typename ArrayT >
@@ -582,13 +582,13 @@ class Array
       * or \e end is set to a non-zero value, only elements in the sub-interval
       * `[begin, end)` are set.
       *
       * \param v The new value for the array elements.
       * \param value The new value for the array elements.
       * \param begin The beginning of the array sub-interval. It is 0 by
       *              default.
       * \param end The end of the array sub-interval. The default value is 0
       *            which is, however, replaced with the array size.
       */
      void setValue( const ValueType& v,
      void setValue( ValueType value,
                     IndexType begin = 0,
                     IndexType end = 0 );

@@ -603,8 +603,8 @@ class Array
       *
       * where
       *
       * \param elementIdx is an index of the array element being currently processed
       * \param elementValue is a value of the array element being currently processed
       * - \e elementIdx is an index of the array element being currently processed
       * - \e elementValue is a value of the array element being currently processed
       *
       * This is performed at the same place where the array is allocated,
       * i.e. it is efficient even on GPU.
@@ -633,8 +633,8 @@ class Array
       *
       * where
       *
       * \param elementIdx is an index of the array element being currently processed
       * \param elementValue is a value of the array element being currently processed
       * - \e elementIdx is an index of the array element being currently processed
       * - \e elementValue is a value of the array element being currently processed
       *
       * This is performed at the same place where the array is allocated,
       * i.e. it is efficient even on GPU.
@@ -663,8 +663,8 @@ class Array
       *
       * where
       *
       * \param elementIdx is an index of the array element being currently processed
       * \param elementValue is a value of the array element being currently processed
       * - \e elementIdx is an index of the array element being currently processed
       * - \e elementValue is a value of the array element being currently processed
       *
       * This is performed at the same place where the array is allocated,
       * i.e. it is efficient even on GPU.
@@ -691,8 +691,8 @@ class Array
       *
       * where
       *
       * \param elementIdx is an index of the array element being currently processed
       * \param elementValue is a value of the array element being currently processed
       * - \e elementIdx is an index of the array element being currently processed
       * - \e elementValue is a value of the array element being currently processed
       *
       * This is performed at the same place where the array is allocated,
       * i.e. it is efficient even on GPU.
@@ -727,7 +727,7 @@ class Array
        * being currently processed:
        *
        * ```
        * auto dataFetcher1 = [=] __cuda_callable__ ( Index idx, Value& value ) -> Result { return ... };
        * auto dataFetcher1 = [=] __cuda_callable__ ( IndexType idx, Value& value ) -> Result { return ... };
        * ```
        *
        * The reduction lambda function takes two variables which are supposed to be reduced:
@@ -744,7 +744,7 @@ class Array
      template< typename Fetch,
                typename Reduce,
                typename Result >
      Result reduceElements( const Index begin, Index end, Fetch&& fetch, Reduce&& reduce, const Result& zero );
      Result reduceElements( IndexType begin, IndexType end, Fetch&& fetch, Reduce&& reduce, const Result& zero );

       /**
        * \brief Computes reduction with array elements on interval [ \e begin, \e end) for constant instances.
@@ -765,7 +765,7 @@ class Array
        * being currently processed:
        *
        * ```
        * auto dataFetcher1 = [=] __cuda_callable__ ( Index idx, Value& value ) -> Result { return ... };
        * auto dataFetcher1 = [=] __cuda_callable__ ( IndexType idx, Value& value ) -> Result { return ... };
        * ```
        *
        * The reduction lambda function takes two variables which are supposed to be reduced:
@@ -782,7 +782,7 @@ class Array
      template< typename Fetch,
                typename Reduce,
                typename Result >
      Result reduceElements( const Index begin, Index end, Fetch&& fetch, Reduce&& reduce, const Result& zero ) const;
      Result reduceElements( IndexType begin, IndexType end, Fetch&& fetch, Reduce&& reduce, const Result& zero ) const;

       /**
        * \brief Computes reduction with all array elements.
@@ -801,7 +801,7 @@ class Array
        * being currently processed:
        *
        * ```
        * auto dataFetcher1 = [=] __cuda_callable__ ( Index idx, Value& value ) -> Result { return ... };
        * auto dataFetcher1 = [=] __cuda_callable__ ( IndexType idx, Value& value ) -> Result { return ... };
        * ```
        *
        * The reduction lambda function takes two variables which are supposed to be reduced:
@@ -837,7 +837,7 @@ class Array
        * being currently processed:
        *
        * ```
        * auto dataFetcher1 = [=] __cuda_callable__ ( Index idx, Value& value ) -> Result { return ... };
        * auto dataFetcher1 = [=] __cuda_callable__ ( IndexType idx, Value& value ) -> Result { return ... };
        * ```
        *
        * The reduction lambda function takes two variables which are supposed to be reduced:
@@ -863,15 +863,15 @@ class Array
       * \e end is set to a non-zero value, only elements in the sub-interval
       * `[begin, end)` are checked.
       *
       * \param v The value to be checked.
       * \param value The value to be checked.
       * \param begin The beginning of the array sub-interval. It is 0 by
       *              default.
       * \param end The end of the array sub-interval. The default value is 0
       *            which is, however, replaced with the array size.
       * \return True if there is _at least one_ element in the sub-interval
       *         `[begin, end)` which has the value \e v.
       * \return `true` if there is _at least one_ element in the sub-interval
       *         `[begin, end)` which has the value \e value.
       */
      bool containsValue( const ValueType& v,
      bool containsValue( ValueType value,
                          IndexType begin = 0,
                          IndexType end = 0 ) const;

@@ -882,15 +882,15 @@ class Array
       * \e end is set to a non-zero value, only elements in the sub-interval
       * `[begin, end)` are checked.
       *
       * \param v The value to be checked.
       * \param value The value to be checked.
       * \param begin The beginning of the array sub-interval. It is 0 by
       *              default.
       * \param end The end of the array sub-interval. The default value is 0
       *            which is, however, replaced with the array size.
       * \return True if there is _all_ elements in the sub-interval
       *         `[begin, end)` have the same value \e v.
       * \return `true` if _all_ elements in the sub-interval `[begin, end)`
       *         have the same value \e value.
       */
      bool containsOnlyValue( const ValueType& v,
      bool containsOnlyValue( ValueType value,
                              IndexType begin = 0,
                              IndexType end = 0 ) const;

@@ -919,13 +919,13 @@ class Array
      /** \brief Internal method for reallocating array elements. Used only
       * from the two overloads of \ref resize.
       */
      void reallocate( Index size );
      void reallocate( IndexType size );

      /** \brief Pointer to the data. */
      Value* data = nullptr;

      /** \brief Number of elements in the array. */
      Index size = 0;
      IndexType size = 0;

      /**
       * \brief The internal allocator instance.
@@ -941,7 +941,7 @@ class Array
 * \tparam Index is a type used for the indexing of the array elements.
 *
 * \param str is a output stream.
 * \param view is the array to be printed.
 * \param array is the array to be printed.
 *
 * \return a reference on the output stream \ref std::ostream&.
 */
+22 −24
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ template< typename Value,
          typename Index,
          typename Allocator >
Array< Value, Device, Index, Allocator >::
Array( const IndexType& size, const AllocatorType& allocator )
Array( IndexType size, const AllocatorType& allocator )
: allocator( allocator )
{
   this->setSize( size );
@@ -63,7 +63,7 @@ template< typename Value,
          typename Index,
          typename Allocator >
Array< Value, Device, Index, Allocator >::
Array( const IndexType& size, const Value& value, const AllocatorType& allocator )
Array( IndexType size, ValueType value, const AllocatorType& allocator )
: allocator( allocator )
{
   this->setSize( size );
@@ -75,8 +75,8 @@ template< typename Value,
          typename Index,
          typename Allocator >
Array< Value, Device, Index, Allocator >::
Array( Value* data,
       const IndexType& size,
Array( ValueType* data,
       IndexType size,
       const AllocatorType& allocator )
: allocator( allocator )
{
@@ -244,7 +244,7 @@ template< typename Value,
          typename Allocator >
void
Array< Value, Device, Index, Allocator >::
reallocate( Index size )
reallocate( IndexType size )
{
   TNL_ASSERT_GE( size, (Index) 0, "Array size must be non-negative." );

@@ -288,10 +288,10 @@ template< typename Value,
          typename Allocator >
void
Array< Value, Device, Index, Allocator >::
resize( Index size )
resize( IndexType size )
{
   // remember the old size and reallocate the array
   const Index old_size = this->size;
   const IndexType old_size = this->size;
   reallocate( size );

   if( old_size < size )
@@ -306,10 +306,10 @@ template< typename Value,
          typename Allocator >
void
Array< Value, Device, Index, Allocator >::
resize( Index size, const ValueType& value )
resize( IndexType size, ValueType value )
{
   // remember the old size and reallocate the array
   const Index old_size = this->size;
   const IndexType old_size = this->size;
   reallocate( size );

   if( old_size < size )
@@ -323,7 +323,7 @@ template< typename Value,
          typename Allocator >
void
Array< Value, Device, Index, Allocator >::
setSize( Index size )
setSize( IndexType size )
{
   TNL_ASSERT_GE( size, (Index) 0, "Array size must be non-negative." );

@@ -495,7 +495,7 @@ template< typename Value,
          typename Allocator >
__cuda_callable__ void
Array< Value, Device, Index, Allocator >::
setElement( const Index& i, const Value& x )
setElement( IndexType i, ValueType x )
{
   TNL_ASSERT_GE( i, (Index) 0, "Element index must be non-negative." );
   TNL_ASSERT_LT( i, this->getSize(), "Element index is out of bounds." );
@@ -508,7 +508,7 @@ template< typename Value,
          typename Allocator >
__cuda_callable__ Value
Array< Value, Device, Index, Allocator >::
getElement( const Index& i ) const
getElement( IndexType i ) const
{
   TNL_ASSERT_GE( i, (Index) 0, "Element index must be non-negative." );
   TNL_ASSERT_LT( i, this->getSize(), "Element index is out of bounds." );
@@ -522,7 +522,7 @@ template< typename Value,
__cuda_callable__
Value&
Array< Value, Device, Index, Allocator >::
operator[]( const Index& i )
operator[]( IndexType i )
{
#ifdef __CUDA_ARCH__
   TNL_ASSERT_TRUE( (std::is_same< Device, Devices::Cuda >{}()), "Attempt to access data not allocated on CUDA device from CUDA device." );
@@ -541,7 +541,7 @@ template< typename Value,
__cuda_callable__
const Value&
Array< Value, Device, Index, Allocator >::
operator[]( const Index& i ) const
operator[]( IndexType i ) const
{
#ifdef __CUDA_ARCH__
   TNL_ASSERT_TRUE( (std::is_same< Device, Devices::Cuda >{}()), "Attempt to access data not allocated on CUDA device from CUDA device." );
@@ -647,9 +647,7 @@ operator==( const ArrayT& array ) const
   if( this->getSize() == 0 )
      return true;
   return Algorithms::MultiDeviceMemoryOperations< Device, typename ArrayT::DeviceType >::
            compare( this->getData(),
                           array.getData(),
                           array.getSize() );
            compare( this->getData(), array.getData(), array.getSize() );
}

template< typename Value,
@@ -670,7 +668,7 @@ template< typename Value,
          typename Allocator >
void
Array< Value, Device, Index, Allocator >::
setValue( const ValueType& v,
setValue( ValueType v,
          IndexType begin,
          IndexType end )
{
@@ -742,7 +740,7 @@ template< typename Value,
         typename Result >
Result
Array< Value, Device, Index, Allocator >::
reduceElements( const Index begin, Index end, Fetch&& fetch, Reduce&& reduce, const Result& zero )
reduceElements( IndexType begin, IndexType end, Fetch&& fetch, Reduce&& reduce, const Result& zero )
{
   return this->getView().reduceElements( begin, end, fetch, reduce, zero );
}
@@ -756,7 +754,7 @@ template< typename Value,
         typename Result >
Result
Array< Value, Device, Index, Allocator >::
reduceElements( const Index begin, Index end, Fetch&& fetch, Reduce&& reduce, const Result& zero ) const
reduceElements( IndexType begin, IndexType end, Fetch&& fetch, Reduce&& reduce, const Result& zero ) const
{
   return this->getConstView().reduceElements( begin, end, fetch, reduce, zero );
}
@@ -795,7 +793,7 @@ template< typename Value,
          typename Allocator >
bool
Array< Value, Device, Index, Allocator >::
containsValue( const ValueType& v,
containsValue( ValueType value,
               IndexType begin,
               IndexType end ) const
{
@@ -803,7 +801,7 @@ containsValue( const ValueType& v,
   if( end == 0 )
      end = this->getSize();

   return Algorithms::MemoryOperations< Device >::containsValue( &this->getData()[ begin ], end - begin, v );
   return Algorithms::MemoryOperations< Device >::containsValue( &this->getData()[ begin ], end - begin, value );
}

template< typename Value,
@@ -812,7 +810,7 @@ template< typename Value,
          typename Allocator >
bool
Array< Value, Device, Index, Allocator >::
containsOnlyValue( const ValueType& v,
containsOnlyValue( ValueType value,
                   IndexType begin,
                   IndexType end ) const
{
@@ -820,7 +818,7 @@ containsOnlyValue( const ValueType& v,
   if( end == 0 )
      end = this->getSize();

   return Algorithms::MemoryOperations< Device >::containsOnlyValue( &this->getData()[ begin ], end - begin, v );
   return Algorithms::MemoryOperations< Device >::containsOnlyValue( &this->getData()[ begin ], end - begin, value );
}

template< typename Value,
+46 −46

File changed.

Preview size limit exceeded, changes collapsed.

+64 −51
Original line number Diff line number Diff line
@@ -32,7 +32,8 @@ template< typename Value,
          typename Index >
__cuda_callable__
ArrayView< Value, Device, Index >::
ArrayView( Value* data, Index size ) : data(data), size(size)
ArrayView( ValueType* data, IndexType size )
: data(data), size(size)
{
   TNL_ASSERT_GE( size, 0, "ArrayView size was initialized with a negative size." );
   TNL_ASSERT_TRUE( (data == nullptr && size == 0) || (data != nullptr && size > 0),
@@ -46,7 +47,7 @@ template< typename Value,
__cuda_callable__
void
ArrayView< Value, Device, Index >::
bind( Value* data, Index size )
bind( ValueType* data, IndexType size )
{
   TNL_ASSERT_GE( size, 0, "ArrayView size was initialized with a negative size." );
   TNL_ASSERT_TRUE( (data == nullptr && size == 0) || (data != nullptr && size > 0),
@@ -60,7 +61,9 @@ template< typename Value,
          typename Device,
          typename Index >
__cuda_callable__
void ArrayView< Value, Device, Index >::bind( ArrayView view )
void
ArrayView< Value, Device, Index >::
bind( ArrayView view )
{
   bind( view.getData(), view.getSize() );
}
@@ -71,7 +74,7 @@ template< typename Value,
__cuda_callable__
typename ArrayView< Value, Device, Index >::ViewType
ArrayView< Value, Device, Index >::
getView( const IndexType begin, IndexType end )
getView( IndexType begin, IndexType end )
{
   if( end == 0 )
      end = this->getSize();
@@ -84,7 +87,7 @@ template< typename Value,
__cuda_callable__
typename ArrayView< Value, Device, Index >::ConstViewType
ArrayView< Value, Device, Index >::
getConstView( const IndexType begin, IndexType end ) const
getConstView( IndexType begin, IndexType end ) const
{
   if( end == 0 )
      end = this->getSize();
@@ -157,8 +160,8 @@ template< typename Value,
          typename Device,
          typename Index >
__cuda_callable__
const
Value* ArrayView< Value, Device, Index >::
const Value*
ArrayView< Value, Device, Index >::
getData() const
{
   return data;
@@ -179,8 +182,8 @@ template< typename Value,
          typename Device,
          typename Index >
__cuda_callable__
const
Value* ArrayView< Value, Device, Index >::
const Value*
ArrayView< Value, Device, Index >::
getArrayData() const
{
   return data;
@@ -214,7 +217,7 @@ template< typename Value,
__cuda_callable__
void
ArrayView< Value, Device, Index >::
setElement( Index i, Value value )
setElement( IndexType i, ValueType value )
{
   TNL_ASSERT_GE( i, 0, "Element index must be non-negative." );
   TNL_ASSERT_LT( i, this->getSize(), "Element index is out of bounds." );
@@ -226,7 +229,7 @@ template< typename Value,
          typename Index >
__cuda_callable__ Value
ArrayView< Value, Device, Index >::
getElement( Index i ) const
getElement( IndexType i ) const
{
   TNL_ASSERT_GE( i, 0, "Element index must be non-negative." );
   TNL_ASSERT_LT( i, this->getSize(), "Element index is out of bounds." );
@@ -238,7 +241,7 @@ template< typename Value,
          typename Index >
__cuda_callable__
Value& ArrayView< Value, Device, Index >::
operator[]( Index i )
operator[]( IndexType i )
{
#ifdef __CUDA_ARCH__
   TNL_ASSERT_TRUE( (std::is_same< Device, Devices::Cuda >{}()), "Attempt to access data not allocated on CUDA device from CUDA device." );
@@ -254,9 +257,9 @@ template< typename Value,
          typename Device,
          typename Index >
__cuda_callable__
const
Value& ArrayView< Value, Device, Index >::
operator[]( Index i ) const
const Value&
ArrayView< Value, Device, Index >::
operator[]( IndexType i ) const
{
#ifdef __CUDA_ARCH__
   TNL_ASSERT_TRUE( (std::is_same< Device, Devices::Cuda >{}()), "Attempt to access data not allocated on CUDA device from CUDA device." );
@@ -302,7 +305,7 @@ template< typename Value,
          typename Index >
void
ArrayView< Value, Device, Index >::
setValue( Value value, const Index begin, Index end )
setValue( ValueType value, IndexType begin, IndexType end )
{
   TNL_ASSERT_GT( size, 0, "Attempted to set value to an empty array view." );
   if( end == 0 )
@@ -314,14 +317,15 @@ template< typename Value,
          typename Device,
          typename Index >
   template< typename Function >
void ArrayView< Value, Device, Index >::
forElements( const Index begin, Index end, Function&& f )
void
ArrayView< Value, Device, Index >::
forElements( IndexType begin, IndexType end, Function&& f )
{
   if( ! this->data )
      return;

   ValueType* d = this->getData();
   auto g = [=] __cuda_callable__ ( Index i ) mutable
   auto g = [=] __cuda_callable__ ( IndexType i ) mutable
   {
      f( i, d[ i ] );
   };
@@ -332,14 +336,15 @@ template< typename Value,
          typename Device,
          typename Index >
   template< typename Function >
void ArrayView< Value, Device, Index >::
forElements( const Index begin, Index end, Function&& f ) const
void
ArrayView< Value, Device, Index >::
forElements( IndexType begin, IndexType end, Function&& f ) const
{
   if( ! this->data )
      return;

   const ValueType* d = this->getData();
   auto g = [=] __cuda_callable__ ( Index i )
   auto g = [=] __cuda_callable__ ( IndexType i )
   {
      f( i, d[ i ] );
   };
@@ -350,7 +355,8 @@ template< typename Value,
          typename Device,
          typename Index >
   template< typename Function >
void ArrayView< Value, Device, Index >::
void
ArrayView< Value, Device, Index >::
forAllElements( Function&& f )
{
   this->forElements( 0, this->getSize(), f );
@@ -360,7 +366,8 @@ template< typename Value,
          typename Device,
          typename Index >
   template< typename Function >
void ArrayView< Value, Device, Index >::
void
ArrayView< Value, Device, Index >::
forAllElements( Function&& f ) const
{
   this->forElements( 0, this->getSize(), f );
@@ -372,8 +379,9 @@ template< typename Value,
   template< typename Fetch,
             typename Reduce,
             typename Result >
Result ArrayView< Value, Device, Index >::
reduceElements( Index begin, Index end, Fetch&& fetch, Reduce&& reduce, const Result& zero )
Result
ArrayView< Value, Device, Index >::
reduceElements( IndexType begin, IndexType end, Fetch&& fetch, Reduce&& reduce, const Result& zero )
{
   if( ! this->data )
      return zero;
@@ -389,8 +397,9 @@ template< typename Value,
   template< typename Fetch,
             typename Reduce,
             typename Result >
Result ArrayView< Value, Device, Index >::
reduceElements( Index begin, Index end, Fetch&& fetch, Reduce&& reduce, const Result& zero ) const
Result
ArrayView< Value, Device, Index >::
reduceElements( IndexType begin, IndexType end, Fetch&& fetch, Reduce&& reduce, const Result& zero ) const
{
   if( ! this->data )
      return;
@@ -406,7 +415,8 @@ template< typename Value,
   template< typename Fetch,
             typename Reduce,
             typename Result >
Result ArrayView< Value, Device, Index >::
Result
ArrayView< Value, Device, Index >::
reduceEachElement( Fetch&& fetch, Reduce&& reduce, const Result& zero )
{
   return this->reduceElements( 0, this->getSize(), fetch, reduce, zero );
@@ -418,7 +428,8 @@ template< typename Value,
   template< typename Fetch,
             typename Reduce,
             typename Result >
Result ArrayView< Value, Device, Index >::
Result
ArrayView< Value, Device, Index >::
reduceEachElement( Fetch&& fetch, Reduce&& reduce, const Result& zero ) const
{
   return this->reduceElements( 0, this->getSize(), fetch, reduce, zero );
@@ -429,9 +440,9 @@ template< typename Value,
          typename Index >
bool
ArrayView< Value, Device, Index >::
containsValue( Value value,
               const Index begin,
               Index end ) const
containsValue( ValueType value,
               IndexType begin,
               IndexType end ) const
{
   if( end == 0 )
      end = this->getSize();
@@ -443,33 +454,21 @@ template< typename Value,
          typename Index >
bool
ArrayView< Value, Device, Index >::
containsOnlyValue( Value value,
                   const Index begin,
                   Index end  ) const
containsOnlyValue( ValueType value,
                   IndexType begin,
                   IndexType end ) const
{
   if( end == 0 )
      end = this->getSize();
   return Algorithms::MemoryOperations< Device >::containsOnlyValue( &this->getData()[ begin ], end - begin, value );
}

template< typename Value, typename Device, typename Index >
std::ostream& operator<<( std::ostream& str, const ArrayView< Value, Device, Index >& view )
{
   str << "[ ";
   if( view.getSize() > 0 )
   {
      str << view.getElement( 0 );
      for( Index i = 1; i < view.getSize(); i++ )
         str << ", " << view.getElement( i );
   }
   str << " ]";
   return str;
}

template< typename Value,
          typename Device,
          typename Index >
void ArrayView< Value, Device, Index >::save( const String& fileName ) const
void
ArrayView< Value, Device, Index >::
save( const String& fileName ) const
{
   File( fileName, std::ios_base::out ) << *this;
}
@@ -484,6 +483,20 @@ load( const String& fileName )
   File( fileName, std::ios_base::in ) >> *this;
}

template< typename Value, typename Device, typename Index >
std::ostream& operator<<( std::ostream& str, const ArrayView< Value, Device, Index >& view )
{
   str << "[ ";
   if( view.getSize() > 0 )
   {
      str << view.getElement( 0 );
      for( Index i = 1; i < view.getSize(); i++ )
         str << ", " << view.getElement( i );
   }
   str << " ]";
   return str;
}

// Serialization of array views into binary files.
template< typename Value, typename Device, typename Index >
File& operator<<( File& file, const ArrayView< Value, Device, Index > view )
+5 −5

File changed.

Preview size limit exceeded, changes collapsed.

Loading