Feature/tensors performance #497

Closed
margarita0303 wants to merge 91 commits from feature/tensors-performance into feature/tensors-performance
2 changed files with 5 additions and 4 deletions
Showing only changes of commit 29ed51c50a - Show all commits

View File

@ -837,7 +837,7 @@ public open class DoubleTensorAlgebra :
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 commonShape = tensor.shape.sliceArray(0 until size - 2)
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)
.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)

View File

@ -372,7 +372,8 @@ private fun SIGN(a: Double, b: Double): Double {
else
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 m = shape.component1()
val n = shape.component2()
@ -531,7 +532,7 @@ internal fun MutableStructure2D<Double>.svdGolubKahanHelper(u: MutableStructure2
var z = 0.0
var x = 0.0
for (k in n - 1 downTo 0) {
for (its in 1 until 30) {
for (its in 1 until iterations) {
flag = 1
for (newl in k downTo 0) {
nm = newl - 1