Skip to content

Commit

Permalink
Move the plugins from detray to algebra-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Nov 25, 2024
1 parent 28f9cc5 commit 1bdb854
Show file tree
Hide file tree
Showing 15 changed files with 367 additions and 24 deletions.
43 changes: 32 additions & 11 deletions common/include/algebra/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@

namespace algebra::concepts {

/// Arithmetic types
template <typename T>
concept arithmetic = std::is_arithmetic_v<T>;

// Value concept: Single entry
template <typename T>
concept value = std::is_arithmetic_v<std::decay_t<T>>;
concept value = algebra::concepts::arithmetic<std::decay_t<T>>;

/// Scalar concept: Elements of vectors/matrices (can be simd vectors)
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 +71,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 Expand Up @@ -104,4 +104,25 @@ concept transform3D = requires(T trf) {
trf.vector_to_local(typename T::vector3());
};

/// Algebra plugin concept
template <typename A>
concept algebra = (concepts::value<typename A::value_type> &&
concepts::scalar<typename A::scalar> &&
concepts::index<typename A::size_type> &&
concepts::simd_scalar<typename A::template simd<float>> &&
concepts::vector3D<typename A::vector3D> &&
concepts::point2D<typename A::point2D> &&
concepts::point3D<typename A::point3D> &&
concepts::transform3D<typename A::transform3D> &&
concepts::matrix<typename A::template matrix<3, 3>>);

/// Check if an algebra has soa layout
/// @{
template <typename A>
concept soa = (!concepts::arithmetic<algebra::get_scalar_t<A>>);

template <typename A>
concept aos = (!concepts::soa<A>);
/// @}

} // namespace algebra::concepts
57 changes: 54 additions & 3 deletions common/include/algebra/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include <cmath>
#include <type_traits>

namespace algebra::traits {
namespace algebra {

namespace traits {

/// Matrix traits
/// @{
Expand Down Expand Up @@ -79,7 +81,8 @@ 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 @@ -129,7 +132,55 @@ template <class M>
using block_getter_t = typename block_getter<M>::type;
/// @}

} // namespace algebra::traits
/// The algebra types
/// @{
template <typename T>
struct get_algebra {};

template <typename 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 value = typename T::value_type;
using scalar = typename T::scalar;
using point2D = typename T::point2D;
using point3D = typename T::point3D;
using vector3D = typename T::vector3D;
using transform3D = typename T::transform3D;
template <std::size_t ROWS, std::size_t COLS>
using matrix = typename T::template matrix<ROWS, COLS>;
};

} // namespace traits

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

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

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

template <typename A>
using get_point3D_t = typename traits::get_algebra<A>::point3D;

template <typename A>
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>;
/// @}

} // namespace algebra

/// Default type trait specializations
/// @{
Expand Down
27 changes: 27 additions & 0 deletions frontend/array_cmath/include/algebra/array_cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,31 @@ using transform3 =

} // namespace array

namespace plugin {

/// Define the plugin types
/// @{
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>;
};
/// @}

} // namespace plugin

} // namespace algebra
27 changes: 27 additions & 0 deletions frontend/eigen_eigen/include/algebra/eigen_eigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,31 @@ using transform3 = math::transform3<T>;

} // namespace eigen

namespace plugin {

/// Define the plugin types
/// @{
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>;
};
/// @}

} // namespace plugin

} // namespace algebra
27 changes: 27 additions & 0 deletions frontend/eigen_generic/include/algebra/eigen_generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,31 @@ using transform3 =

} // namespace eigen

namespace plugin {

/// Define the plugin types
/// @{
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>;
};
/// @}

} // namespace plugin

} // namespace algebra
27 changes: 27 additions & 0 deletions frontend/fastor_fastor/include/algebra/fastor_fastor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,31 @@ using transform3 = math::transform3<T>;

} // namespace fastor

namespace plugin {

/// Define the plugin types
/// @{
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>;
};
/// @}

} // namespace plugin

} // namespace algebra
27 changes: 27 additions & 0 deletions frontend/smatrix_generic/include/algebra/smatrix_generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,31 @@ using transform3 =

} // namespace smatrix

namespace plugin {

/// Define the plugin types
/// @{
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>;
};
/// @}

} // namespace plugin

} // namespace algebra
27 changes: 27 additions & 0 deletions frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,31 @@ using transform3 = math::transform3<T>;

} // namespace smatrix

namespace plugin {

/// Define the plugin types
/// @{
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>;
};
/// @}

} // namespace plugin

} // namespace algebra
27 changes: 27 additions & 0 deletions frontend/vc_aos/include/algebra/vc_aos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,31 @@ using transform3 = math::transform3<vc_aos::storage_type, T>;

} // namespace vc_aos

namespace plugin {

/// Define the plugin types
/// @{
template <typename V>
struct vc_aos {
/// Define scalar type
using value_type = V;

template <typename T>
using simd = T;

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

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

} // namespace plugin

} // namespace algebra
Loading

0 comments on commit 1bdb854

Please sign in to comment.