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_MVSWITCH_H
34 #define FLENS_BLAS_CLOSURES_MVSWITCH_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 //      y = beta*y + A*x
47 //
48 //  If x 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 mvSwitch
56 //
57 template <typename ALPHA, typename MA, typename VX, typename BETA, typename VY>
58     typename RestrictTo<IsSame<MA, typename MA::Impl>::value &&
59                         IsSame<VX, typename VX::Impl>::value &&
60                         IsSame<VY, typename VY::Impl>::value,
61              void>::Type
62     mvSwitch(Transpose trans, const ALPHA &alpha, const MA &A, const VX &x,
63              const BETA &beta, VY &y);
64 
65 //
66 //  case 1: A is no closure
67 //
68 template <typename ALPHA, typename MA, typename VX, typename BETA, typename VY>
69     typename RestrictTo<!IsClosure<MA>::value,
70              void>::Type
71     mvCase(Transpose trans, const ALPHA &alpha, const MA &A, const VX &x,
72            const BETA &beta, VY &y);
73 
74 //
75 //  case 2: A is closure of type scale*A
76 //
77 template <typename ALPHA, typename T, typename MA, typename VX, typename BETA,
78           typename VY>
79     void
80     mvCase(Transpose trans, const ALPHA &alpha,
81            const MatrixClosure<OpMult, ScalarValue<T>, MA> &scale_A,
82            const VX &x, const BETA &beta, VY &y);
83 
84 //
85 //  case 3: A is some other closure
86 //
87 template <typename ALPHA, typename Op, typename L, typename R, typename VX,
88           typename BETA, typename VY>
89     void
90     mvCase(Transpose trans, const ALPHA &alpha,
91            const MatrixClosure<Op, L, R> &A,
92            const VX &x, const BETA &beta, VY &y);
93 
94 } } // namespace blas, flens
95 
96 #endif // FLENS_BLAS_CLOSURES_MVSWITCH_H