1 /*
2 * Copyright (c) 2010, 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 CXXBLAS_LEVEL2_SYMV_TCC
34 #define CXXBLAS_LEVEL2_SYMV_TCC 1
35
36 #include <complex>
37 #include <cxxblas/level1/level1.h>
38
39 namespace cxxblas {
40
41 template <typename IndexType, typename ALPHA, typename MA, typename VX,
42 typename BETA, typename VY>
43 void
44 symv_generic(StorageOrder order, StorageUpLo upLo,
45 IndexType n,
46 const ALPHA &alpha,
47 const MA *A, IndexType ldA,
48 const VX *x, IndexType incX,
49 const BETA &beta,
50 VY *y, IndexType incY)
51 {
52 if (order==ColMajor) {
53 upLo = (upLo==Upper) ? Lower : Upper;
54 }
55 scal_generic(n, beta, y, incY);
56 if (upLo==Upper) {
57 for (IndexType i=0, iY=0; i<n; ++i, iY+=incY) {
58 VY _y = VY(0);
59 dotu_generic(n-i, A+i*ldA+i, IndexType(1), x+i*incX, incX, _y);
60 y[iY] += alpha*_y;
61 }
62 for (IndexType i=0, iY=0; i<n; ++i, iY+=incY) {
63 VY _y = VY(0);
64 dotu_generic(i, A+i, ldA, x, incX, _y);
65 y[iY] += alpha*_y;
66 }
67 } else {
68 for (IndexType i=0, iY=0; i<n; ++i, iY+=incY) {
69 VY _y = VY(0);
70 dotu_generic(i, A+i*ldA, IndexType(1), x, incX, _y);
71 y[iY] += alpha*_y;
72 }
73 for (IndexType i=0, iY=0; i<n; ++i, iY+=incY) {
74 VY _y = VY(0);
75 dotu_generic(n-i, A+i*ldA+i, ldA, x+i*incX, incX, _y);
76 y[iY] += alpha*_y;
77 }
78 }
79 }
80
81 //------------------------------------------------------------------------------
82
83 template <typename IndexType, typename ALPHA, typename MA, typename VX,
84 typename BETA, typename VY>
85 void
86 symv(StorageOrder order, StorageUpLo upLo,
87 IndexType n,
88 const ALPHA &alpha,
89 const MA *A, IndexType ldA,
90 const VX *x, IndexType incX,
91 const BETA &beta,
92 VY *y, IndexType incY)
93 {
94 CXXBLAS_DEBUG_OUT("symv_generic");
95
96 if (incX<0) {
97 x -= incX*(n-1);
98 }
99 if (incY<0) {
100 y -= incY*(n-1);
101 }
102 symv_generic(order, upLo, n, alpha, A, ldA, x, incX, beta, y, incY);
103 }
104
105 #ifdef HAVE_CBLAS
106
107 // ssymv
108 template <typename IndexType>
109 typename If<IndexType>::isBlasCompatibleInteger
110 symv(StorageOrder order, StorageUpLo upLo,
111 IndexType n, float alpha,
112 const float *A, IndexType ldA,
113 const float *x, IndexType incX,
114 float beta,
115 float *y, IndexType incY)
116 {
117 CXXBLAS_DEBUG_OUT("[" BLAS_IMPL "] cblas_ssymv");
118
119 cblas_ssymv(CBLAS::getCblasType(order), CBLAS::getCblasType(upLo),
120 n, alpha,
121 A, ldA,
122 x, incX,
123 beta,
124 y, incY);
125 }
126
127 // dsymv
128 template <typename IndexType>
129 typename If<IndexType>::isBlasCompatibleInteger
130 symv(StorageOrder order, StorageUpLo upLo,
131 IndexType n, double alpha,
132 const double *A, IndexType ldA,
133 const double *x, IndexType incX,
134 double beta,
135 double *y, IndexType incY)
136 {
137 CXXBLAS_DEBUG_OUT("[" BLAS_IMPL "] cblas_dsymv");
138
139 cblas_dsymv(CBLAS::getCblasType(order), CBLAS::getCblasType(upLo),
140 n, alpha,
141 A, ldA,
142 x, incX,
143 beta,
144 y, incY);
145 }
146
147 #endif // HAVE_CBLAS
148
149 } // namespace cxxblas
150
151 #endif // CXXBLAS_LEVEL2_SYMV_TCC
2 * Copyright (c) 2010, 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 CXXBLAS_LEVEL2_SYMV_TCC
34 #define CXXBLAS_LEVEL2_SYMV_TCC 1
35
36 #include <complex>
37 #include <cxxblas/level1/level1.h>
38
39 namespace cxxblas {
40
41 template <typename IndexType, typename ALPHA, typename MA, typename VX,
42 typename BETA, typename VY>
43 void
44 symv_generic(StorageOrder order, StorageUpLo upLo,
45 IndexType n,
46 const ALPHA &alpha,
47 const MA *A, IndexType ldA,
48 const VX *x, IndexType incX,
49 const BETA &beta,
50 VY *y, IndexType incY)
51 {
52 if (order==ColMajor) {
53 upLo = (upLo==Upper) ? Lower : Upper;
54 }
55 scal_generic(n, beta, y, incY);
56 if (upLo==Upper) {
57 for (IndexType i=0, iY=0; i<n; ++i, iY+=incY) {
58 VY _y = VY(0);
59 dotu_generic(n-i, A+i*ldA+i, IndexType(1), x+i*incX, incX, _y);
60 y[iY] += alpha*_y;
61 }
62 for (IndexType i=0, iY=0; i<n; ++i, iY+=incY) {
63 VY _y = VY(0);
64 dotu_generic(i, A+i, ldA, x, incX, _y);
65 y[iY] += alpha*_y;
66 }
67 } else {
68 for (IndexType i=0, iY=0; i<n; ++i, iY+=incY) {
69 VY _y = VY(0);
70 dotu_generic(i, A+i*ldA, IndexType(1), x, incX, _y);
71 y[iY] += alpha*_y;
72 }
73 for (IndexType i=0, iY=0; i<n; ++i, iY+=incY) {
74 VY _y = VY(0);
75 dotu_generic(n-i, A+i*ldA+i, ldA, x+i*incX, incX, _y);
76 y[iY] += alpha*_y;
77 }
78 }
79 }
80
81 //------------------------------------------------------------------------------
82
83 template <typename IndexType, typename ALPHA, typename MA, typename VX,
84 typename BETA, typename VY>
85 void
86 symv(StorageOrder order, StorageUpLo upLo,
87 IndexType n,
88 const ALPHA &alpha,
89 const MA *A, IndexType ldA,
90 const VX *x, IndexType incX,
91 const BETA &beta,
92 VY *y, IndexType incY)
93 {
94 CXXBLAS_DEBUG_OUT("symv_generic");
95
96 if (incX<0) {
97 x -= incX*(n-1);
98 }
99 if (incY<0) {
100 y -= incY*(n-1);
101 }
102 symv_generic(order, upLo, n, alpha, A, ldA, x, incX, beta, y, incY);
103 }
104
105 #ifdef HAVE_CBLAS
106
107 // ssymv
108 template <typename IndexType>
109 typename If<IndexType>::isBlasCompatibleInteger
110 symv(StorageOrder order, StorageUpLo upLo,
111 IndexType n, float alpha,
112 const float *A, IndexType ldA,
113 const float *x, IndexType incX,
114 float beta,
115 float *y, IndexType incY)
116 {
117 CXXBLAS_DEBUG_OUT("[" BLAS_IMPL "] cblas_ssymv");
118
119 cblas_ssymv(CBLAS::getCblasType(order), CBLAS::getCblasType(upLo),
120 n, alpha,
121 A, ldA,
122 x, incX,
123 beta,
124 y, incY);
125 }
126
127 // dsymv
128 template <typename IndexType>
129 typename If<IndexType>::isBlasCompatibleInteger
130 symv(StorageOrder order, StorageUpLo upLo,
131 IndexType n, double alpha,
132 const double *A, IndexType ldA,
133 const double *x, IndexType incX,
134 double beta,
135 double *y, IndexType incY)
136 {
137 CXXBLAS_DEBUG_OUT("[" BLAS_IMPL "] cblas_dsymv");
138
139 cblas_dsymv(CBLAS::getCblasType(order), CBLAS::getCblasType(upLo),
140 n, alpha,
141 A, ldA,
142 x, incX,
143 beta,
144 y, incY);
145 }
146
147 #endif // HAVE_CBLAS
148
149 } // namespace cxxblas
150
151 #endif // CXXBLAS_LEVEL2_SYMV_TCC