1 | /***************************************************************************
|
---|
2 | * blitz/meta/matmat.h TinyMatrix matrix-matrix product metaprogram
|
---|
3 | *
|
---|
4 | * $Id: matmat.h,v 1.1.1.1 1999-11-26 16:37:08 ansari Exp $
|
---|
5 | *
|
---|
6 | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
|
---|
7 | *
|
---|
8 | * This program is free software; you can redistribute it and/or
|
---|
9 | * modify it under the terms of the GNU General Public License
|
---|
10 | * as published by the Free Software Foundation; either version 2
|
---|
11 | * of the License, or (at your option) any later version.
|
---|
12 | *
|
---|
13 | * This program is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | * GNU General Public License for more details.
|
---|
17 | *
|
---|
18 | * Suggestions: blitz-suggest@cybervision.com
|
---|
19 | * Bugs: blitz-bugs@cybervision.com
|
---|
20 | *
|
---|
21 | * For more information, please see the Blitz++ Home Page:
|
---|
22 | * http://seurat.uwaterloo.ca/blitz/
|
---|
23 | *
|
---|
24 | ***************************************************************************
|
---|
25 | * $Log: not supported by cvs2svn $
|
---|
26 | * Revision 1.1.1.1 1999/04/09 17:59:03 ansari
|
---|
27 | * Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99
|
---|
28 | *
|
---|
29 | * Revision 1.3 1998/03/14 00:08:44 tveldhui
|
---|
30 | * 0.2-alpha-05
|
---|
31 | *
|
---|
32 | * Revision 1.2 1998/03/14 00:04:47 tveldhui
|
---|
33 | * 0.2-alpha-05
|
---|
34 | *
|
---|
35 | * Revision 1.1 1997/07/16 14:51:20 tveldhui
|
---|
36 | * Update: Alpha release 0.2 (Arrays)
|
---|
37 | *
|
---|
38 | */
|
---|
39 |
|
---|
40 | #ifndef BZ_META_MATMAT_H
|
---|
41 | #define BZ_META_MATMAT_H
|
---|
42 |
|
---|
43 | #ifndef BZ_TINYMAT_H
|
---|
44 | #error <blitz/meta/matmat.h> must be included via <blitz/tinymat.h>
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #include <blitz/meta/metaprog.h>
|
---|
48 | #include <blitz/tinymatexpr.h>
|
---|
49 |
|
---|
50 | BZ_NAMESPACE(blitz)
|
---|
51 |
|
---|
52 | // Template metaprogram for matrix-matrix multiplication
|
---|
53 | template<int N_rows1, int N_columns, int N_columns2, int N_rowStride1,
|
---|
54 | int N_colStride1, int N_rowStride2, int N_colStride2, int K>
|
---|
55 | class _bz_meta_matrixMatrixProduct {
|
---|
56 | public:
|
---|
57 | enum { go = (K != N_columns - 1) };
|
---|
58 |
|
---|
59 | template<class T_numtype1, class T_numtype2>
|
---|
60 | static inline BZ_PROMOTE(T_numtype1, T_numtype2)
|
---|
61 | f(const T_numtype1* matrix1, const T_numtype2* matrix2, int i, int j)
|
---|
62 | {
|
---|
63 | return matrix1[i * N_rowStride1 + K * N_colStride1]
|
---|
64 | * matrix2[K * N_rowStride2 + j * N_colStride2]
|
---|
65 | + _bz_meta_matrixMatrixProduct<N_rows1 * go, N_columns * go,
|
---|
66 | N_columns2 * go, N_rowStride1 * go, N_colStride1 * go,
|
---|
67 | N_rowStride2 * go, N_colStride2 * go, (K+1) * go>
|
---|
68 | ::f(matrix1, matrix2, i, j);
|
---|
69 | }
|
---|
70 | };
|
---|
71 |
|
---|
72 | template<>
|
---|
73 | class _bz_meta_matrixMatrixProduct<0,0,0,0,0,0,0,0> {
|
---|
74 | public:
|
---|
75 | static inline _bz_meta_nullOperand f(const void*, const void*, int, int)
|
---|
76 | { return _bz_meta_nullOperand(); }
|
---|
77 | };
|
---|
78 |
|
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 | template<class T_numtype1, class T_numtype2, int N_rows1, int N_columns,
|
---|
83 | int N_columns2, int N_rowStride1, int N_colStride1,
|
---|
84 | int N_rowStride2, int N_colStride2>
|
---|
85 | class _bz_tinyMatrixMatrixProduct {
|
---|
86 | public:
|
---|
87 | typedef BZ_PROMOTE(T_numtype1, T_numtype2) T_numtype;
|
---|
88 |
|
---|
89 | enum { rows = N_rows1, columns = N_columns2 };
|
---|
90 |
|
---|
91 | _bz_tinyMatrixMatrixProduct(const T_numtype1* matrix1,
|
---|
92 | const T_numtype2* matrix2)
|
---|
93 | : matrix1_(matrix1), matrix2_(matrix2)
|
---|
94 | { }
|
---|
95 |
|
---|
96 | _bz_tinyMatrixMatrixProduct(const _bz_tinyMatrixMatrixProduct<T_numtype1,
|
---|
97 | T_numtype2, N_rows1, N_columns, N_columns2, N_rowStride1, N_colStride1,
|
---|
98 | N_rowStride2, N_colStride2>& x)
|
---|
99 | : matrix1_(x.matrix1_), matrix2_(x.matrix2_)
|
---|
100 | { }
|
---|
101 |
|
---|
102 | const T_numtype1* matrix1() const
|
---|
103 | { return matrix1_; }
|
---|
104 |
|
---|
105 | const T_numtype2* matrix2() const
|
---|
106 | { return matrix2_; }
|
---|
107 |
|
---|
108 | T_numtype operator()(int i, int j) const
|
---|
109 | {
|
---|
110 | return _bz_meta_matrixMatrixProduct<N_rows1, N_columns,
|
---|
111 | N_columns2, N_rowStride1, N_colStride1, N_rowStride2,
|
---|
112 | N_colStride2, 0>::f(matrix1_, matrix2_, i, j);
|
---|
113 | }
|
---|
114 |
|
---|
115 | protected:
|
---|
116 | const T_numtype1* matrix1_;
|
---|
117 | const T_numtype2* matrix2_;
|
---|
118 | };
|
---|
119 |
|
---|
120 | template<class T_numtype1, class T_numtype2, int N_rows1, int N_columns1,
|
---|
121 | int N_columns2>
|
---|
122 | inline
|
---|
123 | _bz_tinyMatExpr<_bz_tinyMatrixMatrixProduct<T_numtype1, T_numtype2, N_rows1,
|
---|
124 | N_columns1, N_columns2, N_columns1, 1, N_columns2, 1> >
|
---|
125 | product(const TinyMatrix<T_numtype1, N_rows1, N_columns1>& a,
|
---|
126 | const TinyMatrix<T_numtype2, N_columns1, N_columns2>& b)
|
---|
127 | {
|
---|
128 | typedef _bz_tinyMatrixMatrixProduct<T_numtype1, T_numtype2,
|
---|
129 | N_rows1, N_columns1, N_columns2, N_columns1, 1, N_columns2, 1> T_expr;
|
---|
130 | return _bz_tinyMatExpr<T_expr>(T_expr(a.data(), b.data()));
|
---|
131 | }
|
---|
132 |
|
---|
133 | BZ_NAMESPACE_END
|
---|
134 |
|
---|
135 | #endif // BZ_META_MATMAT_H
|
---|
136 |
|
---|