Skip to content

Commit

Permalink
Python port done
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardovera committed May 1, 2020
1 parent 0186e6d commit 5b503bc
Show file tree
Hide file tree
Showing 30 changed files with 101 additions and 47 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ list(
)

list(
APPEND _py_metrics euclidean homogeneous conformal minkowski
APPEND _py_metrics euclidean conformal homogeneous minkowski
)

foreach(_metric IN ITEMS ${_py_metrics})
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

0 comments on commit 5b503bc

Please sign in to comment.