Skip to content

Commit

Permalink
refactor: moved VecOrient meta function to backend namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdcvlsc committed Aug 9, 2023
1 parent eb4e7d7 commit c8d2a95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
25 changes: 13 additions & 12 deletions include/cyfre/vectors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@
#include "matrix.hpp"

namespace cyfre {

template <typename Dim, axis_t Axis>
struct VecOrient {
static constexpr bool IsFixed = !std::is_same<Dim, dynamic>::value;
using FixedAxisX = fixed<1, Dim::rows>;
using FixedAxisY = fixed<Dim::rows, 1>;
using FixedOrientation = typename std::conditional<Axis == axis_t::x, FixedAxisX, FixedAxisY>::type;
using OrientDim = typename std::conditional<IsFixed, FixedOrientation, dynamic>::type;
static constexpr size_t rows = (Axis == axis_t::x) ? 1 : Dim::rows;
static constexpr size_t cols = (Axis == axis_t::x) ? Dim::rows : 1;
};
namespace backend {
template <typename Dim, axis_t Axis>
struct VecOrient {
static constexpr bool IsFixed = !std::is_same<Dim, dynamic<0, 0>>::value;
using FixedAxisX = fixed<1, Dim::rows>;
using FixedAxisY = fixed<Dim::rows, 1>;
using FixedOrientation = typename std::conditional<Axis == axis_t::x, FixedAxisX, FixedAxisY>::type;
using OrientDim = typename std::conditional<IsFixed, FixedOrientation, dynamic<0, 0>>::type;
static constexpr size_t rows = (Axis == axis_t::x) ? 1 : Dim::rows;
static constexpr size_t cols = (Axis == axis_t::x) ? Dim::rows : 1;
};
} // namespace backend

/// ===============================================================================================================

/// @brief Fixed vector.
template <
concepts::scalars T, typename Dim, axis_t Axis, order_t Order = order_t::row_major,
typename Blas = backend::cyfre_blas>
struct vec : public mat<T, typename VecOrient<Dim, Axis>::OrientDim, Order, Blas> {
struct vec : public mat<T, typename backend::VecOrient<Dim, Axis>::OrientDim, Order, Blas> {
constexpr vec();

vec(size_t n);
Expand Down
4 changes: 2 additions & 2 deletions src/cyfre/vectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

#define CYFRE_VEC_TARGS template <concepts::scalars T, typename Dim, axis_t Axis, order_t Order, typename Blas>
#define CYFRE_VEC vec<T, Dim, Axis, Order, Blas>
#define CYFRE_VEC_MAT_CONSTRUCTOR mat<T, typename VecOrient<Dim, Axis>::OrientDim, Order, Blas>
#define CYFRE_VEC_MAT_CONSTRUCTOR mat<T, typename backend::VecOrient<Dim, Axis>::OrientDim, Order, Blas>

#include "../../include/cyfre/vectors.hpp"

namespace cyfre {

CYFRE_VEC_TARGS constexpr CYFRE_VEC::vec()
: CYFRE_VEC_MAT_CONSTRUCTOR(VecOrient<Dim, Axis>::rows, VecOrient<Dim, Axis>::cols) {}
: CYFRE_VEC_MAT_CONSTRUCTOR(backend::VecOrient<Dim, Axis>::rows, backend::VecOrient<Dim, Axis>::cols) {}

CYFRE_VEC_TARGS CYFRE_VEC::vec(size_t n) : CYFRE_VEC_MAT_CONSTRUCTOR() {
if constexpr (Axis == axis_t::x) {
Expand Down

0 comments on commit c8d2a95

Please sign in to comment.