Commit f8c8673d authored by Jakub Klinkovský's avatar Jakub Klinkovský

ArrayOperations: added missing methods for the static/sequential specialization

parent 7a5840de
......@@ -48,6 +48,14 @@ struct ArrayOperations< void >
const SourceElement* source,
const Index size );
template< typename DestinationElement,
typename Index,
typename SourceIterator >
static void copyFromIterator( DestinationElement* destination,
Index destinationSize,
SourceIterator first,
SourceIterator last );
template< typename Element1,
typename Element2,
typename Index >
......@@ -55,6 +63,20 @@ struct ArrayOperations< void >
static bool compare( const Element1* destination,
const Element2* source,
const Index size );
template< typename Element,
typename Index >
__cuda_callable__
static bool containsValue( const Element* data,
const Index size,
const Element& value );
template< typename Element,
typename Index >
__cuda_callable__
static bool containsOnlyValue( const Element* data,
const Index size,
const Element& value );
};
template<>
......
......@@ -61,6 +61,23 @@ copy( DestinationElement* destination,
destination[ i ] = source[ i ];
}
template< typename DestinationElement,
typename Index,
typename SourceIterator >
void
ArrayOperations< void >::
copyFromIterator( DestinationElement* destination,
Index destinationSize,
SourceIterator first,
SourceIterator last )
{
Index i = 0;
while( i < destinationSize && first != last )
destination[ i++ ] = *first++;
if( first != last )
throw std::length_error( "Source iterator is larger than the destination array." );
}
template< typename Element1,
typename Element2,
typename Index >
......@@ -77,6 +94,44 @@ compare( const Element1* destination,
return true;
}
template< typename Element,
typename Index >
__cuda_callable__
bool
ArrayOperations< void >::
containsValue( const Element* data,
const Index size,
const Element& value )
{
if( size == 0 ) return false;
TNL_ASSERT_TRUE( data, "Attempted to check data through a nullptr." );
TNL_ASSERT_GE( size, 0, "" );
for( Index i = 0; i < size; i++ )
if( data[ i ] == value )
return true;
return false;
}
template< typename Element,
typename Index >
__cuda_callable__
bool
ArrayOperations< void >::
containsOnlyValue( const Element* data,
const Index size,
const Element& value )
{
if( size == 0 ) return false;
TNL_ASSERT_TRUE( data, "Attempted to check data through a nullptr." );
TNL_ASSERT_GE( size, 0, "" );
for( Index i = 0; i < size; i++ )
if( ! ( data[ i ] == value ) )
return false;
return true;
}
} // namespace Algorithms
} // namespace Containers
} // namespace TNL
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment