Skip to content

Commit

Permalink
Move Vc math overloads to algebra-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Nov 25, 2024
1 parent 328dd04 commit 8580784
Show file tree
Hide file tree
Showing 33 changed files with 524 additions and 312 deletions.
16 changes: 10 additions & 6 deletions common/include/algebra/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ concept value = algebra::concepts::arithmetic<std::decay_t<T>>;
template <typename T>
concept scalar = !algebra::traits::is_matrix<T> &&
!algebra::traits::is_vector<T> && requires(T a, T b) {
{ a + b } -> std::convertible_to<T>;
{ a - b } -> std::convertible_to<T>;
{ a* b } -> std::convertible_to<T>;
{ a / b } -> std::convertible_to<T>;
};
{ a + b }
->std::convertible_to<T>;
{ a - b }
->std::convertible_to<T>;
{ a* b }
->std::convertible_to<T>;
{ a / b }
->std::convertible_to<T>;
};

/// Check if a scalar is simd
template <typename T>
Expand Down Expand Up @@ -71,7 +75,7 @@ template <typename M>
concept matrix = algebra::traits::is_matrix<M>;

template <typename M>
concept square_matrix = matrix<M> && algebra::traits::is_square<M>;
concept square_matrix = matrix<M>&& algebra::traits::is_square<M>;

template <typename M>
concept row_matrix = matrix<M> && (algebra::traits::rows<M> == 1);
Expand Down
5 changes: 3 additions & 2 deletions common/include/algebra/print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ namespace algebra {

/// Print a generic vector or point @param v
template <typename vector_t>
requires(concepts::vector<vector_t> || concepts::point<vector_t>)
ALGEBRA_HOST std::ostream& operator<<(std::ostream& out, const vector_t& v) {
requires(concepts::vector<vector_t> ||
concepts::point<vector_t>) ALGEBRA_HOST std::ostream&
operator<<(std::ostream& out, const vector_t& v) {

using index_t = algebra::traits::index_t<vector_t>;

Expand Down
21 changes: 13 additions & 8 deletions common/include/algebra/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ struct dimensions {

/// Specilization for scalar types
template <typename M>
requires std::is_fundamental_v<M>
struct dimensions<M> {
requires std::is_fundamental_v<M> struct dimensions<M> {

using size_type = std::size_t;

Expand Down Expand Up @@ -138,11 +137,11 @@ template <typename T>
struct get_algebra {};

template <typename T>
requires(!std::is_same_v<typename T::point3D, void>)
struct get_algebra<T> {
requires(!std::is_same_v<typename T::point3D, void>) struct get_algebra<T> {
template <typename U>
using simd = typename T::template simd<U>;
using size_type = typename T::size_type;
using boolean = typename T::boolean;
using value = typename T::value_type;
using scalar = typename T::scalar;
using point2D = typename T::point2D;
Expand All @@ -156,11 +155,20 @@ struct get_algebra<T> {
} // namespace traits

template <typename A>
using get_scalar_t = typename traits::get_algebra<A>::scalar;
using get_value_t = typename traits::get_algebra<A>::value;

template <typename A>
using get_boolean_t = typename traits::get_algebra<A>::boolean;

template <typename A, typename T>
using get_simd_t = typename traits::get_algebra<A>::template simd<T>;

template <typename A>
using get_size_t = typename traits::get_algebra<A>::size_type;

template <typename A>
using get_scalar_t = typename traits::get_algebra<A>::scalar;

template <typename A>
using get_point2D_t = typename traits::get_algebra<A>::point2D;

Expand All @@ -173,9 +181,6 @@ using get_vector3D_t = typename traits::get_algebra<A>::vector3D;
template <typename A>
using get_transform3D_t = typename traits::get_algebra<A>::transform3D;

template <typename A>
using get_size_t = typename traits::get_algebra<A>::size_type;

template <typename A, std::size_t R, std::size_t C>
using get_matrix_t = typename traits::get_algebra<A>::template matrix<R, C>;
/// @}
Expand Down
34 changes: 17 additions & 17 deletions frontend/array_cmath/include/algebra/array_cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,25 @@ namespace plugin {
/// @{
template <typename V>
struct cmath {
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::array::size_type;
using transform3D = algebra::array::transform3<value_type>;
using point2D = algebra::array::point2<value_type>;
using point3D = algebra::array::point3<value_type>;
using vector3D = algebra::array::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::array::matrix_type<value_type, ROWS, COLS>;
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::array::size_type;
using transform3D = algebra::array::transform3<value_type>;
using point2D = algebra::array::point2<value_type>;
using point3D = algebra::array::point3<value_type>;
using vector3D = algebra::array::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::array::matrix_type<value_type, ROWS, COLS>;
};
/// @}

} // namespace plugin
} // namespace plugin

} // namespace algebra
34 changes: 17 additions & 17 deletions frontend/eigen_eigen/include/algebra/eigen_eigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,25 @@ namespace plugin {
/// @{
template <typename V>
struct eigen {
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::eigen::size_type;
using transform3D = algebra::eigen::transform3<value_type>;
using point2D = algebra::eigen::point2<value_type>;
using point3D = algebra::eigen::point3<value_type>;
using vector3D = algebra::eigen::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::eigen::matrix_type<value_type, ROWS, COLS>;
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::eigen::size_type;
using transform3D = algebra::eigen::transform3<value_type>;
using point2D = algebra::eigen::point2<value_type>;
using point3D = algebra::eigen::point3<value_type>;
using vector3D = algebra::eigen::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::eigen::matrix_type<value_type, ROWS, COLS>;
};
/// @}

} // namespace plugin
} // namespace plugin

} // namespace algebra
40 changes: 20 additions & 20 deletions frontend/eigen_generic/include/algebra/eigen_generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#pragma warning(pop)
#endif // MSVC

/// Print the linear algebra types of this backend
using algebra::operator<<;

// System include(s).
#include <type_traits>

/// Print the linear algebra types of this backend
using algebra::operator<<;

namespace algebra {

namespace getter {
Expand Down Expand Up @@ -99,25 +99,25 @@ namespace plugin {
/// @{
template <typename V>
struct eigen_generic {
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::eigen::size_type;
using transform3D = algebra::eigen::transform3<value_type>;
using point2D = algebra::eigen::point2<value_type>;
using point3D = algebra::eigen::point3<value_type>;
using vector3D = algebra::eigen::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::eigen::matrix_type<value_type, ROWS, COLS>;
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::eigen::size_type;
using transform3D = algebra::eigen::transform3<value_type>;
using point2D = algebra::eigen::point2<value_type>;
using point3D = algebra::eigen::point3<value_type>;
using vector3D = algebra::eigen::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::eigen::matrix_type<value_type, ROWS, COLS>;
};
/// @}

} // namespace plugin
} // namespace plugin

} // namespace algebra
34 changes: 17 additions & 17 deletions frontend/fastor_fastor/include/algebra/fastor_fastor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,25 @@ namespace plugin {
/// @{
template <typename V>
struct fastor {
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::fastor::size_type;
using transform3D = algebra::fastor::transform3<value_type>;
using point2D = algebra::fastor::point2<value_type>;
using point3D = algebra::fastor::point3<value_type>;
using vector3D = algebra::fastor::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::fastor::matrix_type<value_type, ROWS, COLS>;
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::fastor::size_type;
using transform3D = algebra::fastor::transform3<value_type>;
using point2D = algebra::fastor::point2<value_type>;
using point3D = algebra::fastor::point3<value_type>;
using vector3D = algebra::fastor::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::fastor::matrix_type<value_type, ROWS, COLS>;
};
/// @}

} // namespace plugin
} // namespace plugin

} // namespace algebra
34 changes: 17 additions & 17 deletions frontend/smatrix_generic/include/algebra/smatrix_generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,25 @@ namespace plugin {
/// @{
template <typename V>
struct smatrix_generic {
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::smatrix::size_type;
using transform3D = algebra::smatrix::transform3<value_type>;
using point2D = algebra::smatrix::point2<value_type>;
using point3D = algebra::smatrix::point3<value_type>;
using vector3D = algebra::smatrix::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::smatrix::matrix_type<value_type, ROWS, COLS>;
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::smatrix::size_type;
using transform3D = algebra::smatrix::transform3<value_type>;
using point2D = algebra::smatrix::point2<value_type>;
using point3D = algebra::smatrix::point3<value_type>;
using vector3D = algebra::smatrix::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::smatrix::matrix_type<value_type, ROWS, COLS>;
};
/// @}

} // namespace plugin
} // namespace plugin

} // namespace algebra
34 changes: 17 additions & 17 deletions frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,25 @@ namespace plugin {
/// @{
template <typename V>
struct smatrix {
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::smatrix::size_type;
using transform3D = algebra::smatrix::transform3<value_type>;
using point2D = algebra::smatrix::point2<value_type>;
using point3D = algebra::smatrix::point3<value_type>;
using vector3D = algebra::smatrix::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::smatrix::matrix_type<value_type, ROWS, COLS>;
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

using boolean = bool;
using scalar = value_type;
using size_type = algebra::smatrix::size_type;
using transform3D = algebra::smatrix::transform3<value_type>;
using point2D = algebra::smatrix::point2<value_type>;
using point3D = algebra::smatrix::point3<value_type>;
using vector3D = algebra::smatrix::vector3<value_type>;

template <std::size_t ROWS, std::size_t COLS>
using matrix = algebra::smatrix::matrix_type<value_type, ROWS, COLS>;
};
/// @}

} // namespace plugin
} // namespace plugin

} // namespace algebra
Loading

0 comments on commit 8580784

Please sign in to comment.