Infrastructure de base
This commit is contained in:
parent
d901e17fa8
commit
491addb201
7 changed files with 296 additions and 0 deletions
61
CMakeLists.txt
Normal file
61
CMakeLists.txt
Normal file
|
|
@ -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
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
|
||||
target_link_libraries (rotgen PRIVATE Eigen3::Eigen)
|
||||
|
||||
##======================================================================================================================
|
||||
## Setup the library's installation target
|
||||
##======================================================================================================================
|
||||
include(${ROTGEN_SOURCE_DIR}/cmake/config/rotgen-install.cmake)
|
||||
23
LICENSE.md
Normal file
23
LICENSE.md
Normal file
|
|
@ -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.
|
||||
27
cmake/config/rotgen-install.cmake
Normal file
27
cmake/config/rotgen-install.cmake
Normal file
|
|
@ -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}" )
|
||||
11
cmake/rotgen-config.cmake
Normal file
11
cmake/rotgen-config.cmake
Normal file
|
|
@ -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)
|
||||
43
include/rotgen/impl/matrix_impl64.hpp
Normal file
43
include/rotgen/impl/matrix_impl64.hpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <cstddef>
|
||||
|
||||
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<payload> storage_;
|
||||
};
|
||||
}
|
||||
49
include/rotgen/matrix.hpp
Normal file
49
include/rotgen/matrix.hpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#pragma once
|
||||
|
||||
#include <rotgen/impl/matrix_impl64.hpp>
|
||||
|
||||
namespace rotgen
|
||||
{
|
||||
template<typename Scalar, int Rows = -1, int Cols = -1>
|
||||
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<parent&>(*this) += static_cast<parent const&>(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& operator*=(matrix const& rhs)
|
||||
{
|
||||
static_cast<parent&>(*this) *= static_cast<parent const&>(rhs);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename S, int R, int C>
|
||||
matrix<S,R,C> operator+(matrix<S,R,C> const& lhs, matrix<S,R,C> const& rhs)
|
||||
{
|
||||
matrix<S,R,C> that(lhs);
|
||||
return that += rhs;
|
||||
}
|
||||
|
||||
template<typename S, int R, int C>
|
||||
matrix<S,R,C> operator*(matrix<S,R,C> const& lhs, matrix<S,R,C> const& rhs)
|
||||
{
|
||||
matrix<S,R,C> that(lhs);
|
||||
return that *= rhs;
|
||||
}
|
||||
}
|
||||
82
src/matrix_impl64.cpp
Normal file
82
src/matrix_impl64.cpp
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <Eigen/Dense>
|
||||
|
||||
namespace rotgen
|
||||
{
|
||||
struct matrix_impl64::payload
|
||||
{
|
||||
Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> 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<payload>(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<std::size_t>(storage_->data.rows());
|
||||
}
|
||||
|
||||
std::size_t matrix_impl64::cols() const
|
||||
{
|
||||
return static_cast<std::size_t>(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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue