mirror of
https://github.com/nasrlol/torque.git
synced 2025-11-27 23:09:21 +01:00
feature: checkpoint
This commit is contained in:
parent
409b76a88e
commit
e70ce01ce4
@ -28,12 +28,13 @@ class Prime() extends Benchmark {
|
|||||||
def isPrime(n: Int): Boolean = {
|
def isPrime(n: Int): Boolean = {
|
||||||
if n <= 1 then false
|
if n <= 1 then false
|
||||||
else !(2 to math.sqrt(n).toInt).exists(i => n % i == 0)
|
else !(2 to math.sqrt(n).toInt).exists(i => n % i == 0)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def run(n: Int, result: Boolean): Unit = {
|
def run(n: Int, result: Boolean): Unit = {
|
||||||
|
|
||||||
for i <- 0 to n do if isPrime(i) == result then println("true") else println("false")
|
for i <- 0 to n do if isPrime(i) == result then println("true") else println("false")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
package com.nsrddyn.fpu
|
package com.nsrddyn.fpu
|
||||||
|
|
||||||
|
import scala.math._
|
||||||
|
import scala.collection.immutable.ListSet
|
||||||
|
import scala.collection.mutable.ArrayBuffer
|
||||||
|
|
||||||
class CholeskyDecomposition {
|
class CholeskyDecomposition {
|
||||||
|
|
||||||
@ -13,14 +16,38 @@ class CholeskyDecomposition {
|
|||||||
* Linpack uses the cholesky decomposition
|
* Linpack uses the cholesky decomposition
|
||||||
* https://www.netlib.org/linpack/
|
* 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
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,16 +1,23 @@
|
|||||||
package com.nsrddyn
|
package com.nsrddyn
|
||||||
|
|
||||||
object Torque {
|
import com.nsrddyn.fpu.CholeskyDecomposition
|
||||||
|
import com.nsrddyn.Tests.CholeskyDecompositionTest
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import com.nsrddyn.alu.*
|
import com.nsrddyn.alu.*
|
||||||
import com.nsrddyn.tools.Benchmark
|
import com.nsrddyn.tools.Benchmark
|
||||||
|
|
||||||
@main def main(args: String*): Unit =
|
object Torque {
|
||||||
|
|
||||||
|
println("hello world")
|
||||||
|
|
||||||
|
@main def main(args: String*): Unit = {
|
||||||
// ANSI ESCAPE CODE: clear screen
|
// ANSI ESCAPE CODE: clear screen
|
||||||
println("\u001b[2J\u001b[H")
|
println("\u001b[2J\u001b[H")
|
||||||
println("--- TORQUE STRESS TESTING UTILITY ---")
|
println("--- TORQUE STRESS TESTING UTILITY ---")
|
||||||
|
|
||||||
|
var tester: CholeskyDecompositionTest = new CholeskyDecompositionTest
|
||||||
|
println(tester.test())
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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))
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user