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_PRUNEVECTORCLOSURE_TCC
34 #define FLENS_BLAS_CLOSURES_PRUNEVECTORCLOSURE_TCC 1
35
36 #include <flens/typedefs.h>
37
38 namespace flens {
39
40 //-- General definition --------------------------------------------------------
41
42 template <typename Vector>
43 template <typename ALPHA>
44 const ALPHA &
45 PruneVectorClosure<Vector>::updateScalingFactor(const ALPHA &alpha,
46 const Vector &)
47 {
48 return alpha;
49 }
50
51 template <typename Vector>
52 Transpose
53 PruneVectorClosure<Vector>::updateTranspose(Transpose trans)
54 {
55 return trans;
56 }
57
58 template <typename Vector>
59 const typename PruneVectorClosure<Vector>::Remainder &
60 PruneVectorClosure<Vector>::remainder(const Vector &vector)
61 {
62 return vector;
63 }
64
65 //-- Specialization for particular closures ------------------------------------
66 //-- Closure from alpha*A
67 template <typename L, typename R>
68 struct PruneVectorClosure<VectorClosure<OpMult, ScalarValue<L>, R> >
69 {
70 typedef VectorClosure<OpMult, ScalarValue<L>, R> VC;
71
72 typedef typename PruneVectorClosure<R>::ScalingFactor _ScalingFactor;
73 typedef typename Promotion<L, _ScalingFactor>::Type ScalingFactor;
74 typedef typename PruneVectorClosure<R>::Remainder Remainder;
75
76 template <typename ALPHA>
77 static const typename Promotion<ALPHA, ScalingFactor>::Type
78 updateScalingFactor(const ALPHA &alpha, const VC &vc)
79 {
80 typedef PruneVectorClosure<R> PVC;
81 return PVC::updateScalingFactor(alpha*vc.left().value(), vc.right());
82 }
83
84 static Transpose
85 updateTranspose(Transpose trans)
86 {
87 return PruneVectorClosure<R>::updateTranspose(trans);
88 }
89
90 static const Remainder &
91 remainder(const VC &vc)
92 {
93 return PruneVectorClosure<R>::remainder(vc.right());
94 }
95 };
96
97 //-- Closure from conj(A)
98 template <typename R>
99 struct PruneVectorClosure<VectorClosure<OpConj, R, R> >
100 {
101 typedef VectorClosure<OpConj, R, R> VC;
102
103 typedef typename PruneVectorClosure<R>::ScalingFactor ScalingFactor;
104 typedef typename PruneVectorClosure<R>::Remainder Remainder;
105
106 template <typename ALPHA>
107 static const typename Promotion<ALPHA, ScalingFactor>::Type
108 updateScalingFactor(const ALPHA &alpha, const VC &vc)
109 {
110 return PruneVectorClosure<R>::updateScalingFactor(alpha, vc.right());
111 }
112
113 static Transpose
114 updateTranspose(Transpose trans)
115 {
116 trans = PruneVectorClosure<R>::updateTranspose(trans);
117 return Transpose(trans^Conj);
118 }
119
120 static const Remainder &
121 remainder(const VC &vc)
122 {
123 return PruneVectorClosure<R>::remainder(vc.right());
124 }
125 };
126
127 } // namespace flens
128
129 #endif // FLENS_BLAS_CLOSURES_PRUNEVECTORCLOSURE_TCC
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_PRUNEVECTORCLOSURE_TCC
34 #define FLENS_BLAS_CLOSURES_PRUNEVECTORCLOSURE_TCC 1
35
36 #include <flens/typedefs.h>
37
38 namespace flens {
39
40 //-- General definition --------------------------------------------------------
41
42 template <typename Vector>
43 template <typename ALPHA>
44 const ALPHA &
45 PruneVectorClosure<Vector>::updateScalingFactor(const ALPHA &alpha,
46 const Vector &)
47 {
48 return alpha;
49 }
50
51 template <typename Vector>
52 Transpose
53 PruneVectorClosure<Vector>::updateTranspose(Transpose trans)
54 {
55 return trans;
56 }
57
58 template <typename Vector>
59 const typename PruneVectorClosure<Vector>::Remainder &
60 PruneVectorClosure<Vector>::remainder(const Vector &vector)
61 {
62 return vector;
63 }
64
65 //-- Specialization for particular closures ------------------------------------
66 //-- Closure from alpha*A
67 template <typename L, typename R>
68 struct PruneVectorClosure<VectorClosure<OpMult, ScalarValue<L>, R> >
69 {
70 typedef VectorClosure<OpMult, ScalarValue<L>, R> VC;
71
72 typedef typename PruneVectorClosure<R>::ScalingFactor _ScalingFactor;
73 typedef typename Promotion<L, _ScalingFactor>::Type ScalingFactor;
74 typedef typename PruneVectorClosure<R>::Remainder Remainder;
75
76 template <typename ALPHA>
77 static const typename Promotion<ALPHA, ScalingFactor>::Type
78 updateScalingFactor(const ALPHA &alpha, const VC &vc)
79 {
80 typedef PruneVectorClosure<R> PVC;
81 return PVC::updateScalingFactor(alpha*vc.left().value(), vc.right());
82 }
83
84 static Transpose
85 updateTranspose(Transpose trans)
86 {
87 return PruneVectorClosure<R>::updateTranspose(trans);
88 }
89
90 static const Remainder &
91 remainder(const VC &vc)
92 {
93 return PruneVectorClosure<R>::remainder(vc.right());
94 }
95 };
96
97 //-- Closure from conj(A)
98 template <typename R>
99 struct PruneVectorClosure<VectorClosure<OpConj, R, R> >
100 {
101 typedef VectorClosure<OpConj, R, R> VC;
102
103 typedef typename PruneVectorClosure<R>::ScalingFactor ScalingFactor;
104 typedef typename PruneVectorClosure<R>::Remainder Remainder;
105
106 template <typename ALPHA>
107 static const typename Promotion<ALPHA, ScalingFactor>::Type
108 updateScalingFactor(const ALPHA &alpha, const VC &vc)
109 {
110 return PruneVectorClosure<R>::updateScalingFactor(alpha, vc.right());
111 }
112
113 static Transpose
114 updateTranspose(Transpose trans)
115 {
116 trans = PruneVectorClosure<R>::updateTranspose(trans);
117 return Transpose(trans^Conj);
118 }
119
120 static const Remainder &
121 remainder(const VC &vc)
122 {
123 return PruneVectorClosure<R>::remainder(vc.right());
124 }
125 };
126
127 } // namespace flens
128
129 #endif // FLENS_BLAS_CLOSURES_PRUNEVECTORCLOSURE_TCC