1 #ifndef _theplu_yat_utility_expression_matrix_binary 2 #define _theplu_yat_utility_expression_matrix_binary 25 #include "yat/utility/BasicMatrix.h" 26 #include "yat/utility/BLAS_utility.h" 27 #include "yat/utility/MatrixExpression.h" 28 #include "yat/utility/yat_assert.h" 30 #include <gsl/gsl_matrix.h> 38 namespace expression {
42 template<
typename LHS,
typename RHS,
class OP>
44 :
public MatrixExpression<MatrixBinary<LHS, RHS, OP> >
47 MatrixBinary(
const BasicMatrix<LHS>& lhs,
const BasicMatrix<RHS>& rhs)
48 : lhs_(lhs), rhs_(rhs)
52 size_t rows(
void)
const {
return lhs_.rows(); }
53 size_t columns(
void)
const {
return rhs_.columns(); }
55 double operator()(
size_t row,
size_t column)
const 56 {
return get(row, column, op_); }
58 void calculate_matrix(gsl_matrix*& result)
const 60 detail::reallocate(result, this->rows(), this->columns());
61 calculate_matrix(result, op_);
65 const BasicMatrix<LHS>& lhs_;
66 const BasicMatrix<RHS>& rhs_;
70 void calculate_matrix(gsl_matrix*& result, T)
const 72 YAT_ASSERT(detail::rows(result) == this->rows());
73 YAT_ASSERT(detail::columns(result) == this->columns());
74 for (
size_t i=0; i<rows(); ++i)
75 for (
size_t j=0; j<columns(); ++j)
76 gsl_matrix_set(result, i, j, (*
this)(i, j));
80 double get(
size_t row,
size_t column, Plus)
const 82 return lhs_(row, column) + rhs_(row, column);
86 double get(
size_t row,
size_t column, Minus)
const 88 return lhs_(row, column) - rhs_(row, column);
The Department of Theoretical Physics namespace as we define it.