Golub-Kahan SVD algorithm for KMP tensors #499
@ -837,7 +837,7 @@ public open class DoubleTensorAlgebra :
|
|||||||
return this.svdGolubKahan()
|
return this.svdGolubKahan()
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun StructureND<Double>.svdGolubKahan(): Triple<DoubleTensor, DoubleTensor, DoubleTensor> {
|
public fun StructureND<Double>.svdGolubKahan(iterations: Int = 30): Triple<DoubleTensor, DoubleTensor, DoubleTensor> {
|
||||||
val size = tensor.dimension
|
val size = tensor.dimension
|
||||||
val commonShape = tensor.shape.sliceArray(0 until size - 2)
|
val commonShape = tensor.shape.sliceArray(0 until size - 2)
|
||||||
val (n, m) = tensor.shape.sliceArray(size - 2 until size)
|
val (n, m) = tensor.shape.sliceArray(size - 2 until size)
|
||||||
@ -859,7 +859,7 @@ public open class DoubleTensorAlgebra :
|
|||||||
.slice(matrix.bufferStart until matrix.bufferStart + matrixSize)
|
.slice(matrix.bufferStart until matrix.bufferStart + matrixSize)
|
||||||
.toDoubleArray()
|
.toDoubleArray()
|
||||||
)
|
)
|
||||||
curMatrix.as2D().svdGolubKahanHelper(uTensors[index].as2D(), sTensorVectors[index], vTensors[index].as2D())
|
curMatrix.as2D().svdGolubKahanHelper(uTensors[index].as2D(), sTensorVectors[index], vTensors[index].as2D(), iterations)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Triple(uTensor.transpose(), sTensor, vTensor)
|
return Triple(uTensor.transpose(), sTensor, vTensor)
|
||||||
|
@ -372,7 +372,8 @@ private fun SIGN(a: Double, b: Double): Double {
|
|||||||
else
|
else
|
||||||
return -abs(a)
|
return -abs(a)
|
||||||
}
|
}
|
||||||
internal fun MutableStructure2D<Double>.svdGolubKahanHelper(u: MutableStructure2D<Double>, w: BufferedTensor<Double>, v: MutableStructure2D<Double>) {
|
internal fun MutableStructure2D<Double>.svdGolubKahanHelper(u: MutableStructure2D<Double>, w: BufferedTensor<Double>,
|
||||||
|
v: MutableStructure2D<Double>, iterations: Int) {
|
||||||
val shape = this.shape
|
val shape = this.shape
|
||||||
val m = shape.component1()
|
val m = shape.component1()
|
||||||
val n = shape.component2()
|
val n = shape.component2()
|
||||||
@ -531,7 +532,7 @@ internal fun MutableStructure2D<Double>.svdGolubKahanHelper(u: MutableStructure2
|
|||||||
var z = 0.0
|
var z = 0.0
|
||||||
var x = 0.0
|
var x = 0.0
|
||||||
for (k in n - 1 downTo 0) {
|
for (k in n - 1 downTo 0) {
|
||||||
for (its in 1 until 30) {
|
for (its in 1 until iterations) {
|
||||||
flag = 1
|
flag = 1
|
||||||
for (newl in k downTo 0) {
|
for (newl in k downTo 0) {
|
||||||
nm = newl - 1
|
nm = newl - 1
|
||||||
|
Loading…
Reference in New Issue
Block a user