VCCC  2024.05
VisualCamp Common C++ library
matrix_mul_scalar.hpp
Go to the documentation of this file.
1 # /*
2 # * Created by YongGyu Lee on 2020/02/05.
3 # */
4 #
5 # ifndef VCCC_MATH_MATRIX_MATRIX_MUL_SCALAR_HPP
6 # define VCCC_MATH_MATRIX_MATRIX_MUL_SCALAR_HPP
7 #
10 # include <type_traits>
11 # include <cassert>
12 
13 namespace vccc {
14 
15 namespace internal {
16 namespace math {
17 
18 template<typename LhsType, typename RhsType>
19 struct traits<MatrixMulScalar<LhsType, RhsType>> {
20  enum : int {
21  rows = traits<LhsType>::rows,
22  cols = traits<LhsType>::cols,
23  size = rows * cols,
24  };
25 
26  enum : int {
27  option = static_cast<int>(traits<LhsType>::option) | static_cast<int>(Flag::kReferenceUnsafe)
28  };
29  using value_type = typename LhsType::value_type;
30 };
31 
32 } // namespace math
33 } // namespace internal
34 
37 
38 template<typename LhsType, typename RhsType>
39 class MatrixMulScalar : public MatrixBase<MatrixMulScalar<LhsType, RhsType>> {
40  public:
41  using value_type = typename LhsType::value_type;
42  using lhs_type = internal::math::hold_type_selector_t<LhsType>;
43  using rhs_type = const std::remove_reference_t<RhsType>;
44 
45  constexpr MatrixMulScalar(const LhsType& lhs, const RhsType& value) : lhs(lhs), value(value) {
46  static_assert(!is_matrix<RhsType>::value, "");
47  }
48 
49  constexpr value_type operator() (std::size_t i) const { return lhs(i) * value; }
50  constexpr value_type operator() (std::size_t i, std::size_t j) const { return lhs(i, j) * value; }
51  constexpr value_type operator[] (std::size_t i) const { return lhs[i] * value; }
52 
53  private:
54  lhs_type lhs;
55  rhs_type value;
56 };
57 
59 constexpr inline
60 MatrixMulScalar<LhsType, RhsType>
61 operator * (const MatrixBase<LhsType>& lhs, const RhsType& value) {
62  return MatrixMulScalar<LhsType, RhsType>(*static_cast<const LhsType*>(&lhs), value);
63 }
64 
66 
67 } // namespace vccc
68 
69 # endif // VCCC_MATH_MATRIX_MATRIX_MUL_SCALAR_HPP
Definition: matrix_base.hpp:20
Definition: matrix_mul_scalar.hpp:39
const std::remove_reference_t< RhsType > rhs_type
Definition: matrix_mul_scalar.hpp:43
constexpr MatrixMulScalar(const LhsType &lhs, const RhsType &value)
Definition: matrix_mul_scalar.hpp:45
constexpr value_type operator[](std::size_t i) const
Definition: matrix_mul_scalar.hpp:51
internal::math::hold_type_selector_t< LhsType > lhs_type
Definition: matrix_mul_scalar.hpp:42
typename LhsType::value_type value_type
Definition: matrix_mul_scalar.hpp:41
constexpr value_type operator()(std::size_t i) const
Definition: matrix_mul_scalar.hpp:49
constexpr MatrixMulMatrix< E1, E2 > operator*(const MatrixBase< E1 > &lhs, const MatrixBase< E2 > &rhs)
Definition: matrix_mul_matrix.hpp:77
Definition: directory.h:12
constexpr auto size(const C &c) -> decltype(c.size())
Definition: size.hpp:16
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
Definition: matrix_base.hpp:67