Commit 0eb9b6e8 authored by ESTERIE Pierre's avatar ESTERIE Pierre

Some more work with tensors

parent 43f1e6fc
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 3
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 2
UseTab: Never
......@@ -89,6 +89,7 @@ if(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/morse_cmake"
option( SCALFMM_USE_LOG "Set to ON to print output debug information" OFF )
option( SCALFMM_USE_MEM_STATS "Set to ON to profile memory" OFF )
option( SCALFMM_ONLY_DEVEL "Set to ON to compile Development tools (only scalfmm team)" ON )
set(SCALFMM_COMPILE_DEFINITIONS "${SCALFMM_COMPILE_DEFINITIONS}" CACHE STRING "Global compile definitions for ScalFMM")
#
# Set scalfmm dev flags
......@@ -149,6 +150,9 @@ if(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/morse_cmake"
endif(xtl_FOUND)
find_package(xtensor CONFIG REQUIRED)
if(xtensor_FOUND)
if(xsimd_FOUND)
list(APPEND SCALFMM_COMPILE_DEFINITIONS XTENSOR_USE_XSIMD)
endif(xsimd_FOUND)
message(STATUS "XTENSOR found")
target_link_libraries(${CMAKE_PROJECT_NAME} INTERFACE xtensor)
else(xtensor_FOUND)
......@@ -455,7 +459,6 @@ if(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/morse_cmake"
#
# Set ScalFMM compile definitions
# -------------------------------
set(SCALFMM_COMPILE_DEFINITIONS "${SCALFMM_COMPILE_DEFINITIONS}" CACHE STRING "Global compile definitions for ScalFMM")
message(STATUS "ScalFMM compile definitions : ${SCALFMM_COMPILE_DEFINITIONS}")
# And adding definitions to target
# --------------------------------
......@@ -496,7 +499,7 @@ if(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/morse_cmake"
if(SCALFMM_USE_STATIC_ANALYSIS AND SCALFMM_USE_CLANGTIDY)
find_program(CLANGTIDY "clang-tidy")
if(CLANGTIDY)
set(CMAKE_CXX_CLANG_TIDY "${CLANGTIDY};-checks=-*,boost-*,cppcoreguidelines-*,clang-analyser-cplusplus*,modernize-*,mpi-*,performance-*,portability-*,readability-*")
set(CMAKE_CXX_CLANG_TIDY "${CLANGTIDY};--header-filter=${CMAKE_SOURCE_DIR}/include/scalfmm/.;--checks=-*,boost-*,cppcoreguidelines-*,clang-analyser-cplusplus*,modernize-*,mpi-*,performance-*,portability-*,readability-*")
message(STATUS "Clang Tidy analysis is ON.")
endif()
endif(SCALFMM_USE_STATIC_ANALYSIS AND SCALFMM_USE_CLANGTIDY)
......
......@@ -3,10 +3,11 @@
# List of source files
set(source_tests_files
sandbox.cpp
test-blas.cpp
test-xtensor.cpp
)
sandbox.cpp
test_tensorial_interpolator.cpp
test-blas.cpp
test-xtensor.cpp
)
# Add execs - 1 cpp = 1 exec
foreach(exec ${source_tests_files})
......
This diff is collapsed.
#include <algorithm>
#include <array>
#include <chrono>
#include <functional>
#include <iostream>
#include <random>
#include <xtensor/xarray.hpp>
#include <xtensor/xio.hpp>
#include <scalfmm/container/particle.hpp>
#include <scalfmm/container/particle_container.hpp>
#include <scalfmm/interpolation/uniform.hpp>
#include <scalfmm/tools/colorized.hpp>
#include <scalfmm/tree/box.hpp>
int main()
{
using size_type = std::size_t;
namespace colors = scalfmm::colors;
constexpr size_type particle_dim{3};
constexpr size_type potential_dim{3};
constexpr size_type order{6};
using particle_type = scalfmm::container::particle<double, particle_dim, double, double, double>;
using point_type = scalfmm::container::point<double, particle_dim>;
using container_type = scalfmm::container::particle_container<particle_type>;
using interpolator_type = scalfmm::interpolation::uniform_interpolator<double, particle_dim>;
const size_type nb_particles{5000};
const size_type tree_height{5};
const double width{3.723};
container_type particles_source{nb_particles};
container_type particles_target{nb_particles};
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<double> dis(-1.0, 1.0);
auto random_r = [&dis, &gen]() { return dis(gen); };
point_type center = {0., 0., 0.};
auto make_particle = [&tree_height, &center, &width, &random_r]() {
point_type position = {random_r() * width, random_r() * width, random_r() * width};
position += center;
particle_type p(position, random_r(), random_r(), random_r());
return p.as_tuple();
};
std::generate(particles_source.begin(), particles_source.end(), make_particle);
center = {2. * width, 0., 0.};
std::generate(particles_target.begin(), particles_target.end(), make_particle);
auto start = std::chrono::high_resolution_clock::now();
interpolator_type s(order, tree_height);
auto end = std::chrono::high_resolution_clock::now();
std::cout << colors::green << "Interpolator construction time : "
<< std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << "ms\n"
<< colors::reset;
return 0;
}
......@@ -5,19 +5,27 @@
namespace scalfmm::meta
{
template<typename T, typename U,
typename = std::enable_if_t<std::is_floating_point<T>::value,T>,
typename = std::enable_if_t<std::is_floating_point<U>::value,U>>
constexpr bool feq(const T& a, const U& b, T epsilon = 1e-7)
{
return a - b < epsilon && b - a < epsilon;
}
template<typename T, typename U, typename = std::enable_if_t<std::is_floating_point<T>::value, T>,
typename = std::enable_if_t<std::is_floating_point<U>::value, U>>
constexpr bool feq(const T& a, const U& b, T epsilon = 1e-7)
{
return a - b < epsilon && b - a < epsilon;
}
template<typename T>
constexpr T pow(T a, std::size_t p)
{
return p == 0 ? 1 : a * pow<T>(a, p-1);
}
}
template<typename T>
constexpr T pow(T a, std::size_t p)
{
return p == 0 ? 1 : a * pow<T>(a, p - 1);
}
template<typename T>
inline T pow(T a, int p)
{
T result = 1;
while(p-- > 0)
result *= a;
return result;
}
} // namespace scalfmm::meta
#endif
......@@ -10,54 +10,84 @@
namespace scalfmm::meta
{
// Equality comparable traits
namespace details
{
inline constexpr auto is_equality_comparable_impl = meta::is_valid([](auto&& a, auto&& b)->decltype(a==b){});
inline constexpr auto has_begin = meta::is_valid([](auto&& a)->decltype(a.begin()){});
inline constexpr auto has_end = meta::is_valid([](auto&& a)->decltype(a.end()){});
}
// Equality comparable traits
namespace details
{
inline constexpr auto is_equality_comparable_impl =
meta::is_valid([](auto&& a, auto&& b) -> decltype(a == b) {});
inline constexpr auto has_begin = meta::is_valid([](auto&& a) -> decltype(a.begin()) {});
inline constexpr auto has_end = meta::is_valid([](auto&& a) -> decltype(a.end()) {});
inline constexpr auto has_plus = meta::is_valid([](auto&& a, auto&&b) ->decltype(a+b) {});
} // namespace details
template<class T>
struct is_equality_comparable
{
static const bool value = decltype(details::is_equality_comparable_impl(T{},T{}))::value;
};
template<class T>
struct is_equality_comparable
{
static const bool value = decltype(details::is_equality_comparable_impl(T{}, T{}))::value;
};
template<class T>
struct has_begin { static const bool value = decltype(details::has_begin(T{}))::value; };
template<typename T>
struct has_end { static const bool value = decltype(details::has_end(T{}))::value; };
template<class T>
struct has_begin
{
static const bool value = decltype(details::has_begin(T{}))::value;
};
template<typename T>
struct has_end
{
static const bool value = decltype(details::has_end(T{}))::value;
};
template<class T>
struct has_range_interface { static const bool value = has_begin<T>::value && has_end<T>::value; };
template<class T>
struct has_range_interface
{
static const bool value = has_begin<T>::value && has_end<T>::value;
};
template< class, class = std::void_t<> >
struct is_float : std::false_type { };
template<class, class = std::void_t<>>
struct is_float : std::false_type
{
};
// specialization recognizes types that do have a nested ::type member:
template< class T >
struct is_float<T, std::void_t<float>> : std::true_type { };
// specialization recognizes types that do have a nested ::type member:
template<class T>
struct is_float<T, std::void_t<float>> : std::true_type
{
};
template< class, class = std::void_t<> >
struct is_double : std::false_type { };
template<class, class = std::void_t<>>
struct is_double : std::false_type
{
};
// specialization recognizes types that do have a nested ::type member:
template< class T >
struct is_double<T, std::void_t<double>> : std::true_type { };
// specialization recognizes types that do have a nested ::type member:
template<class T>
struct is_double<T, std::void_t<double>> : std::true_type
{
};
// Tuple cat
template<typename T, typename U>
struct tuple_cat
{ using type = decltype(std::tuple_cat(T{},U{})); };
// Tuple cat
template<typename T, typename U>
struct tuple_cat
{
using type = decltype(std::tuple_cat(T{}, U{}));
};
template<typename, typename = std::void_t<>>
struct has_value_type : std::false_type{};
template<typename, typename = std::void_t<>>
struct has_value_type : std::false_type
{
};
template<typename T>
struct has_value_type<T, std::void_t<typename T::value_type>> : std::true_type{};
template<typename T>
struct has_value_type<T, std::void_t<typename T::value_type>> : std::true_type
{
};
template<typename T>
struct is_addable
{
static const bool value = decltype(details::has_plus(T{},T{}))::value;
};
} // namespace scalfmm::meta
} // namespace scalfmm::meta
#endif
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