Skip to content

Commit

Permalink
Separate checks for slice and View particle sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Jun 30, 2023
1 parent 1ef6b51 commit 71b7854
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/Cabana_ParticleInit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ void createParticles(
Kokkos::is_view<PositionType>::value ),
int>::type* = 0 )
{
// Ensure correct space for the particles.
assert( positions.size() == num_particles );
// Ensure correct space for the particles (View or Slice).
checkSize( positions, num_particles );

using PoolType = Kokkos::Random_XorShift64_Pool<ExecutionSpace>;
using RandomType = Kokkos::Random_XorShift64<ExecutionSpace>;
Expand Down
18 changes: 18 additions & 0 deletions core/src/Cabana_Slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,24 @@ void copyViewToSlice( ViewType& view, const SliceType& slice,
copyViewToSlice( exec_space{}, view, slice, begin, end );
}

// Check slice size.
template <class SliceType>
void checkSize(
SliceType slice, const std::size_t size,
typename std::enable_if<is_slice<SliceType>::value, int>::type* = 0 )
{
assert( slice.size() == size );
}

// Check View size.
template <class ViewType>
void checkSize(
ViewType view, const std::size_t size,
typename std::enable_if<Kokkos::is_view<ViewType>::value, int>::type* = 0 )
{
assert( view.extent( 0 ) == size );
}

//---------------------------------------------------------------------------//

} // end namespace Cabana
Expand Down

0 comments on commit 71b7854

Please sign in to comment.