-
Notifications
You must be signed in to change notification settings - Fork 1
/
matmul.h
35 lines (26 loc) · 1.11 KB
/
matmul.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/****************************************************************/
/* author: Aydin Buluc ([email protected]) ----------------------/
/* description: Helper class in order to get rid of copying */
/* and temporaries during the y += A*x or A+=B*C calls */
/* acknowlegment: This technique is described in Stroustrup, */
/* The C++ Programming Language, 3rd Edition, */
/* Section 22.4.7 [Temporaries, Copying and Loops] */
/****************************************************************/
#ifndef _MAT_MUL_H
#define _MAT_MUL_H
template <class OPT1, class OPT2>
struct Matmul
{
const OPT1 & op1; // just keeps references to objects
const OPT2 & op2;
// Constructor
Matmul(const OPT1 & operand1, const OPT2 & operand2): op1(operand1), op2(operand2) { }
// No need for operator BT() because we have the corresponding copy constructor
// and assignment operators to evaluate and return result !
};
template <class OPT1, class OPT2>
inline Matmul< OPT1,OPT2 > operator* (const OPT1 & operand1, const OPT2 & operand2)
{
return Matmul< OPT1,OPT2 >(operand1,operand2); //! Just defer the multiplication
}
#endif