Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python port #2

Merged
merged 6 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,89 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Eigen3 3.3 NO_MODULE REQUIRED)

# for testing we will need the python interpreter
find_package(PythonInterp REQUIRED)

# we require python development headers
find_package(PythonLibs ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} EXACT REQUIRED)

#file(MAKE_DIRECTORY reports)
#file(MAKE_DIRECTORY tbgal)
#file(WRITE tbgal/__init.py__)

# now search for the boost component
# depending on the boost version it is called either python,
# python2, python27, python3, python36, python37, ...

list(
APPEND _components
python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}
python${PYTHON_VERSION_MAJOR}
python
)

set(_boost_component_found "")

foreach(_component IN ITEMS ${_components})
find_package(Boost COMPONENTS ${_component})
if(Boost_FOUND)
set(_boost_component_found ${_component})
break()
endif()
endforeach()

if(_boost_component_found STREQUAL "")
message(FATAL_ERROR "No matching Boost.Python component found")
endif()

list(
APPEND _py_dims 1 2 3 D
)

list(
APPEND _py_metrics euclidean conformal homogeneous minkowski
)

foreach(_metric IN ITEMS ${_py_metrics})
foreach(_dim IN ITEMS ${_py_dims})
message(Building\ ${_metric}${_dim})
python_add_module(${_metric}${_dim} ./python/src/${_metric}/${_metric}${_dim}.cpp)
target_link_libraries(${_metric}${_dim} PUBLIC Boost::${_boost_component_found} ${PYTHON_LIBRARIES})
target_include_directories(${_metric}${_dim} PRIVATE ${PYTHON_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR})
set_target_properties(${_metric}${_dim}
PROPERTIES
PREFIX ""
ARCHIVE_OUTPUT_DIRECTORY "tbgal/${_metric}"
LIBRARY_OUTPUT_DIRECTORY "tbgal/${_metric}"
RUNTIME_OUTPUT_DIRECTORY "tbgal/${_metric}"
)
add_custom_command(TARGET ${_metric}${_dim} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory tbgal)
add_custom_command(TARGET ${_metric}${_dim} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E touch tbgal/__init__.py)
endforeach()
endforeach()


message(Building\ SignedPQ)
python_add_module(PQ ./python/src/signed/PQ.cpp)
target_link_libraries(PQ PUBLIC Boost::${_boost_component_found} ${PYTHON_LIBRARIES})
target_include_directories(PQ PRIVATE ${PYTHON_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR})
set_target_properties(PQ
PROPERTIES
PREFIX ""
ARCHIVE_OUTPUT_DIRECTORY "tbgal/signed"
LIBRARY_OUTPUT_DIRECTORY "tbgal/signed"
RUNTIME_OUTPUT_DIRECTORY "tbgal/signed"
)
add_custom_command(TARGET PQ PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory tbgal)
add_custom_command(TARGET PQ PRE_BUILD COMMAND ${CMAKE_COMMAND} -E touch tbgal/__init__.py)


message(STATUS "Eigen3_DIR = ${EIGEN3_INCLUDE_DIR}")
message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}")
message(STATUS "PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}")

file(INSTALL "./cpp/include" DESTINATION "${CMAKE_INSTALL_PREFIX}" FILES_MATCHING PATTERN "*.hpp")

configure_file("./cmake/TbGALConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/TbGALConfig.cmake" @ONLY NEWLINE_STYLE UNIX)
Expand Down
8 changes: 4 additions & 4 deletions cpp/include/tbgal/Conformal/macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
#define _TBGAL_OVERLOAD_CONFORMAL_UTILS(METRIC_SPACE) \
\
template<typename... ScalarTypes, typename = std::enable_if_t<std::disjunction_v<std::bool_constant<!detail::is_iterator_v<ScalarTypes> >...> > > \
constexpr decltype(auto) euclidean_vector(ScalarTypes &&... coords) noexcept { \
constexpr decltype(auto) euclidean_vector(ScalarTypes &&... coords) { \
return tbgal::detail::make_vector(&METRIC_SPACE, std::move(coords)..., 0, 0); \
} \
\
template<typename IteratorType, typename = std::enable_if_t<detail::is_iterator_v<IteratorType> > > \
constexpr decltype(auto) euclidean_vector(IteratorType begin, IteratorType end) noexcept { \
constexpr decltype(auto) euclidean_vector(IteratorType begin, IteratorType end) { \
return tbgal::detail::make_vector_using_iterator(&METRIC_SPACE, begin, end, 0, 0); \
} \
\
template<typename... ScalarTypes, typename = std::enable_if_t<std::disjunction_v<std::bool_constant<!detail::is_iterator_v<ScalarTypes> >...> > > \
constexpr decltype(auto) point(ScalarTypes &&... coords) noexcept { \
constexpr decltype(auto) point(ScalarTypes &&... coords) { \
return tbgal::detail::make_vector(&METRIC_SPACE, std::move(coords)..., 1, ((std::move(coords) * std::move(coords)) + ... + 0) / 2); \
} \
\
template<typename IteratorType, typename = std::enable_if_t<detail::is_iterator_v<IteratorType> > > \
constexpr decltype(auto) point(IteratorType begin, IteratorType end) noexcept { \
constexpr decltype(auto) point(IteratorType begin, IteratorType end) { \
std::remove_cv_t<std::remove_reference_t<typename std::iterator_traits<IteratorType>::value_type> > aux = 0; \
for (IteratorType itr = begin; itr != end; ++itr) { \
aux += (*itr) * (*itr); \
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/tbgal/Euclidean/macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
#define _TBGAL_OVERLOAD_EUCLIDEAN_UTILS(METRIC_SPACE) \
\
template<typename... ScalarTypes, typename = std::enable_if_t<std::disjunction_v<std::bool_constant<!detail::is_iterator_v<ScalarTypes> >...> > > \
constexpr decltype(auto) euclidean_vector(ScalarTypes &&... coords) noexcept { \
constexpr decltype(auto) euclidean_vector(ScalarTypes &&... coords) { \
return tbgal::detail::make_vector(&METRIC_SPACE, std::move(coords)...); \
} \
\
template<typename IteratorType, typename = std::enable_if_t<detail::is_iterator_v<IteratorType> > > \
constexpr decltype(auto) euclidean_vector(IteratorType begin, IteratorType end) noexcept { \
constexpr decltype(auto) euclidean_vector(IteratorType begin, IteratorType end) { \
return tbgal::detail::make_vector_using_iterator(&METRIC_SPACE, begin, end); \
}

Expand Down
12 changes: 6 additions & 6 deletions cpp/include/tbgal/Homogeneous/macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@
#define _TBGAL_OVERLOAD_HOMOGENEOUS_UTILS(METRIC_SPACE) \
\
template<typename... ScalarTypes, typename = std::enable_if_t<std::disjunction_v<std::bool_constant<!detail::is_iterator_v<ScalarTypes> >...> > > \
constexpr decltype(auto) direction(ScalarTypes &&... coords) noexcept { \
constexpr decltype(auto) direction(ScalarTypes &&... coords) { \
return tbgal::detail::make_vector(&METRIC_SPACE, std::move(coords)..., 0); \
} \
\
template<typename IteratorType, typename = std::enable_if_t<detail::is_iterator_v<IteratorType> > > \
constexpr decltype(auto) direction(IteratorType begin, IteratorType end) noexcept { \
constexpr decltype(auto) direction(IteratorType begin, IteratorType end) { \
return tbgal::detail::make_vector_using_iterator(&METRIC_SPACE, begin, end, 0); \
} \
\
template<typename... ScalarTypes, typename = std::enable_if_t<std::disjunction_v<std::bool_constant<!detail::is_iterator_v<ScalarTypes> >...> > > \
constexpr decltype(auto) euclidean_vector(ScalarTypes &&... coords) noexcept { \
constexpr decltype(auto) euclidean_vector(ScalarTypes &&... coords) { \
return tbgal::detail::make_vector(&METRIC_SPACE, std::move(coords)..., 0); \
} \
\
template<typename IteratorType, typename = std::enable_if_t<detail::is_iterator_v<IteratorType> > > \
constexpr decltype(auto) euclidean_vector(IteratorType begin, IteratorType end) noexcept { \
constexpr decltype(auto) euclidean_vector(IteratorType begin, IteratorType end) { \
return tbgal::detail::make_vector_using_iterator(&METRIC_SPACE, begin, end, 0); \
} \
\
template<typename... ScalarTypes, typename = std::enable_if_t<std::disjunction_v<std::bool_constant<!detail::is_iterator_v<ScalarTypes> >...> > > \
constexpr decltype(auto) point(ScalarTypes &&... coords) noexcept { \
constexpr decltype(auto) point(ScalarTypes &&... coords) { \
return tbgal::detail::make_vector(&METRIC_SPACE, std::move(coords)..., 1); \
} \
\
template<typename IteratorType, typename = std::enable_if_t<detail::is_iterator_v<IteratorType> > > \
constexpr decltype(auto) point(IteratorType begin, IteratorType end) noexcept { \
constexpr decltype(auto) point(IteratorType begin, IteratorType end) { \
return tbgal::detail::make_vector_using_iterator(&METRIC_SPACE, begin, end, 1); \
}

Expand Down
8 changes: 4 additions & 4 deletions cpp/include/tbgal/Minkowski/macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@
#define _TBGAL_OVERLOAD_MINKOWSKI_UTILS(METRIC_SPACE) \
\
template<typename... ScalarTypes, typename = std::enable_if_t<std::disjunction_v<std::bool_constant<!detail::is_iterator_v<ScalarTypes> >...> > > \
constexpr decltype(auto) euclidean_vector(ScalarTypes &&... coords) noexcept { \
constexpr decltype(auto) euclidean_vector(ScalarTypes &&... coords) { \
return tbgal::detail::make_vector(&METRIC_SPACE, std::move(coords)..., 0, 0); \
} \
\
template<typename IteratorType, typename = std::enable_if_t<detail::is_iterator_v<IteratorType> > > \
constexpr decltype(auto) euclidean_vector(IteratorType begin, IteratorType end) noexcept { \
constexpr decltype(auto) euclidean_vector(IteratorType begin, IteratorType end) { \
return tbgal::detail::make_vector_using_iterator(&METRIC_SPACE, begin, end, 0, 0); \
} \
\
template<typename... ScalarTypes, typename = std::enable_if_t<std::disjunction_v<std::bool_constant<!detail::is_iterator_v<ScalarTypes> >...> > > \
constexpr decltype(auto) point(ScalarTypes &&... coords) noexcept { \
constexpr decltype(auto) point(ScalarTypes &&... coords) { \
auto aux = ((std::move(coords) * std::move(coords)) + ... + 0); \
return tbgal::detail::make_vector(&METRIC_SPACE, std::move(coords)..., (aux - 1) / 2, (aux + 1) / 2); \
} \
\
template<typename IteratorType, typename = std::enable_if_t<detail::is_iterator_v<IteratorType> > > \
constexpr decltype(auto) point(IteratorType begin, IteratorType end) noexcept { \
constexpr decltype(auto) point(IteratorType begin, IteratorType end) { \
std::remove_cv_t<std::remove_reference_t<typename std::iterator_traits<IteratorType>::value_type> > aux = 0; \
for (IteratorType itr = begin; itr != end; ++itr) { \
aux += (*itr) * (*itr); \
Expand Down
16 changes: 8 additions & 8 deletions cpp/include/tbgal/addition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace tbgal {
//TODO [FUTURE] Implement associativity.

template<typename FirstScalarType, typename FirstFactoringProductType, typename SecondScalarType, typename SecondFactoringProductType>
constexpr decltype(auto) addition(FactoredMultivector<FirstScalarType, FirstFactoringProductType> const &arg1, FactoredMultivector<SecondScalarType, SecondFactoringProductType> const &arg2) noexcept {
constexpr decltype(auto) addition(FactoredMultivector<FirstScalarType, FirstFactoringProductType> const &arg1, FactoredMultivector<SecondScalarType, SecondFactoringProductType> const &arg2) {
using ResultingScalarType = std::common_type_t<FirstScalarType, SecondScalarType>;
using ResultingFactoringProductType = OuterProduct<typename FirstFactoringProductType::MetricSpaceType>;
using ResultingFactoredMultivectorType = FactoredMultivector<ResultingScalarType, ResultingFactoringProductType>;
Expand All @@ -46,43 +46,43 @@ namespace tbgal {
}

template<typename FirstScalarType, typename FirstFactoringProductType, typename SecondScalarType, typename = std::enable_if_t<!is_multivector_v<SecondScalarType> > >
constexpr decltype(auto) addition(FactoredMultivector<FirstScalarType, FirstFactoringProductType> const &arg1, SecondScalarType const &arg2) noexcept {
constexpr decltype(auto) addition(FactoredMultivector<FirstScalarType, FirstFactoringProductType> const &arg1, SecondScalarType const &arg2) {
if (arg1.factors_count() == 0) {
return scalar(arg1.space_ptr(), arg1.scalar() + arg2);
}
throw NotSupportedError("The general case of summation of factored multivectors is not supported.");
}

template<typename FirstScalarType, typename SecondScalarType, typename SecondFactoringProductType, typename = std::enable_if_t<!is_multivector_v<FirstScalarType> > >
constexpr decltype(auto) addition(FirstScalarType const &arg1, FactoredMultivector<SecondScalarType, SecondFactoringProductType> const &arg2) noexcept {
constexpr decltype(auto) addition(FirstScalarType const &arg1, FactoredMultivector<SecondScalarType, SecondFactoringProductType> const &arg2) {
if (arg2.factors_count() == 0) {
return scalar(arg2.space_ptr(), arg1 + arg2.scalar());
}
throw NotSupportedError("The general case of summation of factored multivectors is not supported.");
}

template<typename FirstScalarType, typename SecondScalarType, typename = std::enable_if_t<!(is_multivector_v<FirstScalarType> || is_multivector_v<SecondScalarType>)> >
constexpr decltype(auto) addition(FirstScalarType const &arg1, SecondScalarType const &arg2) noexcept {
constexpr decltype(auto) addition(FirstScalarType const &arg1, SecondScalarType const &arg2) {
return arg1 + arg2;
}

template<typename FirstType, typename SecondType>
constexpr decltype(auto) add(FirstType const &arg1, SecondType const &arg2) noexcept {
constexpr decltype(auto) add(FirstType const &arg1, SecondType const &arg2) {
return addition(arg1, arg2);
}

template<typename FirstScalarType, typename FirstFactoringProductType, typename SecondScalarType, typename SecondFactoringProductType>
constexpr decltype(auto) operator+(FactoredMultivector<FirstScalarType, FirstFactoringProductType> const &arg1, FactoredMultivector<SecondScalarType, SecondFactoringProductType> const &arg2) noexcept {
constexpr decltype(auto) operator+(FactoredMultivector<FirstScalarType, FirstFactoringProductType> const &arg1, FactoredMultivector<SecondScalarType, SecondFactoringProductType> const &arg2) {
return addition(arg1, arg2);
}

template<typename FirstScalarType, typename FirstFactoringProductType, typename SecondScalarType, typename = std::enable_if_t<!is_multivector_v<SecondScalarType> > >
constexpr decltype(auto) operator+(FactoredMultivector<FirstScalarType, FirstFactoringProductType> const &arg1, SecondScalarType const &arg2) noexcept {
constexpr decltype(auto) operator+(FactoredMultivector<FirstScalarType, FirstFactoringProductType> const &arg1, SecondScalarType const &arg2) {
return addition(arg1, arg2);
}

template<typename FirstScalarType, typename SecondScalarType, typename SecondFactoringProductType, typename = std::enable_if_t<!is_multivector_v<FirstScalarType> > >
constexpr decltype(auto) operator+(FirstScalarType const &arg1, FactoredMultivector<SecondScalarType, SecondFactoringProductType> const &arg2) noexcept {
constexpr decltype(auto) operator+(FirstScalarType const &arg1, FactoredMultivector<SecondScalarType, SecondFactoringProductType> const &arg2) {
return addition(arg1, arg2);
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/include/tbgal/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ namespace tbgal {
}

template<typename MetricSpaceType, typename... ScalarTypes>
constexpr decltype(auto) make_vector(MetricSpaceType const *, ScalarTypes &&...) noexcept;
constexpr decltype(auto) make_vector(MetricSpaceType const *, ScalarTypes &&...);

template<typename MetricSpaceType, typename IteratorType, typename... ExtraScalarTypes>
constexpr decltype(auto) make_vector_using_iterator(MetricSpaceType const *, IteratorType, IteratorType, ExtraScalarTypes &&...) noexcept;
constexpr decltype(auto) make_vector_using_iterator(MetricSpaceType const *, IteratorType, IteratorType, ExtraScalarTypes &&...);

}

Expand Down
9 changes: 9 additions & 0 deletions cpp/include/tbgal/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@
namespace tbgal {

class NotSupportedError : public std::logic_error {

// private:
// const char *what_msg;

public:

explicit NotSupportedError(const std::string &what_arg) :
std::logic_error(what_arg) {
// this->what_msg = what_arg.c_str();
}

explicit NotSupportedError(const char *what_arg) :
std::logic_error(what_arg) {
// this->what_msg = what_arg;
}

// char const* what() const throw() { return this->what_msg; }

};

}
Expand Down
Loading