forked from ericjang/svd3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_cpu.c
73 lines (56 loc) · 2.21 KB
/
main_cpu.c
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
#include <stdio.h>
#include "svd3.h"
#include <time.h>
// some printing utilities
inline void printMat3(float a11, float a12, float a13,
float a21, float a22, float a23,
float a31, float a32, float a33)
{
printf("%f %f %f \n", a11, a12, a13);
printf("%f %f %f \n", a21, a22, a23);
printf("%f %f %f \n", a31, a32, a33);
}
inline void printQuat(float * q)
{
// print w,x,y,z
printf("%f %f %f %f\n",q[3],q[0],q[1],q[2]);
}
int main() {
float a11, a12, a13, a21, a22, a23, a31, a32, a33;
a11 = -0.558253f; a12 = -0.0461681f; a13 = -0.505735f;
a21 = -0.411397f; a22 = 0.0365854f; a23 = 0.199707f;
a31 = 0.285389f; a32 = -0.313789f; a33 = 0.200189f;
// printf("Original Matrix:\n");
// printMat3(a11, a12, a13, a21, a22, a23, a31, a32, a33);
float u11, u12, u13, u21, u22, u23, u31, u32, u33;
float s11, s12, s13, s21, s22, s23, s31, s32, s33;
float v11, v12, v13, v21, v22, v23, v31, v32, v33;
clock_t start, end;
start = clock();
for (int i = 0; i < 1e6; i++)
{
svd(a11, a12, a13, a21, a22, a23, a31, a32, a33,
&u11, &u12, &u13, &u21, &u22, &u23, &u31, &u32, &u33,
&s11, &s12, &s13, &s21, &s22, &s23, &s31, &s32, &s33,
&v11, &v12, &v13, &v21, &v22, &v23, &v31, &v32, &v33);
}
end = clock();
printf("Average SVD takes %f microseconds \n ", 1e6 * ((double)(end - start) / 1e6 / CLOCKS_PER_SEC));
printf("U:\n");
printMat3(u11, u12, u13, u21, u22, u23, u31, u32, u33);
printf("S:\n");
printMat3(s11, s12, s13, s21, s22, s23, s31, s32, s33);
printf("V:\n");
printMat3(v11, v12, v13, v21, v22, v23, v31, v32, v33);
float t11, t12, t13, t21, t22, t23, t31, t32, t33;
multAB(u11, u12, u13, u21, u22, u23, u31, u32, u33,
s11, s12, s13, s21, s22, s23, s31, s32, s33,
&t11, &t12, &t13, &t21, &t22, &t23, &t31, &t32, &t33);
float m11, m12, m13, m21, m22, m23, m31, m32, m33;
multAB(t11, t12, t13, t21, t22, t23, t31, t32, t33,
v11, v21, v31, v12, v22, v32, v13, v23, v33,
&m11, &m12, &m13, &m21, &m22, &m23, &m31, &m32, &m33);
printf("USV* : \n");
printMat3(m11, m12, m13, m21, m22, m23, m31, m32, m33);
return 0;
}