-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode.c
More file actions
59 lines (56 loc) · 1.63 KB
/
code.c
File metadata and controls
59 lines (56 loc) · 1.63 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
/* Add arrays of contiguous data */
typedef struct {double real; double imag;} cdouble;
typedef struct {float real; float imag;} cfloat;
void zadd(cdouble *a, cdouble *b, cdouble *c, long n)
{
while (n--) {
c->real = a->real + b->real;
c->imag = a->imag + b->imag;
a++; b++; c++;
}
}
//with similar code for cadd, dadd, and sadd that handles complex float, double, and float data-types, respectively:
void cadd(cfloat *a, cfloat *b, cfloat *c, long n)
{
while (n--) {
c->real = a->real + b->real;
c->imag = a->imag + b->imag;
a++; b++; c++;
}
}
void dadd(double *a, double *b, double *c, long n)
{
while (n--) {
*c++ = *a++ + *b++;
}
}
void sadd(float *a, float *b, float *c, long n)
{
while (n--) {
*c++ = *a++ + *b++;
}
}
//The code.c file also contains the function dfilter2d:
/* Assumes b is contiguous and
a has strides that are multiples of sizeof(double)
*/
void
dfilter2d(double *a, double *b, int *astrides, int *dims)
{
int i, j, M, N, S0, S1;
int r, c, rm1, rp1, cp1, cm1;
M = dims[0]; N = dims[1];
S0 = astrides[0]/sizeof(double);
S1=astrides[1]/sizeof(double);
for (i=1; i<M-1; i++) {
r = i*S0; rp1 = r+S0; rm1 = r-S0;
for (j=1; j<N-1; j++) {
c = j*S1; cp1 = j+S1; cm1 = j-S1;
b[i*N+j] = a[r+c] + \
(a[rp1+c] + a[rm1+c] + \
a[r+cp1] + a[r+cm1])*0.5 + \
(a[rp1+cp1] + a[rp1+cm1] + \
a[rm1+cp1] + a[rm1+cp1])*0.25;
}
}
}