From 491addb20126466b97bbc945603123709ca099d8 Mon Sep 17 00:00:00 2001 From: Joel Falcou Date: Wed, 7 May 2025 17:01:58 +0200 Subject: [PATCH] Infrastructure de base --- CMakeLists.txt | 61 ++++++++++++++++++++ LICENSE.md | 23 ++++++++ cmake/config/rotgen-install.cmake | 27 +++++++++ cmake/rotgen-config.cmake | 11 ++++ include/rotgen/impl/matrix_impl64.hpp | 43 ++++++++++++++ include/rotgen/matrix.hpp | 49 ++++++++++++++++ src/matrix_impl64.cpp | 82 +++++++++++++++++++++++++++ 7 files changed, 296 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 LICENSE.md create mode 100644 cmake/config/rotgen-install.cmake create mode 100644 cmake/rotgen-config.cmake create mode 100644 include/rotgen/impl/matrix_impl64.hpp create mode 100644 include/rotgen/matrix.hpp create mode 100644 src/matrix_impl64.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..fec05b7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,61 @@ +##====================================================================================================================== +## ROTGEN - Runtime Overlay for Eigen +## Copyright : CODE RECKONS +## SPDX-License-Identifier: BSL-1.0 +##====================================================================================================================== +cmake_minimum_required(VERSION 3.22) +enable_testing() + +##====================================================================================================================== +## Setup project +##====================================================================================================================== +set(ROTGEN_MAJOR_VERSION 0) +set(ROTGEN_MINOR_VERSION 0) +set(ROTGEN_PATCH_VERSION 1) +set(ROTGEN_VERSION ${ROTGEN_MAJOR_VERSION}.${ROTGEN_MINOR_VERSION}.${ROTGEN_PATCH_VERSION}) + +set(PROJECT_VERSION ${ROTGEN_VERSION}) +project(ROTGEN VERSION ${PROJECT_VERSION} DESCRIPTION "Runtime Overlay for Eigen" LANGUAGES CXX) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ROTGEN_SOURCE_DIR}/cmake ) + +##====================================================================================================================== +## Prevent in-source build +##====================================================================================================================== +if (${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) + message(FATAL_ERROR "[${PROJECT_NAME}]: In-source build is not supported") +endif() + +##====================================================================================================================== +## Sources & Public Headers lists +##====================================================================================================================== +set ( SOURCES + src/matrix_impl64.cpp + ) + +##====================================================================================================================== +## Setup the library's dependencies +##====================================================================================================================== +find_package (Eigen3 3.4 REQUIRED NO_MODULE) + +##====================================================================================================================== +## Setup the library's build +##====================================================================================================================== +add_library(rotgen SHARED ${SOURCES}) +set_target_properties(rotgen PROPERTIES VERSION ${PROJECT_VERSION}) +set_target_properties(rotgen PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}) + +target_compile_features(rotgen INTERFACE cxx_std_17) +set_target_properties(rotgen PROPERTIES EXPORT_NAME rotgen) +add_library(rotgen::rotgen ALIAS rotgen) + +target_include_directories(rotgen PUBLIC + $ + $ +) + +target_link_libraries (rotgen PRIVATE Eigen3::Eigen) + +##====================================================================================================================== +## Setup the library's installation target +##====================================================================================================================== +include(${ROTGEN_SOURCE_DIR}/cmake/config/rotgen-install.cmake) \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..127a5bc --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/cmake/config/rotgen-install.cmake b/cmake/config/rotgen-install.cmake new file mode 100644 index 0000000..5369cf6 --- /dev/null +++ b/cmake/config/rotgen-install.cmake @@ -0,0 +1,27 @@ +##================================================================================================== +## ROTGEN - Runtime Overlay for Eigen +## Copyright : CODE RECKONS +## SPDX-License-Identifier: BSL-1.0 +##================================================================================================== +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +set(MAIN_DEST "${CMAKE_INSTALL_LIBDIR}/rotgen") +set(INSTALL_DEST "${CMAKE_INSTALL_INCLUDEDIR}") +set(DOC_DEST "${CMAKE_INSTALL_DOCDIR}") + +write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/rotgen-config-version.cmake" + VERSION "${EVE_VERSION}" + COMPATIBILITY ExactVersion + ) + +## ================================================================================================= +## Install target with versioned folder +## ================================================================================================= +install(TARGETS rotgen EXPORT rotgen-targets DESTINATION "${MAIN_DEST}") +install(TARGETS LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/rotgen DESTINATION "${INSTALL_DEST}" ) +install(FILES ${PROJECT_SOURCE_DIR}/cmake/rotgen-config.cmake DESTINATION "${MAIN_DEST}" ) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/rotgen-config-version.cmake DESTINATION "${MAIN_DEST}" ) +install(FILES ${PROJECT_SOURCE_DIR}/LICENSE.md DESTINATION "${DOC_DEST}" ) +install(EXPORT rotgen-targets NAMESPACE "rotgen::" DESTINATION "${MAIN_DEST}" ) \ No newline at end of file diff --git a/cmake/rotgen-config.cmake b/cmake/rotgen-config.cmake new file mode 100644 index 0000000..8d2e33e --- /dev/null +++ b/cmake/rotgen-config.cmake @@ -0,0 +1,11 @@ +##================================================================================================== +## ROTGEN - Runtime Overlay for Eigen +## Copyright : CODE RECKONS +## SPDX-License-Identifier: BSL-1.0 +##================================================================================================== + +##================================================================================================== +## Reuse install.cmake to prepare package properly +##================================================================================================== +include("${CMAKE_CURRENT_LIST_DIR}/rotgen-targets.cmake") +set(ROTGEN_LIBRARIES rotgen::rotgen) \ No newline at end of file diff --git a/include/rotgen/impl/matrix_impl64.hpp b/include/rotgen/impl/matrix_impl64.hpp new file mode 100644 index 0000000..b031e3b --- /dev/null +++ b/include/rotgen/impl/matrix_impl64.hpp @@ -0,0 +1,43 @@ +//================================================================================================== +/* + ROTGEN - Runtime Overlay for Eigen + Copyright : CODE RECKONS + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#pragma once + +#include +#include + +namespace rotgen +{ + class matrix_impl64 + { + public: + matrix_impl64(std::size_t rows = 0, std::size_t cols = 0); + + matrix_impl64(matrix_impl64 const& other); + matrix_impl64& operator=(matrix_impl64 const& other); + matrix_impl64(matrix_impl64&&) noexcept; + matrix_impl64& operator=(matrix_impl64&&) noexcept; + + ~matrix_impl64(); + + std::size_t rows() const; + std::size_t cols() const; + + double& operator()(std::size_t i, std::size_t j); + double const& operator()(std::size_t i, std::size_t j) const; + + matrix_impl64& operator+=(matrix_impl64 const& rhs); + matrix_impl64& operator*=(matrix_impl64 const& rhs); + matrix_impl64& operator*=(double d); + + friend std::ostream& operator<<(std::ostream&,matrix_impl64 const&); + + private: + struct payload; + std::unique_ptr storage_; + }; +} diff --git a/include/rotgen/matrix.hpp b/include/rotgen/matrix.hpp new file mode 100644 index 0000000..c5bf594 --- /dev/null +++ b/include/rotgen/matrix.hpp @@ -0,0 +1,49 @@ +//================================================================================================== +/* + ROTGEN - Runtime Overlay for Eigen + Copyright : CODE RECKONS + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#pragma once + +#include + +namespace rotgen +{ + template + class matrix : public matrix_impl64 + { + using parent = matrix_impl64; + + public: + matrix() : parent(Rows==-1?0:Rows,Cols==-1?0:Cols) {} + matrix(std::size_t r, std::size_t c) : parent(r,c) {} + + matrix& operator+=(matrix const& rhs) + { + static_cast(*this) += static_cast(rhs); + return *this; + } + + matrix& operator*=(matrix const& rhs) + { + static_cast(*this) *= static_cast(rhs); + return *this; + } + }; + + template + matrix operator+(matrix const& lhs, matrix const& rhs) + { + matrix that(lhs); + return that += rhs; + } + + template + matrix operator*(matrix const& lhs, matrix const& rhs) + { + matrix that(lhs); + return that *= rhs; + } +} \ No newline at end of file diff --git a/src/matrix_impl64.cpp b/src/matrix_impl64.cpp new file mode 100644 index 0000000..219b9f1 --- /dev/null +++ b/src/matrix_impl64.cpp @@ -0,0 +1,82 @@ +//================================================================================================== +/* + ROTGEN - Runtime Overlay for Eigen + Copyright : CODE RECKONS + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#include +#include + +namespace rotgen +{ + struct matrix_impl64::payload + { + Eigen::Matrix data; + payload(std::size_t r=0, std::size_t c=0) : data(r, c) {} + }; + + std::ostream& operator<<(std::ostream& os,matrix_impl64 const& m) + { + return os << m.storage_->data; + } + + matrix_impl64::matrix_impl64(std::size_t r, std::size_t c) + : storage_(std::make_unique(r,c)) + {} + + matrix_impl64::matrix_impl64(matrix_impl64 const& o) + : matrix_impl64(o.storage_->data.rows(),o.storage_->data.cols()) + { + storage_->data = o.storage_->data; + } + + matrix_impl64& matrix_impl64::operator=(matrix_impl64 const& o) + { + if (this != &o) storage_->data = o.storage_->data; + return *this; + } + + matrix_impl64::matrix_impl64(matrix_impl64&&) noexcept = default; + matrix_impl64& matrix_impl64::operator=(matrix_impl64&&) noexcept = default; + + matrix_impl64::~matrix_impl64() = default; + + std::size_t matrix_impl64::rows() const + { + return static_cast(storage_->data.rows()); + } + + std::size_t matrix_impl64::cols() const + { + return static_cast(storage_->data.cols()); + } + + double& matrix_impl64::operator()(std::size_t i, std::size_t j) + { + return storage_->data(i,j); + } + + double const& matrix_impl64::operator()(std::size_t i, std::size_t j) const + { + return storage_->data(i,j); + } + + matrix_impl64& matrix_impl64::operator+=(matrix_impl64 const& rhs) + { + storage_->data += rhs.storage_->data; + return *this; + } + + matrix_impl64& matrix_impl64::operator*=(matrix_impl64 const& rhs) + { + storage_->data *= rhs.storage_->data; + return *this; + } + + matrix_impl64& matrix_impl64::operator*=(double s) + { + storage_->data *= s; + return *this; + } +} \ No newline at end of file