1 /*
2 * Copyright (c) 2010, Michael Lehn
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3) Neither the name of the FLENS development group nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef FLENS_BLAS_CLOSURES_PRUNEMATRIXCLOSURE_TCC
34 #define FLENS_BLAS_CLOSURES_PRUNEMATRIXCLOSURE_TCC 1
35
36 #include <flens/typedefs.h>
37
38 namespace flens {
39
40 //-- General definition --------------------------------------------------------
41
42 template <typename Matrix>
43 template <typename ALPHA>
44 const ALPHA &
45 PruneMatrixClosure<Matrix>::updateScalingFactor(const ALPHA &alpha,
46 const Matrix &)
47 {
48 return alpha;
49 }
50
51 template <typename Matrix>
52 Transpose
53 PruneMatrixClosure<Matrix>::updateTranspose(Transpose trans)
54 {
55 return trans;
56 }
57
58 template <typename Matrix>
59 const typename PruneMatrixClosure<Matrix>::Remainder &
60 PruneMatrixClosure<Matrix>::remainder(const Matrix &matrix)
61 {
62 return matrix;
63 }
64
65 //-- Specialization for particular closures ------------------------------------
66 //-- Closure from alpha*A
67 template <typename L, typename R>
68 struct PruneMatrixClosure<MatrixClosure<OpMult, ScalarValue<L>, R> >
69 {
70 typedef MatrixClosure<OpMult, ScalarValue<L>, R> MC;
71
72 typedef typename PruneMatrixClosure<R>::ScalingFactor _ScalingFactor;
73 typedef typename Promotion<L, _ScalingFactor>::Type ScalingFactor;
74 typedef typename PruneMatrixClosure<R>::Remainder Remainder;
75
76 template <typename ALPHA>
77 static const typename Promotion<ALPHA, ScalingFactor>::Type
78 updateScalingFactor(const ALPHA &alpha, const MC &mc)
79 {
80 typedef PruneMatrixClosure<R> PMC;
81 return PMC::updateScalingFactor(alpha*mc.left().value(), mc.right());
82 }
83
84 static Transpose
85 updateTranspose(Transpose trans)
86 {
87 return PruneMatrixClosure<R>::updateTranspose(trans);
88 }
89
90 static const Remainder &
91 remainder(const MC &mc)
92 {
93 return PruneMatrixClosure<R>::remainder(mc.right());
94 }
95 };
96
97 //-- Closure from transpose(A)
98 template <typename R>
99 struct PruneMatrixClosure<MatrixClosure<OpTrans, R, R> >
100 {
101 typedef MatrixClosure<OpTrans, R, R> MC;
102
103 typedef typename PruneMatrixClosure<R>::ScalingFactor ScalingFactor;
104 typedef typename PruneMatrixClosure<R>::Remainder Remainder;
105
106 template <typename ALPHA>
107 static const typename Promotion<ALPHA, ScalingFactor>::Type
108 updateScalingFactor(const ALPHA &alpha, const MC &mc)
109 {
110 return PruneMatrixClosure<R>::updateScalingFactor(alpha, mc.right());
111 }
112
113 static Transpose
114 updateTranspose(Transpose trans)
115 {
116 trans = PruneMatrixClosure<R>::updateTranspose(trans);
117 return Transpose(trans^Trans);
118 }
119
120 static const Remainder &
121 remainder(const MC &mc)
122 {
123 return PruneMatrixClosure<R>::remainder(mc.right());
124 }
125 };
126
127 //-- Closure from conjugate(A)
128 template <typename R>
129 struct PruneMatrixClosure<MatrixClosure<OpConj, R, R> >
130 {
131 typedef MatrixClosure<OpConj, R, R> MC;
132
133 typedef typename PruneMatrixClosure<R>::ScalingFactor ScalingFactor;
134 typedef typename PruneMatrixClosure<R>::Remainder Remainder;
135
136 template <typename ALPHA>
137 static const typename Promotion<ALPHA, ScalingFactor>::Type
138 updateScalingFactor(const ALPHA &alpha, const MC &mc)
139 {
140 return PruneMatrixClosure<R>::updateScalingFactor(alpha, mc.right());
141 }
142
143 static Transpose
144 updateTranspose(Transpose trans)
145 {
146 trans = PruneMatrixClosure<R>::updateTranspose(trans);
147 return Transpose(trans^Conj);
148 }
149
150 static const Remainder &
151 remainder(const MC &mc)
152 {
153 return PruneMatrixClosure<R>::remainder(mc.right());
154 }
155 };
156
157 } // namespace flens
158
159 #endif // FLENS_BLAS_CLOSURES_PRUNEMATRIXCLOSURE_TCC
160
2 * Copyright (c) 2010, Michael Lehn
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3) Neither the name of the FLENS development group nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef FLENS_BLAS_CLOSURES_PRUNEMATRIXCLOSURE_TCC
34 #define FLENS_BLAS_CLOSURES_PRUNEMATRIXCLOSURE_TCC 1
35
36 #include <flens/typedefs.h>
37
38 namespace flens {
39
40 //-- General definition --------------------------------------------------------
41
42 template <typename Matrix>
43 template <typename ALPHA>
44 const ALPHA &
45 PruneMatrixClosure<Matrix>::updateScalingFactor(const ALPHA &alpha,
46 const Matrix &)
47 {
48 return alpha;
49 }
50
51 template <typename Matrix>
52 Transpose
53 PruneMatrixClosure<Matrix>::updateTranspose(Transpose trans)
54 {
55 return trans;
56 }
57
58 template <typename Matrix>
59 const typename PruneMatrixClosure<Matrix>::Remainder &
60 PruneMatrixClosure<Matrix>::remainder(const Matrix &matrix)
61 {
62 return matrix;
63 }
64
65 //-- Specialization for particular closures ------------------------------------
66 //-- Closure from alpha*A
67 template <typename L, typename R>
68 struct PruneMatrixClosure<MatrixClosure<OpMult, ScalarValue<L>, R> >
69 {
70 typedef MatrixClosure<OpMult, ScalarValue<L>, R> MC;
71
72 typedef typename PruneMatrixClosure<R>::ScalingFactor _ScalingFactor;
73 typedef typename Promotion<L, _ScalingFactor>::Type ScalingFactor;
74 typedef typename PruneMatrixClosure<R>::Remainder Remainder;
75
76 template <typename ALPHA>
77 static const typename Promotion<ALPHA, ScalingFactor>::Type
78 updateScalingFactor(const ALPHA &alpha, const MC &mc)
79 {
80 typedef PruneMatrixClosure<R> PMC;
81 return PMC::updateScalingFactor(alpha*mc.left().value(), mc.right());
82 }
83
84 static Transpose
85 updateTranspose(Transpose trans)
86 {
87 return PruneMatrixClosure<R>::updateTranspose(trans);
88 }
89
90 static const Remainder &
91 remainder(const MC &mc)
92 {
93 return PruneMatrixClosure<R>::remainder(mc.right());
94 }
95 };
96
97 //-- Closure from transpose(A)
98 template <typename R>
99 struct PruneMatrixClosure<MatrixClosure<OpTrans, R, R> >
100 {
101 typedef MatrixClosure<OpTrans, R, R> MC;
102
103 typedef typename PruneMatrixClosure<R>::ScalingFactor ScalingFactor;
104 typedef typename PruneMatrixClosure<R>::Remainder Remainder;
105
106 template <typename ALPHA>
107 static const typename Promotion<ALPHA, ScalingFactor>::Type
108 updateScalingFactor(const ALPHA &alpha, const MC &mc)
109 {
110 return PruneMatrixClosure<R>::updateScalingFactor(alpha, mc.right());
111 }
112
113 static Transpose
114 updateTranspose(Transpose trans)
115 {
116 trans = PruneMatrixClosure<R>::updateTranspose(trans);
117 return Transpose(trans^Trans);
118 }
119
120 static const Remainder &
121 remainder(const MC &mc)
122 {
123 return PruneMatrixClosure<R>::remainder(mc.right());
124 }
125 };
126
127 //-- Closure from conjugate(A)
128 template <typename R>
129 struct PruneMatrixClosure<MatrixClosure<OpConj, R, R> >
130 {
131 typedef MatrixClosure<OpConj, R, R> MC;
132
133 typedef typename PruneMatrixClosure<R>::ScalingFactor ScalingFactor;
134 typedef typename PruneMatrixClosure<R>::Remainder Remainder;
135
136 template <typename ALPHA>
137 static const typename Promotion<ALPHA, ScalingFactor>::Type
138 updateScalingFactor(const ALPHA &alpha, const MC &mc)
139 {
140 return PruneMatrixClosure<R>::updateScalingFactor(alpha, mc.right());
141 }
142
143 static Transpose
144 updateTranspose(Transpose trans)
145 {
146 trans = PruneMatrixClosure<R>::updateTranspose(trans);
147 return Transpose(trans^Conj);
148 }
149
150 static const Remainder &
151 remainder(const MC &mc)
152 {
153 return PruneMatrixClosure<R>::remainder(mc.right());
154 }
155 };
156
157 } // namespace flens
158
159 #endif // FLENS_BLAS_CLOSURES_PRUNEMATRIXCLOSURE_TCC
160