Skip to content

Commit

Permalink
Split the test suit to allow for incremental development of plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Apr 12, 2024
1 parent 8befb32 commit 562414f
Show file tree
Hide file tree
Showing 15 changed files with 416 additions and 392 deletions.
113 changes: 8 additions & 105 deletions frontend/vc_vc/include/algebra/vc_vc.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Algebra plugins library, part of the ACTS project
*
* (c) 2020-2022 CERN for the benefit of the ACTS project
* (c) 2020-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand All @@ -16,25 +16,12 @@
#include <cassert>
#include <type_traits>

/// @name Operators on @c algebra::vc types
/// @{

using algebra::cmath::operator*;
using algebra::cmath::operator-;
using algebra::cmath::operator+;

/// @}

namespace algebra {
namespace vc {

/// @name Vc based transforms on @c algebra::vc::storage_type
/// @{

// Pull in the definitions needed by the cmath transforms, into this namespace.
using math::perp;
using math::phi;

template <typename T>
using transform3 = math::transform3<storage_type, T, vector3<T>, point2<T>>;

Expand All @@ -47,12 +34,6 @@ namespace getter {
/// @name Getter functions on @c algebra::vc types
/// @{

using cmath::eta;
using cmath::norm;
using cmath::perp;
using cmath::phi;
using cmath::theta;

using vc::math::eta;
using vc::math::norm;
using vc::math::perp;
Expand All @@ -64,13 +45,14 @@ using vc::math::theta;
/// Function extracting a slice from the matrix used by
/// @c algebra::vc::transform3<float>
template <std::size_t SIZE, std::enable_if_t<SIZE <= 4, bool> = true>
ALGEBRA_HOST_DEVICE inline auto vector(const vc::transform3<float>::matrix44& m,
std::size_t
ALGEBRA_HOST_DEVICE inline vc::vector3<float> vector(
const vc::transform3<float>::matrix44& m,
std::size_t
#ifndef NDEBUG
row
row
#endif // not NDEBUG
,
std::size_t col) {
,
std::size_t col) {

assert(row == 0);
assert(col < 4);
Expand All @@ -91,7 +73,7 @@ ALGEBRA_HOST_DEVICE inline auto vector(const vc::transform3<float>::matrix44& m,
/// Function extracting a slice from the matrix used by
/// @c algebra::vc::transform3<double>
template <std::size_t SIZE, std::enable_if_t<SIZE <= 4, bool> = true>
ALGEBRA_HOST_DEVICE inline auto vector(
ALGEBRA_HOST_DEVICE inline vc::vector3<double> vector(
const vc::transform3<double>::matrix44& m,
std::size_t
#ifndef NDEBUG
Expand Down Expand Up @@ -130,8 +112,6 @@ namespace vector {
/// @name Vector functions on @c algebra::vc types
/// @{

using cmath::dot;
using cmath::normalize;
using vc::math::cross;
using vc::math::dot;
using vc::math::normalize;
Expand All @@ -150,82 +130,5 @@ using array_type = vc::storage_type<T, N>;
template <typename T, size_type ROWS, size_type COLS>
using matrix_type = vc::matrix_type<T, ROWS, COLS>;

/*template <typename scalar_t>
using element_getter = cmath::element_getter<size_type, Vc::array, scalar_t>;
template <typename scalar_t>
using block_getter = cmath::block_getter<size_type, Vc::array, scalar_t>;
// matrix actor
template <typename scalar_t, typename determinant_actor_t,
typename inverse_actor_t>
using actor =
cmath::matrix::actor<size_type, array_type, matrix_type, scalar_t,
determinant_actor_t, inverse_actor_t,
element_getter<scalar_t>, block_getter<scalar_t>>;*/

namespace determinant {

// determinant aggregation
/*template <typename scalar_t, class... As>
using actor =
cmath::matrix::determinant::actor<size_type, matrix_type, scalar_t, As...>;
// determinant::cofactor
template <typename scalar_t, size_type... Ds>
using cofactor =
cmath::matrix::determinant::cofactor<size_type, matrix_type, scalar_t,
element_getter<scalar_t>, Ds...>;
// determinant::partial_pivot_lud
template <typename scalar_t, size_type... Ds>
using partial_pivot_lud = cmath::matrix::determinant::partial_pivot_lud<
size_type, matrix_type, scalar_t, element_getter<scalar_t>, Ds...>;
// determinant::hard_coded
template <typename scalar_t, size_type... Ds>
using hard_coded =
cmath::matrix::determinant::hard_coded<size_type, matrix_type, scalar_t,
element_getter<scalar_t>, Ds...>;
// preset(s) as standard option(s) for user's convenience
template <typename scalar_t>
using preset0 =
actor<scalar_t, partial_pivot_lud<scalar_t>, hard_coded<scalar_t, 2, 4>>;
} // namespace determinant
namespace inverse {
// inverion aggregation
template <typename scalar_t, class... As>
using actor =
cmath::matrix::inverse::actor<size_type, matrix_type, scalar_t, As...>;
// inverse::cofactor
template <typename scalar_t, size_type... Ds>
using cofactor =
cmath::matrix::inverse::cofactor<size_type, matrix_type, scalar_t,
element_getter<scalar_t>, Ds...>;
// inverse::partial_pivot_lud
template <typename scalar_t, size_type... Ds>
using partial_pivot_lud =
cmath::matrix::inverse::partial_pivot_lud<size_type, matrix_type, scalar_t,
element_getter<scalar_t>, Ds...>;
// inverse::hard_coded
template <typename scalar_t, size_type... Ds>
using hard_coded =
cmath::matrix::inverse::hard_coded<size_type, matrix_type, scalar_t,
element_getter<scalar_t>, Ds...>;
// preset(s) as standard option(s) for user's convenience
template <typename scalar_t>
using preset0 =
actor<scalar_t, partial_pivot_lud<scalar_t>, hard_coded<scalar_t, 2, 4>>;*/

} // namespace determinant

} // namespace matrix
} // namespace algebra
24 changes: 12 additions & 12 deletions math/vc/include/algebra/math/impl/vc_transform3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ struct transform3 {
ALGEBRA_HOST_DEVICE
transform3(const vector3 &t, const vector3 &x, const vector3 &y,
const vector3 &z, bool get_inverse = true) {
_data.x = {x[0], x[1], x[2], 0.};
_data.y = {y[0], y[1], y[2], 0.};
_data.z = {z[0], z[1], z[2], 0.};
_data.t = {t[0], t[1], t[2], 1.};
_data.x = {x[0], x[1], x[2], 0.f};
_data.y = {y[0], y[1], y[2], 0.f};
_data.z = {z[0], z[1], z[2], 0.f};
_data.t = {t[0], t[1], t[2], 1.f};

if (get_inverse) {
_data_inv = invert(_data);
Expand All @@ -163,10 +163,10 @@ struct transform3 {
ALGEBRA_HOST_DEVICE
transform3(const vector3 &t) {

_data.x = {1., 0., 0., 0.};
_data.y = {0., 1., 0., 0.};
_data.z = {0., 0., 1., 0.};
_data.t = {t[0], t[1], t[2], 1.};
_data.x = {1.f, 0.f, 0.f, 0.f};
_data.y = {0.f, 1.f, 0.f, 0.f};
_data.z = {0.f, 0.f, 1.f, 0.f};
_data.t = {t[0], t[1], t[2], 1.f};

_data_inv = invert(_data);
}
Expand Down Expand Up @@ -199,10 +199,10 @@ struct transform3 {
ALGEBRA_HOST_DEVICE
transform3() {

_data.x = {1., 0., 0., 0.};
_data.y = {0., 1., 0., 0.};
_data.z = {0., 0., 1., 0.};
_data.t = {0., 0., 0., 1.};
_data.x = {1.f, 0.f, 0.f, 0.f};
_data.y = {0.f, 1.f, 0.f, 0.f};
_data.z = {0.f, 0.f, 1.f, 0.f};
_data.t = {0.f, 0.f, 0.f, 1.f};

_data_inv = _data;
}
Expand Down
2 changes: 1 addition & 1 deletion math/vc/include/algebra/math/impl/vc_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ALGEBRA_HOST_DEVICE inline auto cross(const vector_type1 &a,
-> decltype(a * b - a * b) {

return {a[1] * b[2] - b[1] * a[2], a[2] * b[0] - b[2] * a[0],
a[0] * b[1] - b[0] * a[1], 0};
a[0] * b[1] - b[0] * a[1], 0.f};
}

} // namespace algebra::vc::math
18 changes: 12 additions & 6 deletions storage/common/include/algebra/storage/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,23 @@ class vector {
template <typename... Values,
std::enable_if_t<std::conjunction_v<
std::is_convertible<Values, value_type>...> &&
sizeof...(Values) <= N,
sizeof...(Values) <= N && N != 4,
bool> = true>
constexpr vector(Values &&... vals) : m_data{std::forward<Values>(vals)...} {
constexpr vector(Values &&...vals) : m_data{std::forward<Values>(vals)...} {
if constexpr ((sizeof...(Values) < N) &&
(!std::conjunction_v<std::is_same<array_type, Values>...>)) {
zero_fill(std::make_index_sequence<N - sizeof...(Values)>{});
zero_fill(std::make_index_sequence<N - sizeof...(Values) - 1>{});
}
}

template <typename... Values,
std::enable_if_t<std::conjunction_v<
std::is_convertible<Values, value_type>...> &&
N == 4,
bool> = true>
constexpr vector(Values &&...vals)
: m_data{std::forward<Values>(vals)..., 0.f} {}

/// Construct from existing array storage @param vals .
constexpr vector(const array_type &vals) : m_data{vals} {}

Expand Down Expand Up @@ -132,9 +140,7 @@ class vector {
/// Sets the trailing uninitialized values to zero.
template <std::size_t... Is>
constexpr void zero_fill(std::index_sequence<Is...>) noexcept {
if constexpr (sizeof...(Is) > 0) {
((m_data[N - sizeof...(Is) + Is] = value_t(0)), ...);
}
//((m_data[N - sizeof...(Is) + Is] = value_t(0)), ...);
}
};

Expand Down
4 changes: 2 additions & 2 deletions storage/vc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Algebra plugins library, part of the ACTS project (R&D line)
#
# (c) 2021-2023 CERN for the benefit of the ACTS project
# (c) 2021-2024 CERN for the benefit of the ACTS project
#
# Mozilla Public License Version 2.0

Expand All @@ -9,6 +9,6 @@ algebra_add_library( algebra_vc_storage vc_storage
"include/algebra/storage/vc.hpp"
"include/algebra/storage/impl/vc_array4_wrapper.hpp" )
target_link_libraries( algebra_vc_storage
INTERFACE algebra::common Vc::Vc )
INTERFACE algebra::common algebra::common_storage Vc::Vc )
algebra_test_public_headers( algebra_vc_storage
"algebra/storage/vc.hpp" )
16 changes: 14 additions & 2 deletions tests/array/array_cmath.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Algebra plugins library, part of the ACTS project
*
* (c) 2020-2022 CERN for the benefit of the ACTS project
* (c) 2020-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand Down Expand Up @@ -32,6 +32,14 @@ struct test_specialisation_name {
}
};

// Register the tests
REGISTER_TYPED_TEST_SUITE_P(test_host_basics_vector, local_vectors, vector3,
getter);
REGISTER_TYPED_TEST_SUITE_P(test_host_basics_matrix, matrix3, matrix64,
matrix22);
REGISTER_TYPED_TEST_SUITE_P(test_host_basics_transform, transform3,
global_transformations);

// Instantiate the test(s).
typedef testing::Types<
test_types<float, algebra::array::point2<float>,
Expand All @@ -51,5 +59,9 @@ typedef testing::Types<
double, algebra::matrix::determinant::preset0<double>,
algebra::matrix::inverse::preset0<double>>>>
array_cmath_types;
INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_host_basics,
INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_host_basics_vector,
array_cmath_types, test_specialisation_name);
INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_host_basics_matrix,
array_cmath_types, test_specialisation_name);
INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_host_basics_transform,
array_cmath_types, test_specialisation_name);
Loading

0 comments on commit 562414f

Please sign in to comment.