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_AXPY_H
 34 #define FLENS_BLAS_CLOSURES_AXPY_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 ALPHA, typename VL, typename VR, typename VY>
 49     void
 50     axpy(const ALPHA &alpha,
 51          const VectorClosure<OpAdd, VL, VR> &x, Vector<VY> &y);
 52 
 53 // y += x1 - x2
 54 template <typename ALPHA, typename VL, typename VR, typename VY>
 55     void
 56     axpy(const ALPHA &alpha,
 57          const VectorClosure<OpSub, VL, VR> &x, Vector<VY> &y);
 58 
 59 // y += scalar*x
 60 template <typename ALPHA, typename T, typename VX, typename VY>
 61     void
 62     axpy(const ALPHA &alpha,
 63          const VectorClosure<OpMult, ScalarValue<T>, VX> &x, Vector<VY> &y);
 64 
 65 // y += x/scalar
 66 template <typename ALPHA, typename VX, typename T, typename VY>
 67     void
 68     axpy(const ALPHA &alpha,
 69          const VectorClosure<OpDiv, VX, ScalarValue<T> > &x, Vector<VY> &y);
 70 
 71 // y += A*x
 72 template <typename ALPHA, typename ML, typename VR, typename VY>
 73     typename RestrictTo<ClosureType<OpMult, ML, VR>::isMatrixVectorProduct,
 74              void>::Type
 75     axpy(const ALPHA &alpha,
 76          const VectorClosure<OpMult, ML, VR> &Ax, Vector<VY> &y);
 77 
 78 // y += x*A
 79 template <typename ALPHA, typename VL, typename MR, typename VY>
 80     typename RestrictTo<ClosureType<OpMult, VL, MR>::isVectorMatrixProduct,
 81              void>::Type
 82     axpy(const ALPHA &alpha,
 83          const VectorClosure<OpMult, VL, MR> &xA, Vector<VY> &y);
 84 
 85 // y += <Unknown Closure>
 86 template <typename ALPHA, typename Op, typename VL, typename VR, typename VY>
 87     void
 88     axpy(const ALPHA &alpha,
 89          const VectorClosure<Op, VL, VR> &x, Vector<VY> &y);
 90 
 91 //-- matrix closures -----------------------------------------------------------
 92 //
 93 //  In the following comments op(X) denotes  x, X^T or X^H
 94 //
 95 
 96 //  B += alpha*op(A1 + A2)
 97 template <typename ALPHA, typename ML, typename MR, typename MB>
 98     void
 99     axpy(Transpose trans, const ALPHA &alpha,
100          const MatrixClosure<OpAdd, ML, MR> &A, Matrix<MB> &B);
101 
102 //  B += alpha*op(A1 - A2)
103 template <typename ALPHA, typename ML, typename MR, typename MB>
104     void
105     axpy(Transpose trans, const ALPHA &alpha,
106          const MatrixClosure<OpSub, ML, MR> &A, Matrix<MB> &B);
107 
108 //  B += scalar*op(A)
109 template <typename ALPHA, typename T, typename MA, typename MB>
110     void
111     axpy(Transpose trans, const ALPHA &alpha,
112          const MatrixClosure<OpMult, ScalarValue<T>, MA> &A, Matrix<MB> &B);
113 
114 //  B += op(A)/scalar
115 template <typename ALPHA, typename MA, typename T, typename MB>
116     void
117     axpy(Transpose trans, const ALPHA &alpha,
118          const MatrixClosure<OpDiv, MA, ScalarValue<T> > &A, Matrix<MB> &B);
119 
120 //  B += op(A^T)
121 template <typename ALPHA, typename MA, typename MB>
122     void
123     axpy(Transpose trans, const ALPHA &alpha,
124          const MatrixClosureOpTrans<MA> &A, Matrix<MB> &B);
125 
126 //  C += A*B
127 template <typename ALPHA, typename MA, typename MB, typename MC>
128     typename RestrictTo<ClosureType<OpMult, MA, MB>::isMatrixMatrixProduct,
129              void>::Type
130     axpy(Transpose trans, const ALPHA &alpha,
131          const MatrixClosure<OpMult,MA,MB> &AB, Matrix<MC> &C);
132 
133 // B += <Unknown Closure>
134 template <typename ALPHA, typename Op, typename ML, typename MR, typename MB>
135     void
136     axpy(Transpose trans, const ALPHA &alpha,
137          const MatrixClosure<Op, ML, MR> &A, Matrix<MB> &B);
138 
139 #ifdef FLENS_DEBUG_CLOSURES
140 // B += Some Matrix
141 template <typename ALPHA, typename MA, typename MB>
142     void
143     axpy(Transpose trans, const ALPHA &alpha,
144          const Matrix<MA> &A, Matrix<MB> &B);
145 #endif
146 
147 } } // namespace blas, flens
148 
149 #endif // FLENS_BLAS_CLOSURES_AXPY_H