IT++ Logo
copy_vector.cpp
Go to the documentation of this file.
1 
29 #include <itpp/base/copy_vector.h>
30 
31 #ifndef _MSC_VER
32 # include <itpp/config.h>
33 #else
34 # include <itpp/config_msvc.h>
35 #endif
36 
37 #if defined (HAVE_BLAS)
38 # include <itpp/base/blas.h>
39 #endif
40 
41 
42 namespace itpp
43 {
44 
45 #if defined (HAVE_BLAS)
46 void copy_vector(int n, const double *x, double *y)
47 {
48  int incr = 1;
49  blas::dcopy_(&n, x, &incr, y, &incr);
50 }
51 void copy_vector(int n, const std::complex<double> *x, std::complex<double> *y)
52 {
53  int incr = 1;
54  blas::zcopy_(&n, x, &incr, y, &incr);
55 }
56 #else
57 void copy_vector(int n, const double *x, double *y)
58 {
59  memcpy(y, x, static_cast<unsigned int>(n) * sizeof(double));
60 }
61 void copy_vector(int n, const std::complex<double> *x, std::complex<double> *y)
62 {
63  memcpy(y, x, static_cast<unsigned int>(n) * sizeof(std::complex<double>));
64 }
65 #endif
66 
67 
68 #if defined (HAVE_BLAS)
69 void copy_vector(int n, const double *x, int incx, double *y, int incy)
70 {
71  blas::dcopy_(&n, x, &incx, y, &incy);
72 }
73 void copy_vector(int n, const std::complex<double> *x, int incx,
74  std::complex<double> *y, int incy)
75 {
76  blas::zcopy_(&n, x, &incx, y, &incy);
77 }
78 #else
79 void copy_vector(int n, const double *x, int incx, double *y, int incy)
80 {
81  for (int i = 0; i < n; i++)
82  y[i*incy] = x[i*incx];
83 }
84 void copy_vector(int n, const std::complex<double> *x, int incx,
85  std::complex<double> *y, int incy)
86 {
87  for (int i = 0; i < n; i++)
88  y[i*incy] = x[i*incx];
89 }
90 #endif
91 
92 
93 #if defined (HAVE_BLAS)
94 void swap_vector(int n, double *x, double *y)
95 {
96  int incr = 1;
97  blas::dswap_(&n, x, &incr, y, &incr);
98 }
99 void swap_vector(int n, std::complex<double> *x, std::complex<double> *y)
100 {
101  int incr = 1;
102  blas::zswap_(&n, x, &incr, y, &incr);
103 }
104 #else
105 void swap_vector(int n, double *x, double *y)
106 {
107  for (int i = 0; i < n; i++)
108  std::swap(x[i], y[i]);
109 }
110 void swap_vector(int n, std::complex<double> *x, std::complex<double> *y)
111 {
112  for (int i = 0; i < n; i++)
113  std::swap(x[i], y[i]);
114 }
115 #endif
116 
117 
118 #if defined (HAVE_BLAS)
119 void swap_vector(int n, double *x, int incx, double *y, int incy)
120 {
121  blas::dswap_(&n, x, &incx, y, &incy);
122 }
123 void swap_vector(int n, std::complex<double> *x, int incx,
124  std::complex<double> *y, int incy)
125 {
126  blas::zswap_(&n, x, &incx, y, &incy);
127 }
128 #else
129 void swap_vector(int n, double *x, int incx, double *y, int incy)
130 {
131  for (int i = 0; i < n; i++)
132  std::swap(x[i*incx], y[i*incy]);
133 }
134 void swap_vector(int n, std::complex<double> *x, int incx,
135  std::complex<double> *y, int incy)
136 {
137  for (int i = 0; i < n; i++)
138  std::swap(x[i*incx], y[i*incy]);
139 }
140 #endif
141 
142 
143 #if defined(HAVE_BLAS)
144 void scal_vector(int n, double alpha, double *x)
145 {
146  int incr = 1;
147  blas::dscal_(&n, &alpha, x, &incr);
148 }
149 void scal_vector(int n, std::complex<double> alpha, std::complex<double> *x)
150 {
151  int incr = 1;
152  blas::zscal_(&n, &alpha, x, &incr);
153 }
154 #else
155 void scal_vector(int n, double alpha, double *x)
156 {
157  if (alpha != 1.0) {
158  for (int i = 0; i < n; ++i) {
159  x[i] *= alpha;
160  }
161  }
162 }
163 void scal_vector(int n, std::complex<double> alpha, std::complex<double> *x)
164 {
165  if (alpha != std::complex<double>(1.0)) {
166  for (int i = 0; i < n; ++i) {
167  x[i] *= alpha;
168  }
169  }
170 }
171 #endif
172 
173 
174 #if defined(HAVE_BLAS)
175 void scal_vector(int n, double alpha, double *x, int incx)
176 {
177  blas::dscal_(&n, &alpha, x, &incx);
178 }
179 void scal_vector(int n, std::complex<double> alpha, std::complex<double> *x,
180  int incx)
181 {
182  blas::zscal_(&n, &alpha, x, &incx);
183 }
184 #else
185 void scal_vector(int n, double alpha, double *x, int incx)
186 {
187  if (alpha != 1.0) {
188  for (int i = 0; i < n; ++i) {
189  x[i*incx] *= alpha;
190  }
191  }
192 }
193 void scal_vector(int n, std::complex<double> alpha, std::complex<double> *x,
194  int incx)
195 {
196  if (alpha != std::complex<double>(1.0)) {
197  for (int i = 0; i < n; ++i) {
198  x[i*incx] *= alpha;
199  }
200  }
201 }
202 #endif
203 
204 
205 #if defined(HAVE_BLAS)
206 void axpy_vector(int n, double alpha, const double *x, double *y)
207 {
208  int incr = 1;
209  blas::daxpy_(&n, &alpha, x, &incr, y, &incr);
210 }
211 void axpy_vector(int n, std::complex<double> alpha,
212  const std::complex<double> *x, std::complex<double> *y)
213 {
214  int incr = 1;
215  blas::zaxpy_(&n, &alpha, x, &incr, y, &incr);
216 }
217 #else
218 void axpy_vector(int n, double alpha, const double *x, double *y)
219 {
220  if (alpha != 1.0) {
221  for (int i = 0; i < n; ++i) {
222  y[i] += alpha * x[i];
223  }
224  }
225  else {
226  for (int i = 0; i < n; ++i) {
227  y[i] += x[i];
228  }
229  }
230 }
231 void axpy_vector(int n, std::complex<double> alpha,
232  const std::complex<double> *x, std::complex<double> *y)
233 {
234  if (alpha != std::complex<double>(1.0)) {
235  for (int i = 0; i < n; ++i) {
236  y[i] += alpha * x[i];
237  }
238  }
239  else {
240  for (int i = 0; i < n; ++i) {
241  y[i] += x[i];
242  }
243  }
244 }
245 #endif
246 
247 
248 #if defined(HAVE_BLAS)
249 void axpy_vector(int n, double alpha, const double *x, int incx, double *y,
250  int incy)
251 {
252  blas::daxpy_(&n, &alpha, x, &incx, y, &incy);
253 }
254 void axpy_vector(int n, std::complex<double> alpha,
255  const std::complex<double> *x, int incx,
256  std::complex<double> *y, int incy)
257 {
258  blas::zaxpy_(&n, &alpha, x, &incx, y, &incy);
259 }
260 #else
261 void axpy_vector(int n, double alpha, const double *x, int incx, double *y,
262  int incy)
263 {
264  if (alpha != 1.0) {
265  for (int i = 0; i < n; ++i) {
266  y[i*incy] += alpha * x[i*incx];
267  }
268  }
269  else {
270  for (int i = 0; i < n; ++i) {
271  y[i*incy] += x[i*incx];
272  }
273  }
274 }
275 void axpy_vector(int n, std::complex<double> alpha,
276  const std::complex<double> *x, int incx,
277  std::complex<double> *y, int incy)
278 {
279  if (alpha != std::complex<double>(1.0)) {
280  for (int i = 0; i < n; ++i) {
281  y[i*incy] += alpha * x[i*incx];
282  }
283  }
284  else {
285  for (int i = 0; i < n; ++i) {
286  y[i*incy] += x[i*incx];
287  }
288  }
289 }
290 #endif
291 
292 } // namespace itpp
SourceForge Logo

Generated on Sat Jul 6 2013 10:54:20 for IT++ by Doxygen 1.8.2