From 2b17cf6f97a238d897f82a3cf9387cc4f9b28bb7 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Fri, 21 Mar 2014 01:17:19 -0400 Subject: [PATCH] Add scalar-matrix multiplication --- Base/include/MatrixBase.h | 49 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/Base/include/MatrixBase.h b/Base/include/MatrixBase.h index 80facc4..51303a3 100644 --- a/Base/include/MatrixBase.h +++ b/Base/include/MatrixBase.h @@ -234,6 +234,54 @@ namespace FasTC { ResultType GetMultiplication() const { return MultiplyMatrix(m_A, m_B); } }; + template + class MultSwitch< + eVectorType_Matrix, + eVectorType_Scalar, + TypeOne, TypeTwo> { + private: + const TypeOne &m_A; + const TypeTwo &m_B; + + public: + typedef MatrixBase ResultType; + + MultSwitch(const TypeOne &a, const TypeTwo &b) + : m_A(a), m_B(b) { } + + ResultType GetMultiplication() const { + TypeOne result; + for(int i = 0; i < TypeOne::Size; i++) { + result[i] = m_A[i] * m_B; + } + return result; + } + }; + + template + class MultSwitch< + eVectorType_Scalar, + eVectorType_Matrix, + TypeOne, TypeTwo> { + private: + const TypeOne &m_A; + const TypeTwo &m_B; + + public: + typedef MatrixBase ResultType; + + MultSwitch(const TypeOne &a, const TypeTwo &b) + : m_A(a), m_B(b) { } + + ResultType GetMultiplication() const { + TypeTwo result; + for(int i = 0; i < TypeTwo::Size; i++) { + result[i] = m_A * m_B[i]; + } + return result; + } + }; + // Outer product... template MatrixBase<_T, N, M> operator^( @@ -256,7 +304,6 @@ namespace FasTC { ) { return a ^ b; } - }; #endif // BASE_INCLUDE_MATRIXBASE_H_