1#ifndef PBAT_MATH_LINALG_MINI_SCALE_H
2#define PBAT_MATH_LINALG_MINI_SCALE_H
7#include "pbat/HostDevice.h"
17template <
class TMatrix>
21 using NestedType = TMatrix;
22 using ScalarType =
typename NestedType::ScalarType;
23 using SelfType = Scale<NestedType>;
25 static auto constexpr kRows = NestedType::kRows;
26 static auto constexpr kCols = NestedType::kCols;
27 static bool constexpr bRowMajor = NestedType::bRowMajor;
29 PBAT_HOST_DEVICE Scale(ScalarType _k, NestedType
const& _A) : k(_k), A(_A) {}
31 PBAT_HOST_DEVICE ScalarType operator()(
auto i,
auto j)
const {
return k * A(i, j); }
34 PBAT_HOST_DEVICE ScalarType operator()(
auto i)
const {
return (*
this)(i % kRows, i / kRows); }
35 PBAT_HOST_DEVICE ScalarType operator[](
auto i)
const {
return (*
this)(i); }
37 PBAT_MINI_READ_API(SelfType)
44template <
class TMatrix>
45PBAT_HOST_DEVICE
auto operator*(
typename std::remove_cvref_t<TMatrix>::ScalarType k, TMatrix&& A)
47 using MatrixType = std::remove_cvref_t<TMatrix>;
48 PBAT_MINI_CHECK_CMATRIX(MatrixType);
52template <
class TMatrix>
53PBAT_HOST_DEVICE
auto operator*(TMatrix&& A,
typename std::remove_cvref_t<TMatrix>::ScalarType k)
55 return k * std::forward<TMatrix>(A);
58template <
class TMatrix>
59PBAT_HOST_DEVICE
auto operator*=(TMatrix&& A,
typename std::remove_cvref_t<TMatrix>::ScalarType k)
61 MultiplyAssign(std::forward<TMatrix>(A), k);
65template <
class TMatrix>
66PBAT_HOST_DEVICE
auto operator/(TMatrix&& A,
typename std::remove_cvref_t<TMatrix>::ScalarType k)
68 using MatrixType = std::remove_cvref_t<TMatrix>;
69 PBAT_MINI_CHECK_CMATRIX(MatrixType);
70 using ScalarType =
typename MatrixType::ScalarType;
71 return Scale<MatrixType>(ScalarType(1. / k), std::forward<TMatrix>(A));
74template <
class TMatrix>
75PBAT_HOST_DEVICE
auto operator/=(TMatrix&& A,
typename std::remove_cvref_t<TMatrix>::ScalarType k)
77 DivideAssign(std::forward<TMatrix>(A), k);
81template <
class TMatrix>
82PBAT_HOST_DEVICE
auto operator-(TMatrix&& A)
84 using MatrixType = std::remove_cvref_t<TMatrix>;
85 PBAT_MINI_CHECK_CMATRIX(MatrixType);
86 using ScalarType =
typename MatrixType::ScalarType;
Mini linear algebra related functionality.
Definition Assign.h:12
Linear Algebra related functionality.
Definition FilterEigenvalues.h:7
Math related functionality.
Definition Concepts.h:19
Rational operator*(Integer a, Rational const &b)
Multiplication operation between Rational and integral type.
Definition Rational.h:164
The main namespace of the library.
Definition Aliases.h:15