-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplexVector.c
More file actions
81 lines (66 loc) · 1.83 KB
/
ComplexVector.c
File metadata and controls
81 lines (66 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "FFTSVD.h"
#ifdef INTEL_C
#include "ipps.h"
#endif
/* Constructors and Destructors */
ComplexVector ComplexVector_allocate(unsigned int length) {
#ifdef INTEL_C
#ifdef REAL_IS_DOUBLE
ComplexVector vc = (ComplexVector)ippsMalloc_64fc(length);
#else
ComplexVector vc = (ComplexVector)ippsMalloc_32fc(length);
#endif
memset(vc, 0, length * sizeof(complexreal));
return vc;
#else
return (ComplexVector)calloc(length, sizeof(complexreal));
#endif
}
void ComplexVector_free(ComplexVector vector) {
#ifdef INTEL_C
ippsFree(vector);
#else
free(vector);
#endif
}
/* Initialization and Copying */
void ComplexVector_copy(ComplexVector vectordest, ComplexVector vectorsrc, unsigned int length) {
unsigned int i;
#pragma ivdep
for (i = 0; i < length; i++)
vectordest[i] = vectorsrc[i];
}
void ComplexVector_zero(ComplexVector vector, unsigned int length) {
unsigned int i;
#pragma ivdep
for (i = 0; i < length; i++) {
vector[i] = (complexreal)0;
}
}
/* Arithmetic Operations */
void ComplexVector_addelementmultiplyvector(ComplexVector vector1, ComplexVector vector2, ComplexVector vector3, unsigned int length) {
unsigned int i;
#ifdef INTEL_C
#ifdef REAL_IS_FLOAT
ippsAddProduct_32fc((Ipp32fc*)vector2, (Ipp32fc*)vector3, (Ipp32fc*)vector1, length);
#else
#ifdef REAL_IS_DOUBLE
ippsAddProduct_64fc((Ipp64fc*)vector2, (Ipp64fc*)vector3, (Ipp64fc*)vector1, length);
#endif
#endif
#else
#pragma ivdep
for (i = 0; i < length; i++)
vector1[i] += vector2[i] * vector3[i];
#endif
}
void ComplexVector_writefile(char* filename, ComplexVector vector, unsigned int length) {
unsigned int i;
FILE* file = NULL;
file = fopen(filename, "w");
#ifndef _AIX
for (i = 0; i < length; i++)
fprintf(file, "%20.15e %20.15e\n", creal(vector[i]), cimag(vector[i]));
#endif
fclose(file);
}