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_OPERATORS_OPMULT_H
34 #define FLENS_BLAS_OPERATORS_OPMULT_H 1
35
36 #include <flens/aux/isconvertible.h>
37 #include <flens/aux/restrictto.h>
38 #include <flens/matrixtypes/matrixtypes.h>
39 #include <flens/scalartypes/scalartypes.h>
40 #include <flens/vectortypes/vectortypes.h>
41
42 namespace flens {
43
44 struct OpMult {};
45
46 //-- vector-vector products ----------------------------------------------------
47 // x'*y
48 template <typename VX, typename VY>
49 typename Promotion<typename VX::Impl::ElementType,
50 typename VY::Impl::ElementType>::Type
51 operator*(const Vector<VX> &x, const Vector<VY> &y);
52
53 //-- scalar-vector products ----------------------------------------------------
54 // alpha*x
55 template <typename ALPHA, typename V>
56 const typename RestrictTo<
57 IsConvertible<ALPHA, typename V::Impl::ElementType>::value ||
58 IsConvertible<typename V::Impl::ElementType, ALPHA>::value,
59 VectorClosure<OpMult, ScalarValue<ALPHA>, typename V::Impl>
60 >::Type
61 operator*(const ALPHA &alpha, const Vector<V> &x);
62
63 // x*alpha
64 template <typename ALPHA, typename V>
65 const typename RestrictTo<
66 IsConvertible<ALPHA, typename V::Impl::ElementType>::value
67 || IsConvertible<typename V::Impl::ElementType, ALPHA>::value,
68 VectorClosure<OpMult, ScalarValue<ALPHA>, typename V::Impl>
69 >::Type
70 operator*(const Vector<V> &x, const ALPHA &alpha);
71
72 //-- scalar-matrix products ----------------------------------------------------
73 // alpha*A
74 template <typename ALPHA, typename M>
75 const typename RestrictTo<
76 IsConvertible<ALPHA, typename M::Impl::ElementType>::value ||
77 IsConvertible<typename M::Impl::ElementType, ALPHA>::value,
78 MatrixClosure<OpMult, ScalarValue<ALPHA>, typename M::Impl>
79 >::Type
80 operator*(const ALPHA &alpha, const Matrix<M> &A);
81
82 // A*alpha
83 template <typename ALPHA, typename M>
84 const typename RestrictTo<
85 IsConvertible<ALPHA, typename M::Impl::ElementType>::value ||
86 IsConvertible<typename M::Impl::ElementType, ALPHA>::value,
87 MatrixClosure<OpMult, ScalarValue<ALPHA>, typename M::Impl>
88 >::Type
89 operator*(const Matrix<M> &A, const ALPHA &alpha);
90
91 //-- matrix-vector products ----------------------------------------------------
92 // A*x
93 template <typename M, typename V>
94 const VectorClosure<OpMult,
95 typename M::Impl,
96 typename V::Impl>
97 operator*(const Matrix<M> &A, const Vector<V> &x);
98
99 // x*A
100 template <typename M, typename V>
101 const VectorClosure<OpMult,
102 typename V::Impl,
103 typename M::Impl>
104 operator*(const Vector<V> &x, const Matrix<M> &A);
105
106 //-- matrix-matrix products ----------------------------------------------------
107 // A*B
108 template <typename MA, typename MB>
109 const MatrixClosure<OpMult,
110 typename MA::Impl,
111 typename MB::Impl>
112 operator*(const Matrix<MA> &A, const Matrix<MB> &B);
113
114 } // namespace flens
115
116 #endif // FLENS_BLAS_OPERATORS_OPMULT_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_OPERATORS_OPMULT_H
34 #define FLENS_BLAS_OPERATORS_OPMULT_H 1
35
36 #include <flens/aux/isconvertible.h>
37 #include <flens/aux/restrictto.h>
38 #include <flens/matrixtypes/matrixtypes.h>
39 #include <flens/scalartypes/scalartypes.h>
40 #include <flens/vectortypes/vectortypes.h>
41
42 namespace flens {
43
44 struct OpMult {};
45
46 //-- vector-vector products ----------------------------------------------------
47 // x'*y
48 template <typename VX, typename VY>
49 typename Promotion<typename VX::Impl::ElementType,
50 typename VY::Impl::ElementType>::Type
51 operator*(const Vector<VX> &x, const Vector<VY> &y);
52
53 //-- scalar-vector products ----------------------------------------------------
54 // alpha*x
55 template <typename ALPHA, typename V>
56 const typename RestrictTo<
57 IsConvertible<ALPHA, typename V::Impl::ElementType>::value ||
58 IsConvertible<typename V::Impl::ElementType, ALPHA>::value,
59 VectorClosure<OpMult, ScalarValue<ALPHA>, typename V::Impl>
60 >::Type
61 operator*(const ALPHA &alpha, const Vector<V> &x);
62
63 // x*alpha
64 template <typename ALPHA, typename V>
65 const typename RestrictTo<
66 IsConvertible<ALPHA, typename V::Impl::ElementType>::value
67 || IsConvertible<typename V::Impl::ElementType, ALPHA>::value,
68 VectorClosure<OpMult, ScalarValue<ALPHA>, typename V::Impl>
69 >::Type
70 operator*(const Vector<V> &x, const ALPHA &alpha);
71
72 //-- scalar-matrix products ----------------------------------------------------
73 // alpha*A
74 template <typename ALPHA, typename M>
75 const typename RestrictTo<
76 IsConvertible<ALPHA, typename M::Impl::ElementType>::value ||
77 IsConvertible<typename M::Impl::ElementType, ALPHA>::value,
78 MatrixClosure<OpMult, ScalarValue<ALPHA>, typename M::Impl>
79 >::Type
80 operator*(const ALPHA &alpha, const Matrix<M> &A);
81
82 // A*alpha
83 template <typename ALPHA, typename M>
84 const typename RestrictTo<
85 IsConvertible<ALPHA, typename M::Impl::ElementType>::value ||
86 IsConvertible<typename M::Impl::ElementType, ALPHA>::value,
87 MatrixClosure<OpMult, ScalarValue<ALPHA>, typename M::Impl>
88 >::Type
89 operator*(const Matrix<M> &A, const ALPHA &alpha);
90
91 //-- matrix-vector products ----------------------------------------------------
92 // A*x
93 template <typename M, typename V>
94 const VectorClosure<OpMult,
95 typename M::Impl,
96 typename V::Impl>
97 operator*(const Matrix<M> &A, const Vector<V> &x);
98
99 // x*A
100 template <typename M, typename V>
101 const VectorClosure<OpMult,
102 typename V::Impl,
103 typename M::Impl>
104 operator*(const Vector<V> &x, const Matrix<M> &A);
105
106 //-- matrix-matrix products ----------------------------------------------------
107 // A*B
108 template <typename MA, typename MB>
109 const MatrixClosure<OpMult,
110 typename MA::Impl,
111 typename MB::Impl>
112 operator*(const Matrix<MA> &A, const Matrix<MB> &B);
113
114 } // namespace flens
115
116 #endif // FLENS_BLAS_OPERATORS_OPMULT_H