Golub-Kahan SVD algorithm for KMP tensors #499

Closed
grinisrit wants to merge 64 commits from dev into dev
Showing only changes of commit a497a5df1a - Show all commits

View File

@ -65,8 +65,7 @@ internal fun MutableStructure2D<Double>.svdGolabKahan(v: MutableStructure2D<Doub
f = this[i, i]
if (f >= 0) {
g = (-1) * abs(sqrt(s))
}
else {
} else {
g = abs(sqrt(s))
}
val h = f * g - s
@ -106,8 +105,7 @@ internal fun MutableStructure2D<Double>.svdGolabKahan(v: MutableStructure2D<Doub
f = this[i, l]
if (f >= 0) {
g = (-1) * abs(sqrt(s))
}
else {
} else {
g = abs(sqrt(s))
}
val h = f * g - s
@ -183,8 +181,7 @@ internal fun MutableStructure2D<Double>.svdGolabKahan(v: MutableStructure2D<Doub
for (j in i until m) {
this[j, i] *= g
}
}
else {
} else {
for (j in i until m) {
this[j, i] = 0.0
}
@ -276,9 +273,9 @@ internal fun MutableStructure2D<Double>.svdGolabKahan(v: MutableStructure2D<Doub
y = w[nm, 0]
g = rv1[nm]
h = rv1[k]
f = ((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y)
g = pythag(f,1.0)
f=((x-z)*(x+z)+h*((y/(f+SIGN(g,f)))-h))/x
f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y)
g = pythag(f, 1.0)
f = ((x - z) * (x + z) + h * ((y / (f + SIGN(g, f))) - h)) / x
c = 1.0
s = 1.0
@ -289,7 +286,7 @@ internal fun MutableStructure2D<Double>.svdGolabKahan(v: MutableStructure2D<Doub
y = w[i, 0]
h = s * g
g = c * g
z = pythag(f,h)
z = pythag(f, h)
rv1[j] = z
c = f / z
s = h / z
@ -299,12 +296,12 @@ internal fun MutableStructure2D<Double>.svdGolabKahan(v: MutableStructure2D<Doub
y *= c
for (jj in 0 until n) {
x=v[jj, j];
z=v[jj, i];
x = v[jj, j];
z = v[jj, i];
v[jj, j] = x * c + z * s;
v[jj, i] = z * c - x * s;
}
z = pythag(f,h)
z = pythag(f, h)
w[j, 0] = z
if (z != 0.0) {
z = 1.0 / z