Skip to content

Commit 5009bf7

Browse files
CusiniMcorbett5rrsettgast
authored
ci: activate lvarray bound checks on ci. (#344)
* Made some sorted error checks associated with bounds checking. * ci: activate lvarray bound checks on ci. * add set for release. --------- Co-authored-by: Benjamin Curtice Corbett <[email protected]> Co-authored-by: Randolph Settgast <[email protected]>
1 parent b1074b1 commit 5009bf7

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

cmake/CMakeBasics.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
set(CMAKE_ENABLE_EXPORTS ON)
2+
option( LVARRAY_BOUNDS_CHECK "Enable bounds checking in LvArray" OFF )
23

34
if( CMAKE_BUILD_TYPE MATCHES "Debug" )
4-
option( LVARRAY_BOUNDS_CHECK "" ON )
5+
set( LVARRAY_BOUNDS_CHECK ON CACHE BOOL "")
56
else()
6-
option( LVARRAY_BOUNDS_CHECK "" OFF )
7+
set( LVARRAY_BOUNDS_CHECK OFF CACHE BOOL "")
78
endif()
89

9-
1010
option( ENABLE_TOTALVIEW_OUTPUT "" OFF )
1111

1212
set( LVARRAY_BUILD_OBJ_LIBS OFF CACHE BOOL "" )

src/sortedArrayManipulation.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ template< typename ITER, typename Compare=less< typename std::iterator_traits< I
306306
LVARRAY_HOST_DEVICE inline
307307
std::ptrdiff_t removeDuplicates( ITER first, ITER const last, Compare && comp=Compare() )
308308
{
309-
LVARRAY_ASSERT( isSorted( first, last, comp ) );
309+
#ifdef LVARRAY_BOUNDS_CHECK
310+
LVARRAY_ERROR_IF( !isSorted( first, last, comp ), "Input needs to be sorted" );
311+
#endif
310312

311313
if( first == last )
312314
{
@@ -520,7 +522,9 @@ std::ptrdiff_t remove( T * const LVARRAY_RESTRICT ptr,
520522
LVARRAY_ASSERT( arrayManipulation::isPositive( size ) );
521523
LVARRAY_ASSERT( isSortedUnique( ptr, ptr + size ) );
522524

523-
LVARRAY_ASSERT( isSortedUnique( first, last ) );
525+
#ifdef LVARRAY_BOUNDS_CHECK
526+
LVARRAY_ERROR_IF( !isSortedUnique( first, last ), "Input needs to be unique and sorted." );
527+
#endif
524528

525529
// Find the position of the first value to remove and the position it's at in the array.
526530
ITER valueToRemove = first;
@@ -683,7 +687,9 @@ std::ptrdiff_t insert( T * const LVARRAY_RESTRICT ptr,
683687
LVARRAY_ASSERT( arrayManipulation::isPositive( size ) );
684688
LVARRAY_ASSERT( isSortedUnique( ptr, ptr + size ) );
685689

686-
LVARRAY_ASSERT( isSortedUnique( first, last ) );
690+
#ifdef LVARRAY_BOUNDS_CHECK
691+
LVARRAY_ERROR_IF( !isSortedUnique( first, last ), "Input needs to be unique and sorted." );
692+
#endif
687693

688694
// Special case for inserting into an empty array.
689695
if( size == 0 )

0 commit comments

Comments
 (0)