Commit 96ffbe9c authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

NDArray: move asserts into the getStorageIndex method

parent 3158530a
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -167,9 +167,6 @@ public:
   operator()( IndexTypes&&... indices )
   {
      static_assert( sizeof...( indices ) == getDimension(), "got wrong number of indices" );
      __ndarray_impl::assertIndicesInBounds( getSizes(), OverlapsType{}, std::forward< IndexTypes >( indices )... );
      TNL_ASSERT_LT( getStorageIndex( std::forward< IndexTypes >( indices )... ), getStorageSize(),
                     "storage index out of bounds - either input error or a bug in the indexer" );
      return array[ getStorageIndex( std::forward< IndexTypes >( indices )... ) ];
   }

@@ -179,9 +176,6 @@ public:
   operator()( IndexTypes&&... indices ) const
   {
      static_assert( sizeof...( indices ) == getDimension(), "got wrong number of indices" );
      __ndarray_impl::assertIndicesInBounds( getSizes(), OverlapsType{}, std::forward< IndexTypes >( indices )... );
      TNL_ASSERT_LT( getStorageIndex( std::forward< IndexTypes >( indices )... ), getStorageSize(),
                     "storage index out of bounds - either input error or a bug in the indexer" );
      return array[ getStorageIndex( std::forward< IndexTypes >( indices )... ) ];
   }

@@ -294,9 +288,6 @@ public:
   getElement( IndexTypes&&... indices ) const
   {
      static_assert( sizeof...( indices ) == getDimension(), "got wrong number of indices" );
      __ndarray_impl::assertIndicesInBounds( getSizes(), OverlapsType{}, std::forward< IndexTypes >( indices )... );
      TNL_ASSERT_LT( getStorageIndex( std::forward< IndexTypes >( indices )... ), getStorageSize(),
                     "storage index out of bounds - either input error or a bug in the indexer" );
      return array.getElement( getStorageIndex( std::forward< IndexTypes >( indices )... ) );
   }

+13 −4
Original line number Diff line number Diff line
@@ -91,10 +91,19 @@ public:
   getStorageIndex( IndexTypes&&... indices ) const
   {
      static_assert( sizeof...( indices ) == SizesHolder::getDimension(), "got wrong number of indices" );
      return Base::template getStorageIndex< Permutation, Overlaps >
      __ndarray_impl::assertIndicesInBounds( getSizes(), OverlapsType{}, std::forward< IndexTypes >( indices )... );
      const IndexType result = Base::template getStorageIndex< Permutation, Overlaps >
                               ( sizes,
                                 static_cast< const StridesHolder& >( *this ),
                                 std::forward< IndexTypes >( indices )... );
      TNL_ASSERT_GE( result, (IndexType) 0,
                     "storage index out of bounds - either input error or a bug in the indexer" );
      // upper bound can be checked only for contiguous arrays/views
      if( StridesHolder::isContiguous() ) {
         TNL_ASSERT_LT( result, getStorageSize(),
                        "storage index out of bounds - either input error or a bug in the indexer" );
      }
      return result;
   }

protected:
+0 −2
Original line number Diff line number Diff line
@@ -223,7 +223,6 @@ public:
   operator()( IndexTypes&&... indices )
   {
      static_assert( sizeof...( indices ) == getDimension(), "got wrong number of indices" );
      __ndarray_impl::assertIndicesInBounds( getSizes(), OverlapsType{}, std::forward< IndexTypes >( indices )... );
      return array[ getStorageIndex( std::forward< IndexTypes >( indices )... ) ];
   }

@@ -233,7 +232,6 @@ public:
   operator()( IndexTypes&&... indices ) const
   {
      static_assert( sizeof...( indices ) == getDimension(), "got wrong number of indices" );
      __ndarray_impl::assertIndicesInBounds( getSizes(), OverlapsType{}, std::forward< IndexTypes >( indices )... );
      return array[ getStorageIndex( std::forward< IndexTypes >( indices )... ) ];
   }