1 /*
2 * Copyright (c) 2012, 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_MMSWITCH_H
34 #define FLENS_BLAS_CLOSURES_MMSWITCH_H 1
35
36 #include <flens/aux/aux.h>
37 #include <flens/matrixtypes/matrixtypes.h>
38 #include <flens/scalartypes/scalartypes.h>
39 #include <flens/typedefs.h>
40
41 namespace flens { namespace blas {
42
43 //
44 // This switch evaluates closures of the form
45 //
46 // C = beta*C + A*B
47 //
48 // If B is a closure then it gets evaluated and a temporary gets created to
49 // store the result. For matrix A we distinguish between three cases:
50 // case 1: A is no closure
51 // case 2: A is a scaling closure (i.e. scale*A)
52 // case 3: A is some other closure
53
54 //
55 // Entry point for mmSwitch
56 //
57 template <typename ALPHA, typename MA, typename MB, typename BETA, typename MC>
58 typename RestrictTo<IsSame<MA, typename MA::Impl>::value &&
59 IsSame<MB, typename MB::Impl>::value &&
60 IsSame<MC, typename MC::Impl>::value,
61 void>::Type
62 mmSwitch(Transpose transA, Transpose transB, const ALPHA &alpha,
63 const MA &A, const MB &B, const BETA &beta, MC &C);
64
65 //
66 // case 1: A is no closure
67 //
68 template <typename ALPHA, typename MA, typename MB, typename BETA, typename MC>
69 typename RestrictTo<!IsClosure<MA>::value,
70 void>::Type
71 mmCase(Transpose transA, Transpose transB, const ALPHA &alpha,
72 const MA &A, const MB &B, const BETA &beta, MC &C);
73
74 //
75 // case 2: A is closure of type scale*A
76 //
77 template <typename ALPHA, typename T, typename MA, typename MB, typename BETA,
78 typename MC>
79 void
80 mmCase(Transpose transA, Transpose transB, const ALPHA &alpha,
81 const MatrixClosure<OpMult, ScalarValue<T>, MA> &scale_A,
82 const MB &B, const BETA &beta, MC &C);
83
84 //
85 // case 3: A is some other closure
86 //
87 template <typename ALPHA, typename Op, typename L, typename R, typename MB,
88 typename BETA, typename MC>
89 void
90 mmCase(Transpose transA, Transpose transB, const ALPHA &alpha,
91 const MatrixClosure<Op, L, R> &A, const MB &B,
92 const BETA &beta, MC &C);
93
94 } } // namespace blas, flens
95
96 #endif // FLENS_BLAS_CLOSURES_MMSWITCH_H
2 * Copyright (c) 2012, 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_MMSWITCH_H
34 #define FLENS_BLAS_CLOSURES_MMSWITCH_H 1
35
36 #include <flens/aux/aux.h>
37 #include <flens/matrixtypes/matrixtypes.h>
38 #include <flens/scalartypes/scalartypes.h>
39 #include <flens/typedefs.h>
40
41 namespace flens { namespace blas {
42
43 //
44 // This switch evaluates closures of the form
45 //
46 // C = beta*C + A*B
47 //
48 // If B is a closure then it gets evaluated and a temporary gets created to
49 // store the result. For matrix A we distinguish between three cases:
50 // case 1: A is no closure
51 // case 2: A is a scaling closure (i.e. scale*A)
52 // case 3: A is some other closure
53
54 //
55 // Entry point for mmSwitch
56 //
57 template <typename ALPHA, typename MA, typename MB, typename BETA, typename MC>
58 typename RestrictTo<IsSame<MA, typename MA::Impl>::value &&
59 IsSame<MB, typename MB::Impl>::value &&
60 IsSame<MC, typename MC::Impl>::value,
61 void>::Type
62 mmSwitch(Transpose transA, Transpose transB, const ALPHA &alpha,
63 const MA &A, const MB &B, const BETA &beta, MC &C);
64
65 //
66 // case 1: A is no closure
67 //
68 template <typename ALPHA, typename MA, typename MB, typename BETA, typename MC>
69 typename RestrictTo<!IsClosure<MA>::value,
70 void>::Type
71 mmCase(Transpose transA, Transpose transB, const ALPHA &alpha,
72 const MA &A, const MB &B, const BETA &beta, MC &C);
73
74 //
75 // case 2: A is closure of type scale*A
76 //
77 template <typename ALPHA, typename T, typename MA, typename MB, typename BETA,
78 typename MC>
79 void
80 mmCase(Transpose transA, Transpose transB, const ALPHA &alpha,
81 const MatrixClosure<OpMult, ScalarValue<T>, MA> &scale_A,
82 const MB &B, const BETA &beta, MC &C);
83
84 //
85 // case 3: A is some other closure
86 //
87 template <typename ALPHA, typename Op, typename L, typename R, typename MB,
88 typename BETA, typename MC>
89 void
90 mmCase(Transpose transA, Transpose transB, const ALPHA &alpha,
91 const MatrixClosure<Op, L, R> &A, const MB &B,
92 const BETA &beta, MC &C);
93
94 } } // namespace blas, flens
95
96 #endif // FLENS_BLAS_CLOSURES_MMSWITCH_H