// L============================================================================= // L This software is distributed under the MIT license. // L Copyright 2021 Péter Kardos // L============================================================================= #pragma once #include "MatrixImpl.hpp" namespace mathter { namespace impl { template struct ReinterpretCompatible : std::false_type {}; template struct ReinterpretCompatible, Matrix> { static constexpr bool value = std::is_convertible_v; }; template struct RepresentationCompatible : std::false_type {}; template struct RepresentationCompatible, Matrix::value, Layout2, Packed2>> { static constexpr bool value = std::is_convertible_v; }; template struct RepresentationCompatible, Matrix> { static constexpr bool value = std::is_convertible_v; }; } // namespace impl /// Changes the type, order and layout of the matrix, but the elements stay at the same place. template auto matrix_reinterpret_cast(const MatrixSourceT& source) -> std::enable_if_t::value, MatrixDestT> { MatrixDestT dest; for (int i = 0; i < source.RowCount(); ++i) { for (int j = 0; j < source.ColumnCount(); ++j) { dest(i, j) = typename traits::MatrixTraits::Type(source(i, j)); } } return dest; } /// Changes the type, order and layout of the matrix. /// The elements are transposed according to the change in order. template auto matrix_representation_cast(const MatrixSourceT& source) -> std::enable_if_t::value, MatrixDestT> { MatrixDestT dest; for (int i = 0; i < source.RowCount(); ++i) { for (int j = 0; j < source.ColumnCount(); ++j) { if constexpr (traits::MatrixTraits::Order == traits::MatrixTraits::Order) { dest(i, j) = typename traits::MatrixTraits::Type(source(i, j)); } else { dest(j, i) = typename traits::MatrixTraits::Type(source(i, j)); } } } return dest; } } // namespace mathter