Skip to content

Commit

Permalink
Initial matrix implementaiton
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Jul 24, 2024
1 parent de038ec commit b6960a7
Show file tree
Hide file tree
Showing 11 changed files with 421 additions and 261 deletions.
12 changes: 9 additions & 3 deletions frontend/vc_aos/include/algebra/vc_aos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#pragma once

// Project include(s).
#include "algebra/math/cmath.hpp"
#include "algebra/math/vc_aos.hpp"
#include "algebra/storage/vc_aos.hpp"

Expand All @@ -23,7 +22,7 @@ namespace vc_aos {
/// @{

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

/// @}

Expand All @@ -45,7 +44,7 @@ using vc_aos::math::theta;
/// @name Getter functions on @c algebra::vc_aos::matrix_type
/// @{

using cmath::element;
using vc_aos::math::element;

/// Function extracting a slice from matrix44 - const
template <std::size_t SIZE, template <typename, std::size_t> class array_t,
Expand Down Expand Up @@ -102,4 +101,11 @@ using vc_aos::math::normalize;

} // namespace vector

namespace matrix {

template <typename scalar_t>
using actor = vc_aos::matrix::actor<vc_aos::storage_type, scalar_t>;

} // namespace matrix

} // namespace algebra
5 changes: 3 additions & 2 deletions frontend/vc_cmath/include/algebra/vc_cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ namespace vc_aos {
/// @{

template <typename T>
using transform3_actor = matrix::actor<T, matrix::determinant::preset0<T>,
matrix::inverse::preset0<T>>;
using transform3_actor =
algebra::matrix::actor<T, algebra::matrix::determinant::preset0<T>,
algebra::matrix::inverse::preset0<T>>;

template <typename T>
using transform3 = cmath::transform3<transform3_actor<T>>;
Expand Down
68 changes: 48 additions & 20 deletions math/vc_aos/include/algebra/math/impl/vc_aos_getter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "algebra/math/common.hpp"
#include "algebra/math/impl/vc_aos_vector.hpp"
#include "algebra/qualifiers.hpp"
#include "algebra/storage/matrix.hpp"
#include "algebra/storage/vector.hpp"

// Vc include(s).
Expand All @@ -27,47 +28,47 @@ namespace algebra::vc_aos::math {
/// This method retrieves phi from a vector, vector base with rows >= 2
///
/// @param v the input vector
template <typename vector_type,
std::enable_if_t<(Vc::is_simd_vector<vector_type>::value ||
algebra::detail::is_storage_vector_v<vector_type>),
template <typename vector_t,
std::enable_if_t<(Vc::is_simd_vector<vector_t>::value ||
algebra::detail::is_storage_vector_v<vector_t>),
bool> = true>
ALGEBRA_HOST_DEVICE inline auto phi(const vector_type &v) noexcept {
ALGEBRA_HOST_DEVICE inline auto phi(const vector_t &v) noexcept {

return algebra::math::atan2(v[1], v[0]);
}

/// This method retrieves the perpendicular magnitude of a vector with rows >= 2
///
/// @param v the input vector
template <typename vector_type,
std::enable_if_t<(Vc::is_simd_vector<vector_type>::value ||
algebra::detail::is_storage_vector_v<vector_type>),
template <typename vector_t,
std::enable_if_t<(Vc::is_simd_vector<vector_t>::value ||
algebra::detail::is_storage_vector_v<vector_t>),
bool> = true>
ALGEBRA_HOST_DEVICE inline auto perp(const vector_type &v) noexcept {
ALGEBRA_HOST_DEVICE inline auto perp(const vector_t &v) noexcept {

return algebra::math::sqrt(v[0] * v[0] + v[1] * v[1]);
}

/// This method retrieves theta from a vector, vector base with rows >= 3
///
/// @param v the input vector
template <typename vector_type,
std::enable_if_t<(Vc::is_simd_vector<vector_type>::value ||
algebra::detail::is_storage_vector_v<vector_type>),
template <typename vector_t,
std::enable_if_t<(Vc::is_simd_vector<vector_t>::value ||
algebra::detail::is_storage_vector_v<vector_t>),
bool> = true>
ALGEBRA_HOST_DEVICE inline auto theta(const vector_type &v) noexcept {
ALGEBRA_HOST_DEVICE inline auto theta(const vector_t &v) noexcept {

return algebra::math::atan2(perp(v), v[2]);
}

/// This method retrieves the norm of a vector, no dimension restriction
///
/// @param v the input vector
template <typename vector_type,
std::enable_if_t<(Vc::is_simd_vector<vector_type>::value ||
algebra::detail::is_storage_vector_v<vector_type>),
template <typename vector_t,
std::enable_if_t<(Vc::is_simd_vector<vector_t>::value ||
algebra::detail::is_storage_vector_v<vector_t>),
bool> = true>
ALGEBRA_HOST_DEVICE inline auto norm(const vector_type &v) {
ALGEBRA_HOST_DEVICE inline auto norm(const vector_t &v) {

return algebra::math::sqrt(dot(v, v));
}
Expand All @@ -76,13 +77,40 @@ ALGEBRA_HOST_DEVICE inline auto norm(const vector_type &v) {
/// rows >= 3
///
/// @param v the input vector
template <typename vector_type,
std::enable_if_t<(Vc::is_simd_vector<vector_type>::value ||
algebra::detail::is_storage_vector_v<vector_type>),
template <typename vector_t,
std::enable_if_t<(Vc::is_simd_vector<vector_t>::value ||
algebra::detail::is_storage_vector_v<vector_t>),
bool> = true>
ALGEBRA_HOST_DEVICE inline auto eta(const vector_type &v) noexcept {
ALGEBRA_HOST_DEVICE inline auto eta(const vector_t &v) noexcept {

return algebra::math::atanh(v[2] / norm(v));
}

/// Function extracting an element from a matrix (const)
template <
typename matrix_t,
std::enable_if_t<
(Vc::is_simd_vector<typename matrix_t::vector_type>::value ||
algebra::detail::is_storage_vector_v<typename matrix_t::vector_type>),
bool> = true>
ALGEBRA_HOST_DEVICE inline decltype(auto) element(const matrix_t &m,
std::size_t row,
std::size_t col) {

return m[col][row];
}

/// Function extracting an element from a matrix (non-const)
template <
typename matrix_t,
std::enable_if_t<
(Vc::is_simd_vector<typename matrix_t::vector_type>::value ||
algebra::detail::is_storage_vector_v<typename matrix_t::vector_type>),
bool> = true>
ALGEBRA_HOST_DEVICE inline decltype(auto) element(matrix_t &m, std::size_t row,
std::size_t col) {

return m[col][row];
}

} // namespace algebra::vc_aos::math
Loading

0 comments on commit b6960a7

Please sign in to comment.