1 /*
2 * Copyright (c) 2007, 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_COPY_H
34 #define FLENS_BLAS_CLOSURES_COPY_H 1
35
36 #include <cxxblas/typedefs.h>
37
38 #include <flens/blas/closures/closuretype.h>
39 #include <flens/blas/operators/operators.h>
40 #include <flens/matrixtypes/matrixtypes.h>
41 #include <flens/typedefs.h>
42 #include <flens/vectortypes/vectortypes.h>
43
44 namespace flens { namespace blas {
45
46 //-- vector closures -----------------------------------------------------------
47 // y = x1 + x2
48 template <typename VL, typename VR, typename VY>
49 typename RestrictTo<!ClosureType<OpAdd, VL, VR>::isMatrixVectorProduct,
50 void>::Type
51 copy(const VectorClosure<OpAdd, VL, VR> &x, Vector<VY> &y);
52
53 // y = x1 - x2
54 template <typename VL, typename VR, typename VY>
55 typename RestrictTo<!ClosureType<OpSub, VL, VR>::isResidual,
56 void>::Type
57 copy(const VectorClosure<OpSub, VL, VR> &x, Vector<VY> &y);
58
59 // y = alpha*x
60 template <typename T, typename VX, typename VY>
61 void
62 copy(const VectorClosure<OpMult, ScalarValue<T>, VX> &x, Vector<VY> &y);
63
64 // y = x/alpha
65 template <typename VX, typename T, typename VY>
66 void
67 copy(const VectorClosure<OpDiv, VX, ScalarValue<T> > &x, Vector<VY> &y);
68
69 // y = conjugate(x)
70 template <typename VX, typename VY>
71 void
72 copy(const VectorClosureOpConj<VX> &x, Vector<VY> &y);
73
74 // y = beta*y + alpha*op(A)*x
75 template <typename VL, typename MVR, typename VY>
76 typename RestrictTo<ClosureType<OpAdd, VL, MVR>::isMatrixVectorProduct,
77 void>::Type
78 copy(const VectorClosure<OpAdd, VL, MVR> &ypAx, Vector<VY> &y);
79
80 // y = A*x
81 template <typename ML, typename VR, typename VY>
82 typename RestrictTo<ClosureType<OpMult, ML, VR>::isMatrixVectorProduct,
83 void>::Type
84 copy(const VectorClosure<OpMult, ML, VR> &Ax, Vector<VY> &y);
85
86 // y = x*A
87 template <typename VL, typename MR, typename VY>
88 typename RestrictTo<ClosureType<OpMult, VL, MR>::isVectorMatrixProduct,
89 void>::Type
90 copy(const VectorClosure<OpMult, VL, MR> &xA, Vector<VY> &y);
91
92 // y = b - A*x
93 template <typename L, typename R, typename VY>
94 typename RestrictTo<ClosureType<OpSub, L, R>::isResidual,
95 void>::Type
96 copy(const VectorClosure<OpSub, L, R> &bmAx, Vector<VY> &y);
97
98 // y = <Unknown Closure>
99 template <typename Op, typename VL, typename VR, typename VY>
100 void
101 copy(const VectorClosure<Op, VL, VR> &x, Vector<VY> &y);
102
103 //-- matrix closures -----------------------------------------------------------
104 //
105 // In the following comments op(X) denotes x, X^T or X^H
106 //
107
108 // B = op(A1 + A2)
109 template <typename ML, typename MR, typename MB>
110 typename RestrictTo<!ClosureType<OpAdd, ML, MR>::isMatrixMatrixProduct,
111 void>::Type
112 copy(Transpose trans, const MatrixClosure<OpAdd, ML, MR> &A, Matrix<MB> &B);
113
114 // B = op(A1 - A2)
115 template <typename ML, typename MR, typename MB>
116 void
117 copy(Transpose trans, const MatrixClosure<OpSub, ML, MR> &A, Matrix<MB> &B);
118
119 // B = alpha*op(A)
120 template <typename T, typename MA, typename MB>
121 void
122 copy(Transpose trans,
123 const MatrixClosure<OpMult, ScalarValue<T>, MA> &A, Matrix<MB> &B);
124
125 // B = op(A)/alpha
126 template <typename MA, typename T, typename MB>
127 void
128 copy(Transpose trans,
129 const MatrixClosure<OpDiv, MA, ScalarValue<T> > &A, Matrix<MB> &B);
130
131 // B = op(A^T)
132 template <typename MA, typename MB>
133 void
134 copy(Transpose trans, const MatrixClosureOpTrans<MA> &A, Matrix<MB> &B);
135
136 // C = beta*C + A*B
137 template <typename ML, typename MR, typename MC>
138 typename RestrictTo<ClosureType<OpAdd, ML, MR>::isMatrixMatrixProduct,
139 void>::Type
140 copy(Transpose trans, const MatrixClosure<OpAdd, ML, MR> &CPAB,
141 Matrix<MC> &C);
142
143 // C = A*B
144 template <typename MA, typename MB, typename MC>
145 typename RestrictTo<ClosureType<OpMult, MA, MB>::isMatrixMatrixProduct,
146 void>::Type
147 copy(Transpose trans, const MatrixClosure<OpMult,MA,MB> &AB, Matrix<MC> &C);
148
149 // B = <Unknown Closure>
150 template <typename Op, typename ML, typename MR, typename MB>
151 void
152 copy(Transpose trans, const MatrixClosure<Op, ML, MR> &A, Matrix<MB> &B);
153
154 //-- symmetric matrices --------------------------------------------------------
155 //
156 // We just trans is NoTrans or Trans we simply ignore it
157 //
158 template <typename MA, typename MB>
159 void
160 copy(Transpose trans, const SymmetricMatrix<MA> &A, Matrix<MB> &B);
161
162 template <typename MA, typename MB>
163 typename RestrictTo<!IsSymmetricMatrix<MA>::value,
164 void>::Type
165 copy(Transpose trans, const Matrix<MA> &A, SymmetricMatrix<MB> &B);
166
167 } } // namespace blas, flens
168
169 #endif // FLENS_BLAS_CLOSURES_COPY_H
2 * Copyright (c) 2007, 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_COPY_H
34 #define FLENS_BLAS_CLOSURES_COPY_H 1
35
36 #include <cxxblas/typedefs.h>
37
38 #include <flens/blas/closures/closuretype.h>
39 #include <flens/blas/operators/operators.h>
40 #include <flens/matrixtypes/matrixtypes.h>
41 #include <flens/typedefs.h>
42 #include <flens/vectortypes/vectortypes.h>
43
44 namespace flens { namespace blas {
45
46 //-- vector closures -----------------------------------------------------------
47 // y = x1 + x2
48 template <typename VL, typename VR, typename VY>
49 typename RestrictTo<!ClosureType<OpAdd, VL, VR>::isMatrixVectorProduct,
50 void>::Type
51 copy(const VectorClosure<OpAdd, VL, VR> &x, Vector<VY> &y);
52
53 // y = x1 - x2
54 template <typename VL, typename VR, typename VY>
55 typename RestrictTo<!ClosureType<OpSub, VL, VR>::isResidual,
56 void>::Type
57 copy(const VectorClosure<OpSub, VL, VR> &x, Vector<VY> &y);
58
59 // y = alpha*x
60 template <typename T, typename VX, typename VY>
61 void
62 copy(const VectorClosure<OpMult, ScalarValue<T>, VX> &x, Vector<VY> &y);
63
64 // y = x/alpha
65 template <typename VX, typename T, typename VY>
66 void
67 copy(const VectorClosure<OpDiv, VX, ScalarValue<T> > &x, Vector<VY> &y);
68
69 // y = conjugate(x)
70 template <typename VX, typename VY>
71 void
72 copy(const VectorClosureOpConj<VX> &x, Vector<VY> &y);
73
74 // y = beta*y + alpha*op(A)*x
75 template <typename VL, typename MVR, typename VY>
76 typename RestrictTo<ClosureType<OpAdd, VL, MVR>::isMatrixVectorProduct,
77 void>::Type
78 copy(const VectorClosure<OpAdd, VL, MVR> &ypAx, Vector<VY> &y);
79
80 // y = A*x
81 template <typename ML, typename VR, typename VY>
82 typename RestrictTo<ClosureType<OpMult, ML, VR>::isMatrixVectorProduct,
83 void>::Type
84 copy(const VectorClosure<OpMult, ML, VR> &Ax, Vector<VY> &y);
85
86 // y = x*A
87 template <typename VL, typename MR, typename VY>
88 typename RestrictTo<ClosureType<OpMult, VL, MR>::isVectorMatrixProduct,
89 void>::Type
90 copy(const VectorClosure<OpMult, VL, MR> &xA, Vector<VY> &y);
91
92 // y = b - A*x
93 template <typename L, typename R, typename VY>
94 typename RestrictTo<ClosureType<OpSub, L, R>::isResidual,
95 void>::Type
96 copy(const VectorClosure<OpSub, L, R> &bmAx, Vector<VY> &y);
97
98 // y = <Unknown Closure>
99 template <typename Op, typename VL, typename VR, typename VY>
100 void
101 copy(const VectorClosure<Op, VL, VR> &x, Vector<VY> &y);
102
103 //-- matrix closures -----------------------------------------------------------
104 //
105 // In the following comments op(X) denotes x, X^T or X^H
106 //
107
108 // B = op(A1 + A2)
109 template <typename ML, typename MR, typename MB>
110 typename RestrictTo<!ClosureType<OpAdd, ML, MR>::isMatrixMatrixProduct,
111 void>::Type
112 copy(Transpose trans, const MatrixClosure<OpAdd, ML, MR> &A, Matrix<MB> &B);
113
114 // B = op(A1 - A2)
115 template <typename ML, typename MR, typename MB>
116 void
117 copy(Transpose trans, const MatrixClosure<OpSub, ML, MR> &A, Matrix<MB> &B);
118
119 // B = alpha*op(A)
120 template <typename T, typename MA, typename MB>
121 void
122 copy(Transpose trans,
123 const MatrixClosure<OpMult, ScalarValue<T>, MA> &A, Matrix<MB> &B);
124
125 // B = op(A)/alpha
126 template <typename MA, typename T, typename MB>
127 void
128 copy(Transpose trans,
129 const MatrixClosure<OpDiv, MA, ScalarValue<T> > &A, Matrix<MB> &B);
130
131 // B = op(A^T)
132 template <typename MA, typename MB>
133 void
134 copy(Transpose trans, const MatrixClosureOpTrans<MA> &A, Matrix<MB> &B);
135
136 // C = beta*C + A*B
137 template <typename ML, typename MR, typename MC>
138 typename RestrictTo<ClosureType<OpAdd, ML, MR>::isMatrixMatrixProduct,
139 void>::Type
140 copy(Transpose trans, const MatrixClosure<OpAdd, ML, MR> &CPAB,
141 Matrix<MC> &C);
142
143 // C = A*B
144 template <typename MA, typename MB, typename MC>
145 typename RestrictTo<ClosureType<OpMult, MA, MB>::isMatrixMatrixProduct,
146 void>::Type
147 copy(Transpose trans, const MatrixClosure<OpMult,MA,MB> &AB, Matrix<MC> &C);
148
149 // B = <Unknown Closure>
150 template <typename Op, typename ML, typename MR, typename MB>
151 void
152 copy(Transpose trans, const MatrixClosure<Op, ML, MR> &A, Matrix<MB> &B);
153
154 //-- symmetric matrices --------------------------------------------------------
155 //
156 // We just trans is NoTrans or Trans we simply ignore it
157 //
158 template <typename MA, typename MB>
159 void
160 copy(Transpose trans, const SymmetricMatrix<MA> &A, Matrix<MB> &B);
161
162 template <typename MA, typename MB>
163 typename RestrictTo<!IsSymmetricMatrix<MA>::value,
164 void>::Type
165 copy(Transpose trans, const Matrix<MA> &A, SymmetricMatrix<MB> &B);
166
167 } } // namespace blas, flens
168
169 #endif // FLENS_BLAS_CLOSURES_COPY_H