diff --git a/src/main/scala/com/nsrddyn/ALU/Prime.scala b/src/main/scala/com/nsrddyn/ALU/Prime.scala index 343dcee..1432c93 100644 --- a/src/main/scala/com/nsrddyn/ALU/Prime.scala +++ b/src/main/scala/com/nsrddyn/ALU/Prime.scala @@ -28,12 +28,13 @@ class Prime() extends Benchmark { def isPrime(n: Int): Boolean = { if n <= 1 then false else !(2 to math.sqrt(n).toInt).exists(i => n % i == 0) + + } def run(n: Int, result: Boolean): Unit = { for i <- 0 to n do if isPrime(i) == result then println("true") else println("false") - } diff --git a/src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala b/src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala index b42ade9..80a1778 100644 --- a/src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala +++ b/src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala @@ -1,5 +1,8 @@ package com.nsrddyn.fpu +import scala.math._ +import scala.collection.immutable.ListSet +import scala.collection.mutable.ArrayBuffer class CholeskyDecomposition { @@ -13,14 +16,38 @@ class CholeskyDecomposition { * Linpack uses the cholesky decomposition * https://www.netlib.org/linpack/ * + * https://www.geeksforgeeks.org/dsa/cholesky-decomposition-matrix-decomposition/ * + * The Cholesky decomposition maps matrix A into the product of A = L ยท LH where L is the lower triangular matrix and LH is the transposed, + * complex conjugate or Hermitian, and therefore of upper triangular form (Fig. 13.6). + * This is true because of the special case of A being a square, conjugate symmetric matrix. */ - def choleskyDecomposition(n: Int): Unit = { + def run(matrix: List[List[Int]]): Unit = { - for (w <- 0 to n) { + val n: Int = matrix.size + + // store the lower triangular matrix + val lower = Vector[Vector[Int]]() + for (i <- 0 until n) + { + for (j <- 0 until i) + var sum: Double = 0 + + if j == i then + sum += math.pow(lowerBuffer(i)(j), 2) + + end if + lower(i)(j) = (sqrt(matrix(i)(j))()) + + j += 1 } + i += 1 } + + def (matrix: Vector[Vector[Int]], index: int, jindex: int ): Int = if j == 1 then return math.pow(matrix(index)(jindex)) else + + } diff --git a/src/main/scala/com/nsrddyn/Main.scala b/src/main/scala/com/nsrddyn/Main.scala index de4fa1b..8d0ad7f 100644 --- a/src/main/scala/com/nsrddyn/Main.scala +++ b/src/main/scala/com/nsrddyn/Main.scala @@ -1,16 +1,23 @@ package com.nsrddyn +import com.nsrddyn.fpu.CholeskyDecomposition +import com.nsrddyn.Tests.CholeskyDecompositionTest +import java.time.Instant +import com.nsrddyn.alu.* +import com.nsrddyn.tools.Benchmark + object Torque { - import java.time.Instant - import com.nsrddyn.alu.* - import com.nsrddyn.tools.Benchmark - - @main def main(args: String*): Unit = + println("hello world") + @main def main(args: String*): Unit = { // ANSI ESCAPE CODE: clear screen println("\u001b[2J\u001b[H") println("--- TORQUE STRESS TESTING UTILITY ---") - } + var tester: CholeskyDecompositionTest = new CholeskyDecompositionTest + println(tester.test()) + + } +} diff --git a/src/main/scala/com/nsrddyn/Tests/CholeskyDecompositionTest.scala b/src/main/scala/com/nsrddyn/Tests/CholeskyDecompositionTest.scala new file mode 100644 index 0000000..340caa3 --- /dev/null +++ b/src/main/scala/com/nsrddyn/Tests/CholeskyDecompositionTest.scala @@ -0,0 +1,16 @@ +package com.nsrddyn.Tests + +import com.nsrddyn.fpu.CholeskyDecomposition +import scala.collection.immutable.ListSet + +class CholeskyDecompositionTest extends CholeskyDecomposition { + + def test(): Unit = { + + val cdp: CholeskyDecomposition = new CholeskyDecomposition + val matrix: List[List[Int]] = List.empty[List[Int]] + + println(cdp.run(matrix)) + + } +}