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