Notice: If you are member of any public project or group, please make sure that your GitLab username is not the same as the LRZ identifier/Kennung (see https://gitlab.lrz.de/profile/account). Please change your username if necessary. For more information see the section "Public projects / Öffentliche Projekte" at https://doku.lrz.de/display/PUBLIC/GitLab . Thank you!

...
 
Commits (10)
cmake_minimum_required(VERSION 3.9)
project(elsa VERSION 0.5
DESCRIPTION "elsa recon toolbox"
LANGUAGES CXX)
......@@ -6,11 +7,23 @@ project(elsa VERSION 0.5
# ------------ elsa options ------------
# ------------
option(ELSA_TESTING "Enable the unit tests of elsa" ON)
option(GIT_SUBMODULE "Check submodules during build" ON)
option(BUILD_ELSA_PROJECTORS_CUDA "Attempts to build CUDA projectors if set" ON)
# detect if elsa is being bundled, disable some options based on this
if (NOT DEFINED ELSA_MASTER_PROJECT)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(ELSA_MASTER_PROJECT ON)
else()
set(ELSA_MASTER_PROJECT OFF)
endif()
endif ()
option(ELSA_TESTING "Enable the unit tests of elsa" ${ELSA_MASTER_PROJECT})
option(ELSA_INSTALL "Generate the install target" ${ELSA_MASTER_PROJECT})
option(GIT_SUBMODULE "Check submodules during build" ${ELSA_MASTER_PROJECT})
option(ELSA_BUILD_EXAMPLES "Build examples" ${ELSA_MASTER_PROJECT})
option(ELSA_BUILD_CUDA_PROJECTORS "Attempts to build CUDA projectors if set" ON)
option(ELSA_BUILD_WITH_MORE_WARNINGS "Reduce noise of warnings, but make chaning fast and easy" OFF)
option(ELSA_BUILD_WITH_SANITIZERS "Build with Sanitizers. Pass ELSA_SANITIZE_THREAD or ELSA_SANITIZE_ADDRESS" ON)
# ------------ general setup -----------
# ------------
......@@ -25,37 +38,48 @@ include(SetDefaultBuildType)
# set where to install the exports/targets
set(INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake)
# ------------ dependencies ------------
# ------------
# include the git submodule update
include(UpdateGitSubmodules)
# include the InstallElsaModule function
include(InstallElsaModule)
# only populate the dependencies, iff it's a standalone project!
if(ELSA_MASTER_PROJECT)
# include the git submodule update
include(UpdateGitSubmodules)
# setup the Eigen3 library
find_package(Eigen3 3.3 NO_MODULE QUIET) # first try if there is an installed version
if(NOT EIGEN3_INCLUDE_DIR) # if not found, try our submodule
set(EIGEN3_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/thirdparty/eigen3")
message(STATUS "Using eigen3 submodule at ${EIGEN3_INCLUDE_DIR}")
# find Eigen Library
# if you're not using the submodules use set(EIGEN3_INCLUDE_DIR path/to/Eigen3) to point to the Eigen3 directory
find_package(Eigen3 3.3 REQUIRED)
message(STATUS "Using eigen3 submodule at ${EIGEN3_INCLUDE_DIR}")
# find spdlog Library
# if you're not using the submodules use set(Spdlog_INCLUDE_DIR path/to/spdlog) to point to the spdlog directory
find_package(Spdlog REQUIRED)
message(STATUS "Using spdlog submodule at ${Spdlog_INCLUDE_DIR}")
else()
message(STATUS " No dependencies added for elsa, as it's a subproject")
endif()
# include the In stallElsaModule function
include(InstallElsaModule)
# ------------ setup testing -----------
# ------------
# reset ELSA_TESTING to only be active, if it's a standlone project
if(NOT ELSA_MASTER_PROJECT)
set(ELSA_TESTING OFF)
endif(NOT ELSA_MASTER_PROJECT)
if(ELSA_TESTING)
message(STATUS "elsa testing is enabled")
enable_testing()
add_subdirectory(thirdparty/Catch2)
# add the CMake modules for automatic test discovery
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/thirdparty/Catch2/contrib" ${CMAKE_MODULE_PATH})
else(ELSA_TESTING)
message(STATUS "elsa testing is disabled")
message(STATUS " elsa testing is disabled")
endif(ELSA_TESTING)
......@@ -68,38 +92,41 @@ add_subdirectory(elsa)
# the documentation
add_subdirectory(docs EXCLUDE_FROM_ALL)
# the examples
add_subdirectory(examples EXCLUDE_FROM_ALL)
if(ELSA_BUILD_EXAMPLES)
# the examples
add_subdirectory(examples EXCLUDE_FROM_ALL)
endif(ELSA_BUILD_EXAMPLES)
# ------------ setup installation ------
# ------------
# set up the target/library for make install
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# setup the ElsaConfig*.cmake files
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/elsaConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIG_DIR}
)
# install the config files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfigVersion.cmake
DESTINATION ${INSTALL_CONFIG_DIR}
)
# this puts the local build tree into the user package repository, but not the installed version...
# ...but we rely on the paths in the installed version. sigh. commented out for now.
#export(PACKAGE elsa)
if(ELSA_INSTALL)
# set up the target/library for make install
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# setup the ElsaConfig*.cmake files
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/elsaConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIG_DIR}
)
# install the config files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/elsa/elsaConfigVersion.cmake
DESTINATION ${INSTALL_CONFIG_DIR}
)
# this puts the local build tree into the user package repository, but not the installed version...
# ...but we rely on the paths in the installed version. sigh. commented out for now.
#export(PACKAGE elsa)
endif(ELSA_INSTALL)
......@@ -19,6 +19,13 @@
#
# EIGEN3_ROOT
# EIGEN3_ROOT_DIR
#
# as well as in the following subdirectories:
#
# include
# thirdparty
# ThirdParty
# external
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
......@@ -80,11 +87,15 @@ else (EIGEN3_INCLUDE_DIR)
if(NOT EIGEN3_INCLUDE_DIR)
find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
HINTS
ENV EIGEN3_ROOT
ENV EIGEN3_ROOT_DIR
ENV EIGEN3_ROOT
ENV EIGEN3_ROOT_DIR
include
thirdparty
ThirdParty
external
PATHS
${CMAKE_INSTALL_PREFIX}/include
${KDE4_INCLUDE_DIR}
${CMAKE_INSTALL_PREFIX}/include
${KDE4_INCLUDE_DIR}
PATH_SUFFIXES eigen3 eigen
)
endif(NOT EIGEN3_INCLUDE_DIR)
......
# Find the spdlog include directory
#
# This module supports requiring a minimum version, e.g. you can do
# find_package(Spdlog 1.2.3)
# to require version 1.2.3 or newer of spdlog.
#
# The following variables are set if spdlog is found.
# Spdlog_FOUND - True when the spdlog include directory is found.
# Spdlog_INCLUDE_DIR - The path to where the spdlog include files are.
# Spdlog_VERSION - The version of spdlog version
#
# Further the following import target will be created, if Spdlog_FOUND is true
# spdlog::spdlog_header_only - The header-only spdlog library
#
# This module reads hints about search locations from
# the following environment variables:
#
# Spdlog_ROOT
# Spdlog_ROOT_DIR
#
# as well as in the following subdirectories
#
# include
# thirdparty
# ThirdParty
# external
#
#
# function to check version of spdlog
macro(_spdlog_check_version)
file(READ "${Spdlog_INCLUDE_DIR}/include/spdlog/version.h" _spdlog_version_header)
string(REGEX MATCH "define[ \t]+SPDLOG_VER_MAJOR[ \t]+([0-9]+)" _spdlog_major_version_match "${_spdlog_version_header}")
set(SPDLOG_MAJOR_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+SPDLOG_VER_MINOR[ \t]+([0-9]+)" _spdlog_minor_version_match "${_spdlog_version_header}")
set(SPDLOG_MINOR_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+SPDLOG_VER_PATCH[ \t]+([0-9]+)" _spdlog_patch_version_match "${_spdlog_version_header}")
set(SPDLOG_PATCH_VERSION "${CMAKE_MATCH_1}")
set(Spdlog_VERSION ${SPDLOG_MAJOR_VERSION}.${SPDLOG_MINOR_VERSION}.${SPDLOG_PATCH_VERSION})
if(${Spdlog_VERSION} VERSION_LESS ${Spdlog_FIND_VERSION})
set(Spdlog_VERSION_OK FALSE)
else(${Spdlog_VERSION} VERSION_LESS ${Spdlog_FIND_VERSION})
set(Spdlog_VERSION_OK TRUE)
endif(${Spdlog_VERSION} VERSION_LESS ${Spdlog_FIND_VERSION})
if(NOT Spdlog_VERSION_OK)
message(STATUS "spdlog version ${Spdlog_VERSION} found in ${Spdlog_INCLUDE_DIR}, but at least version ${Spdlog_FIND_VERSION} is required")
endif(NOT Spdlog_VERSION_OK)
endmacro(_spdlog_check_version)
# if no version is given, we just fall back to version 1.3.0
if(NOT Spdlog_FIND_VERSION)
if(NOT SPDLOG_MAJOR_VERSION)
set(SPDLOG_MAJOR_VERSION 1)
endif(NOT SPDLOG_MAJOR_VERSION)
if(NOT SPDLOG_MINOR_VERSION)
set(SPDLOG_MINOR_VERSION 3)
endif(NOT SPDLOG_MINOR_VERSION)
if(NOT SPDLOG_PATCH_VERSION)
set(SPDLOG_PATCH_VERSION 0)
endif(NOT SPDLOG_PATCH_VERSION)
set(Spdlog_FIND_VERSION "${SPDLOG_MAJOR_VERSION}.${SPDLOG_MINOR_VERSION}.${SPDLOG_PATCH_VERSION}")
endif(NOT Spdlog_FIND_VERSION)
find_package(PkgConfig)
if(EXISTS "${Spdlog_INCLUDE_DIR}")
_spdlog_check_version()
set(Spdlog_FOUND ${Spdlog_VERSION_OK})
else(EXISTS "${Spdlog_INCLUDE_DIR}")
# search first if an Eigen3Config.cmake is available in the system,
# if successful this would set EIGEN3_INCLUDE_DIR and the rest of
# the script will work as usual
find_package(Spdlog ${Spdlog_FIND_VERSION} NO_MODULE QUIET)
if(NOT Spdlog_INCLUDE_DIR)
find_path(Spdlog_INCLUDE_DIR
NAMES include/spdlog/spdlog.h
HINTS
ENV SPDLOG_ROOT
ENV SPDLOG_ROOT_DIR
include
thirdparty
ThirdParty
external
DOC "spdlog library header files"
PATH_SUFFIXES spdlog
)
message(DEBUG " spdlog dir ${Spdlog_INCLUDE_DIR}")
endif(NOT Spdlog_INCLUDE_DIR)
message(DEBUG " spdlog dir ${Spdlog_INCLUDE_DIR}")
if(Spdlog_INCLUDE_DIR)
_spdlog_check_version()
endif(Spdlog_INCLUDE_DIR)
set(Spdlog_FOUND 0)
endif(EXISTS "${Spdlog_INCLUDE_DIR}")
if(NOT Spdlog_FOUND)
message(STATUS "spdlog could not be found")
endif(NOT Spdlog_FOUND)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Spdlog DEFAULT_MSG Spdlog_INCLUDE_DIR Spdlog_VERSION_OK)
mark_as_advanced(Spdlog_INCLUDE_DIR)
if(Spdlog_FOUND AND NOT TARGET spdlog::spdlog_header_only)
add_library(spdlog::spdlog_header_only INTERFACE IMPORTED)
set_target_properties(spdlog::spdlog_header_only PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Spdlog_INCLUDE_DIR}/include")
endif(Spdlog_FOUND AND NOT TARGET spdlog::spdlog_header_only)
\ No newline at end of file
# install an elsa module
function(InstallElsaModule ELSA_MODULE_NAME ELSA_MODULE_TARGET_NAME ELSA_MODULE_EXPORT_TARGET)
#This is required so that the exported target has the name core and not elsa_core
set_target_properties(${ELSA_MODULE_TARGET_NAME} PROPERTIES EXPORT_NAME ${ELSA_MODULE_NAME})
if(ELSA_INSTALL)
#This is required so that the exported target has the name core and not elsa_core
set_target_properties(${ELSA_MODULE_TARGET_NAME} PROPERTIES EXPORT_NAME ${ELSA_MODULE_NAME})
include(GNUInstallDirs)
# install the module
install(TARGETS ${ELSA_MODULE_TARGET_NAME}
EXPORT ${ELSA_MODULE_EXPORT_TARGET}
INCLUDES DESTINATION include
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# install the header files
install(FILES ${MODULE_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ELSA_MODULE_NAME}
)
# create the config file for the module
install(EXPORT ${ELSA_MODULE_EXPORT_TARGET}
FILE ${ELSA_MODULE_EXPORT_TARGET}.cmake
NAMESPACE elsa::
DESTINATION ${INSTALL_CONFIG_DIR}
)
include(GNUInstallDirs)
# install the module
install(TARGETS ${ELSA_MODULE_TARGET_NAME}
EXPORT ${ELSA_MODULE_EXPORT_TARGET}
INCLUDES DESTINATION include
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# install the header files
install(FILES ${MODULE_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ELSA_MODULE_NAME}
)
# create the config file for the module
install(EXPORT ${ELSA_MODULE_EXPORT_TARGET}
FILE ${ELSA_MODULE_EXPORT_TARGET}.cmake
NAMESPACE elsa::
DESTINATION ${INSTALL_CONFIG_DIR}
)
endif(ELSA_INSTALL)
endfunction()
if(ELSA_SANITIZE_THREAD AND ELSA_SANITIZE_ADDRESS)
message(FATAL_ERROR "AddressSanitizer is not compatible with ThreadSanitizer.")
endif()
if(ELSA_SANITIZE_ADDRESS)
message(STATUS "AddressSanitizer enabled")
set(SANITIZER_FLAGS "-fsanitize=address,undefined")
add_compile_options("-fno-sanitize=signed-integer-overflow")
endif()
if(ELSA_SANITIZE_THREAD)
message(STATUS "ThreadSanitizer enabled")
set(SANITIZER_FLAGS "-fsanitize=thread")
endif()
if(ELSA_SANITIZE_THREAD OR ELSA_SANITIZE_ADDRESS)
add_compile_options(${SANITIZER_FLAGS})
add_compile_options("-fno-sanitize-recover=all")
add_compile_options("-fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS} -fuse-ld=gold")
endif()
......@@ -6,7 +6,6 @@ macro(registerComponent name)
set(ELSA_REGISTERED_COMPONENTS "${ELSA_REGISTERED_COMPONENTS};${name}" PARENT_SCOPE)
endmacro()
# add the elsa modules
add_subdirectory(core)
add_subdirectory(logging)
......@@ -16,11 +15,33 @@ add_subdirectory(functionals)
add_subdirectory(problems)
add_subdirectory(solvers)
add_subdirectory(projectors)
if(BUILD_ELSA_PROJECTORS_CUDA)
if(ELSA_BUILD_CUDA_PROJECTORS)
add_subdirectory(projectors_cuda)
endif(BUILD_ELSA_PROJECTORS_CUDA)
endif(ELSA_BUILD_CUDA_PROJECTORS)
add_subdirectory(generators)
#---------------------------------------------------------------------------------------
# Turn on compiler warnings and sanitizers for all components on, if wanted
#---------------------------------------------------------------------------------------
if(${ELSA_MASTER_PROJECT})
foreach (_component ${ELSA_REGISTERED_COMPONENTS})
# add warnings if enabled
if(${ELSA_BUILD_WITH_MORE_WARNINGS})
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
target_compile_options( elsa_${_component} PUBLIC -Wall -Wextra -Wconversion -pedantic -Wfatal-errors)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options( elsa_${_component} PUBLIC /W3 /WX )
endif()
endif(${ELSA_BUILD_WITH_MORE_WARNINGS})
endforeach (_component ELSA_REGISTERED_COMPONENTS)
# add sanitizers if enabled
if(${ELSA_BUILD_WITH_SANITIZERS})
include(${PROJECT_SOURCE_DIR}/cmake/Sanitizers.cmake)
endif(${ELSA_BUILD_WITH_SANITIZERS})
endif(${ELSA_MASTER_PROJECT})
# propogate the variable to the parent scope
set(ELSA_REGISTERED_COMPONENTS "${ELSA_REGISTERED_COMPONENTS};" PARENT_SCOPE)
......@@ -269,6 +269,78 @@ namespace elsa {
return !(*this == other);
}
template <typename data_t>
typename DataContainer<data_t>::iterator DataContainer<data_t>::begin()
{
return iterator(&(*this)[0]);
}
template <typename data_t>
typename DataContainer<data_t>::const_iterator DataContainer<data_t>::begin() const
{
return const_iterator(&(*this)[0]);
}
template <typename data_t>
typename DataContainer<data_t>::const_iterator DataContainer<data_t>::cbegin() const
{
return const_iterator(&(*this)[0]);
}
template <typename data_t>
typename DataContainer<data_t>::iterator DataContainer<data_t>::end()
{
return ++iterator(&(*this)[getSize()-1]);
}
template <typename data_t>
typename DataContainer<data_t>::const_iterator DataContainer<data_t>::end() const
{
return ++const_iterator(&(*this)[getSize()-1]);
}
template <typename data_t>
typename DataContainer<data_t>::const_iterator DataContainer<data_t>::cend() const
{
return ++const_iterator(&(*this)[getSize()-1]);
}
template <typename data_t>
typename DataContainer<data_t>::reverse_iterator DataContainer<data_t>::rbegin()
{
return reverse_iterator(end());
}
template <typename data_t>
typename DataContainer<data_t>::const_reverse_iterator DataContainer<data_t>::rbegin() const
{
return const_reverse_iterator(cend());
}
template <typename data_t>
typename DataContainer<data_t>::const_reverse_iterator DataContainer<data_t>::crbegin() const
{
return const_reverse_iterator(cend());
}
template <typename data_t>
typename DataContainer<data_t>::reverse_iterator DataContainer<data_t>::rend()
{
return reverse_iterator(begin());
}
template <typename data_t>
typename DataContainer<data_t>::const_reverse_iterator DataContainer<data_t>::rend() const
{
return const_reverse_iterator(cbegin());
}
template <typename data_t>
typename DataContainer<data_t>::const_reverse_iterator DataContainer<data_t>::crend() const
{
return const_reverse_iterator(cbegin());
}
// ------------------------------------------
// explicit template instantiation
template class DataContainer<float>;
......
......@@ -191,6 +191,53 @@ namespace elsa
/// comparison with another DataContainer
bool operator!=(const DataContainer<data_t>& other) const;
/* Iterators */
/// alias for iterator type, use a random vector access iterator
using iterator = typename std::vector<data_t>::iterator;
/// alias for const iterator type
using const_iterator = typename std::vector<data_t>::const_iterator;
/// alias for reverse iterator
using reverse_iterator = std::reverse_iterator<iterator>;
/// alias for const reverse iterator
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
/// returns iterator to beginning of vector
iterator begin();
/// returns iterator to beginning of vector, which can't mutate data
const_iterator begin() const;
/// returns iterator to beginning of vector, which can't mutate data
const_iterator cbegin() const;
/// returns iterator to end of vector
iterator end();
/// returns iterator to end of vector, which can't mutate data
const_iterator end() const;
/// returns iterator to end of vector, which can't mutate data
const_iterator cend() const;
/// returns reversed iterator to end of vector
reverse_iterator rbegin();
/// returns reversed iterator to end of vector, which can't mutate data
const_reverse_iterator rbegin() const;
/// returns reversed iterator to end of vector, which can't mutate data
const_reverse_iterator crbegin() const;
/// returns reversed iterator to beginning of vector
reverse_iterator rend();
/// returns reversed iterator to beginning of vector, which can't mutate data
const_reverse_iterator rend() const;
/// returns reversed iterator to beginning of vector, which can't mutate data
const_reverse_iterator crend() const;
private:
/// the current DataDescriptor
......
......@@ -371,6 +371,162 @@ SCENARIO("Testing the arithmetic operations with DataContainer arguments") {
REQUIRE(resultDivScalar[i] == dc[i] / scalar);
}
}
}
SCENARIO("Testing iterators for DataContainer") {
GIVEN("A 1D container") {
constexpr index_t size = 20;
IndexVector_t numCoeff(1);
numCoeff << size;
DataDescriptor desc(numCoeff);
DataContainer dc1(desc);
DataContainer dc2(desc);
Eigen::VectorXf randVec1 = Eigen::VectorXf::Random(size);
Eigen::VectorXf randVec2 = Eigen::VectorXf::Random(size);
for (index_t i = 0; i < size; ++i) {
dc1[i] = randVec1(i);
dc2[i] = randVec2(i);
}
THEN("We can iterate forward") {
int i = 0;
for(auto v : dc1) {
REQUIRE(v == randVec1[i++]);
}
REQUIRE(i == size);
}
THEN("We can iterate backward") {
int i = size;
for(auto v=dc1.crbegin(); v != dc1.crend(); v++) {
REQUIRE(*v == randVec1[--i]);
}
REQUIRE(i == 0);
}
THEN("We can iterate and mutate") {
int i = 0;
for(auto& v : dc1) {
v = v * 2;
REQUIRE(v == 2 * randVec1[i++]);
}
REQUIRE(i == size);
i = 0;
for(auto v : dc1) {
REQUIRE(v == 2 * randVec1[i++]);
}
REQUIRE(i == size);
}
THEN("We can use STL algorithms") {
REQUIRE(*std::min_element(dc1.cbegin(), dc1.cend()) == randVec1.minCoeff());
REQUIRE(*std::max_element(dc1.cbegin(), dc1.cend()) == randVec1.maxCoeff());
}
}
GIVEN("A 2D container") {
constexpr index_t size = 20;
IndexVector_t numCoeff(2);
numCoeff << size, size;
DataDescriptor desc(numCoeff);
DataContainer dc1(desc);
Eigen::VectorXf randVec1 = Eigen::VectorXf::Random(size * size);
for (index_t i = 0; i < size * size; ++i) {
dc1[i] = randVec1[i];
}
THEN("We can iterate forward") {
int i = 0;
for(auto v : dc1) {
REQUIRE(v == randVec1[i++]);
}
REQUIRE(i == size * size);
}
THEN("We can iterate backward") {
int i = size * size;
for(auto v=dc1.crbegin(); v != dc1.crend(); v++) {
REQUIRE(*v == randVec1[--i]);
}
REQUIRE(i == 0);
}
THEN("We can iterate and mutate") {
int i = 0;
for(auto& v : dc1) {
v = v * 2;
REQUIRE(v == 2 * randVec1[i++]);
}
REQUIRE(i == size * size);
i = 0;
for(auto v : dc1) {
REQUIRE(v == 2 * randVec1[i++]);
}
REQUIRE(i == size * size);
}
THEN("We can use STL algorithms") {
REQUIRE(*std::min_element(dc1.cbegin(), dc1.cend()) == randVec1.minCoeff());
REQUIRE(*std::max_element(dc1.cbegin(), dc1.cend()) == randVec1.maxCoeff());
}
}
GIVEN("A 3D container") {
constexpr index_t size = 20;
IndexVector_t numCoeff(3);
numCoeff << size, size, size;
DataDescriptor desc(numCoeff);
DataContainer dc1(desc);
Eigen::VectorXf randVec1 = Eigen::VectorXf::Random(size * size * size);
for (index_t i = 0; i < size * size * size; ++i) {
dc1[i] = randVec1[i];
}
THEN("We can iterate forward") {
int i = 0;
for(auto v : dc1) {
REQUIRE(v == randVec1[i++]);
}
REQUIRE(i == size * size * size);
}
THEN("We can iterate backward") {
int i = size * size * size;
for(auto v=dc1.crbegin(); v != dc1.crend(); v++) {
REQUIRE(*v == randVec1[--i]);
}
REQUIRE(i == 0);
}
THEN("We can iterate and mutate") {
int i = 0;
for(auto& v : dc1) {
v = v * 2;
REQUIRE(v == 2 * randVec1[i++]);
}
REQUIRE(i == size * size * size);
i = 0;
for(auto v : dc1) {
REQUIRE(v == 2 * randVec1[i++]);
}
REQUIRE(i == size * size * size);
}
THEN("We can use STL algorithms") {
REQUIRE(*std::min_element(dc1.cbegin(), dc1.cend()) == randVec1.minCoeff());
REQUIRE(*std::max_element(dc1.cbegin(), dc1.cend()) == randVec1.maxCoeff());
}
}
}
\ No newline at end of file
......@@ -29,10 +29,7 @@ target_include_directories(${ELSA_MODULE_TARGET_NAME}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
target_include_directories(${ELSA_MODULE_TARGET_NAME}
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/thirdparty/spdlog/include>
)
target_link_libraries(${ELSA_MODULE_TARGET_NAME} PUBLIC spdlog::spdlog_header_only)
# require C++17
target_compile_features(${ELSA_MODULE_TARGET_NAME} PUBLIC cxx_std_17)
......@@ -50,4 +47,4 @@ endif(ELSA_TESTING)
registerComponent(${ELSA_MODULE_NAME})
# install the module
InstallElsaModule(${ELSA_MODULE_NAME} ${ELSA_MODULE_TARGET_NAME} ${ELSA_MODULE_EXPORT_TARGET})
\ No newline at end of file
InstallElsaModule(${ELSA_MODULE_NAME} ${ELSA_MODULE_TARGET_NAME} ${ELSA_MODULE_EXPORT_TARGET})