/**************************************************************************** * Copyright (c) 2017-2022 by the ArborX authors * * All rights reserved. * * * * This file is part of the ArborX library. ArborX is * * distributed under a BSD 3-clause license. For the licensing terms see * * the LICENSE file in the top-level directory. * * * * SPDX-License-Identifier: BSD-3-Clause * ****************************************************************************/ #include #include #include #include using ArborX::Details::check_valid_access_traits; using ArborX::Details::CheckReturnTypeTag; // NOTE Let's not bother with __host__ __device__ annotations here struct NoAccessTraitsSpecialization {}; struct EmptySpecialization {}; template struct ArborX::AccessTraits {}; struct InvalidMemorySpace {}; template struct ArborX::AccessTraits { using memory_space = void; }; struct MissingSizeMemberFunction {}; template struct ArborX::AccessTraits { using memory_space = Kokkos::HostSpace; }; struct SizeMemberFunctionNotStatic {}; template struct ArborX::AccessTraits { using memory_space = Kokkos::HostSpace; int size(SizeMemberFunctionNotStatic) { return 255; } }; struct MissingGetMemberFunction {}; template struct ArborX::AccessTraits { using memory_space = Kokkos::HostSpace; static int size(MissingGetMemberFunction) { return 255; } }; struct GetMemberFunctionNotStatic {}; template struct ArborX::AccessTraits { using memory_space = Kokkos::HostSpace; static int size(GetMemberFunctionNotStatic) { return 255; } ArborX::Point<3> get(GetMemberFunctionNotStatic, int) { return {}; } }; struct GetMemberFunctionVoid {}; template struct ArborX::AccessTraits { using memory_space = Kokkos::HostSpace; static int size(GetMemberFunctionVoid) { return 255; } static void get(GetMemberFunctionVoid, int) {} }; template using deduce_type_t = decltype(ArborX::AccessTraits::get(std::declval(), 0)); void test_access_traits_compile_only() { using Point = ArborX::Point<3>; Kokkos::View p; Kokkos::View v; check_valid_access_traits(p); check_valid_access_traits(v); auto p_with_indices = ArborX::Experimental::attach_indices(p); check_valid_access_traits(p_with_indices); static_assert(std::is_same_v, ArborX::PairValueIndex>); auto p_with_indices_long = ArborX::Experimental::attach_indices(p); static_assert(std::is_same_v, ArborX::PairValueIndex>); using NearestPredicate = decltype(ArborX::nearest(Point{})); Kokkos::View q; check_valid_access_traits(q, CheckReturnTypeTag{}); auto q_with_indices = ArborX::Experimental::attach_indices(q); check_valid_access_traits(q_with_indices, CheckReturnTypeTag{}); using predicate = deduce_type_t; static_assert( std::is_same_v< std::decay_t()))>, long>); struct CustomIndex { char index; CustomIndex(int i) { index = i; } }; auto q_with_custom_indices = ArborX::Experimental::attach_indices(q); check_valid_access_traits(q_with_custom_indices, CheckReturnTypeTag{}); using predicate_custom = deduce_type_t; static_assert(std::is_same_v()))>, CustomIndex>); // Uncomment to see error messages // check_valid_access_traits(NoAccessTraitsSpecialization{}); // check_valid_access_traits(EmptySpecialization{}); // check_valid_access_traits(InvalidMemorySpace{}); // check_valid_access_traits(MissingSizeMemberFunction{}); // check_valid_access_traits(SizeMemberFunctionNotStatic{}); // check_valid_access_traits(MissingGetMemberFunction{}); // check_valid_access_traits(GetMemberFunctionNotStatic{}); // check_valid_access_traits(GetMemberFunctionVoid{}); } void test_deduce_point_type_from_view() { using ArborX::Point; static_assert( std::is_same_v>, Point<3>>); static_assert( std::is_same_v>, Point<3>>); static_assert( std::is_same_v>, Point<2>>); static_assert( std::is_same_v>, Point<5>>); }