MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / JacobiSVD

Function JacobiSVD

src/backend/cpu/homography.cpp:66–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64
65template<typename T, int M, int N>
66void JacobiSVD(T* S, T* V) {
67 const int iterations = 30;
68 array<T, N> d{};
69
70 for (int i = 0; i < N; i++) {
71 T sd = 0;
72 for (int j = 0; j < M; j++) {
73 T t = S[i * M + j];
74 sd += t * t;
75 }
76 d[i] = sd;
77
78 V[i * N + i] = 1;
79 }
80
81 for (int it = 0; it < iterations; it++) {
82 bool converged = false;
83
84 for (int i = 0; i < N - 1; i++) {
85 for (int j = i + 1; j < N; j++) {
86 T* Si = S + i * M;
87 T* Sj = S + j * M;
88 T* Vi = V + i * N;
89 T* Vj = V + j * N;
90
91 T p = static_cast<T>(0);
92 for (int k = 0; k < M; k++) { p += Si[k] * Sj[k]; }
93
94 if (abs(p) <= M * EPS<T>::eps() * sqrt(d[i] * d[j])) {
95 continue;
96 }
97
98 T y = d[i] - d[j];
99 T r = hypot(p * 2, y);
100 T r2 = r * 2;
101 T c, s;
102 if (y >= 0) {
103 c = sqrt((r + y) / r2);
104 s = p / (r2 * c);
105 } else {
106 s = sqrt((r - y) / r2);
107 c = p / (r2 * s);
108 }
109
110 T a = 0, b = 0;
111 for (int k = 0; k < M; k++) {
112 T t0 = c * Si[k] + s * Sj[k];
113 T t1 = c * Sj[k] - s * Si[k];
114 Si[k] = t0;
115 Sj[k] = t1;
116
117 a += t0 * t0;
118 b += t1 * t1;
119 }
120 d[i] = a;
121 d[j] = b;
122
123 for (int l = 0; l < N; l++) {

Callers

nothing calls this directly

Calls 3

sqrtFunction · 0.85
hypotFunction · 0.85
absFunction · 0.70

Tested by

no test coverage detected