mirror of
https://github.com/nasrlol/torque.git
synced 2025-11-27 23:09:21 +01:00
Compare commits
9 Commits
b3a5e3305a
...
e70ce01ce4
| Author | SHA1 | Date | |
|---|---|---|---|
| e70ce01ce4 | |||
| 409b76a88e | |||
| e077e179d4 | |||
| 694f5afeff | |||
| b96c4615cd | |||
| 092f28a3f2 | |||
| 421c6c3c93 | |||
| 4bb2ff6828 | |||
| 308f6addd0 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -10,4 +10,6 @@ hs_err_pid*
|
|||||||
.idea/
|
.idea/
|
||||||
*.iml
|
*.iml
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.scala-build/
|
||||||
|
|
||||||
|
project/metals.sbt
|
||||||
|
|||||||
@ -4,3 +4,4 @@ name := "torque"
|
|||||||
organization := "com.nsrddyn"
|
organization := "com.nsrddyn"
|
||||||
|
|
||||||
libraryDependencies += "dev.zio" %% "zio" % "2.1.22"
|
libraryDependencies += "dev.zio" %% "zio" % "2.1.22"
|
||||||
|
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.19" % Test
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package com.nsrddyn
|
package com.nsrddyn.alu
|
||||||
|
|
||||||
import scala.util.hashing
|
import scala.util.hashing
|
||||||
|
|
||||||
@ -1,9 +1,9 @@
|
|||||||
package com.nsrddyn
|
package com.nsrddyn.alu
|
||||||
|
|
||||||
|
|
||||||
|
import com.nsrddyn.tools.Benchmark
|
||||||
|
|
||||||
class Prime() {
|
class Prime() extends Benchmark {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate all primes up to limit
|
* Calculate all primes up to limit
|
||||||
@ -18,11 +18,25 @@ class Prime() {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO: I did the countrary of what i wanted to accieve with the is prime function
|
||||||
|
* We want the function to be less optimized so that the CPU has more work == more stress
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
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): Unit = for i <- 0 to n do isPrime(i)
|
def run(n: Int, result: Boolean): Unit = {
|
||||||
|
|
||||||
|
for i <- 0 to n do if isPrime(i) == result then println("true") else println("false")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
6
src/main/scala/com/nsrddyn/Enums/Status.scala
Normal file
6
src/main/scala/com/nsrddyn/Enums/Status.scala
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package com.nsrddyn.Enums
|
||||||
|
|
||||||
|
enum Status:
|
||||||
|
case PASS
|
||||||
|
case FAIL
|
||||||
|
|
||||||
53
src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala
Normal file
53
src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package com.nsrddyn.fpu
|
||||||
|
|
||||||
|
import scala.math._
|
||||||
|
import scala.collection.immutable.ListSet
|
||||||
|
import scala.collection.mutable.ArrayBuffer
|
||||||
|
|
||||||
|
class CholeskyDecomposition {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Floating point operation to stress the cpu
|
||||||
|
* Calculate the number of KFLOPS / FLOPS
|
||||||
|
* implementation of the Cholesky decomposition
|
||||||
|
* More information on the Cholesky decomposition at:
|
||||||
|
* https://en.wikipedia.org/wiki/Cholesky_decomposition
|
||||||
|
*
|
||||||
|
* 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 run(matrix: List[List[Int]]): Unit = {
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
6
src/main/scala/com/nsrddyn/FPU/FPU.scala
Normal file
6
src/main/scala/com/nsrddyn/FPU/FPU.scala
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package com.nsrddyn.fpu
|
||||||
|
|
||||||
|
|
||||||
|
class FPU {
|
||||||
|
|
||||||
|
}
|
||||||
5
src/main/scala/com/nsrddyn/FPU/Matrix.scala
Normal file
5
src/main/scala/com/nsrddyn/FPU/Matrix.scala
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package com.nsrddyn.fpu
|
||||||
|
|
||||||
|
class Matrix {
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,20 +1,23 @@
|
|||||||
package com.nsrddyn
|
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 {
|
object Torque {
|
||||||
|
|
||||||
import java.time.Instant
|
println("hello world")
|
||||||
|
|
||||||
@main def main(args: String*): Unit =
|
|
||||||
|
|
||||||
|
@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 ---")
|
||||||
|
|
||||||
val now: Instant = Instant.now()
|
var tester: CholeskyDecompositionTest = new CholeskyDecompositionTest
|
||||||
println(now)
|
println(tester.test())
|
||||||
|
|
||||||
val pr = new Prime()
|
}
|
||||||
|
|
||||||
val intMax = 2147483647
|
|
||||||
pr.run(intMax)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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))
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/main/scala/com/nsrddyn/Tests/PrimeTest.scala
Normal file
29
src/main/scala/com/nsrddyn/Tests/PrimeTest.scala
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.nsrddyn.Test
|
||||||
|
|
||||||
|
import com.nsrddyn.alu.Prime
|
||||||
|
import com.nsrddyn.tools.Benchmark
|
||||||
|
|
||||||
|
class PrimeTest extends Prime {
|
||||||
|
|
||||||
|
def runBasic(): Unit = {
|
||||||
|
|
||||||
|
val pr = new Prime()
|
||||||
|
val br = new Benchmark()
|
||||||
|
|
||||||
|
/*
|
||||||
|
* test cases
|
||||||
|
*
|
||||||
|
* 7919 true
|
||||||
|
* 2147483647 false
|
||||||
|
*/
|
||||||
|
|
||||||
|
val time = pr.run(7919, true)
|
||||||
|
println(time)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
def runExtreme(): Unit = println("running some very have stuff!")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
17
src/main/scala/com/nsrddyn/Tools/Benchmark.scala
Normal file
17
src/main/scala/com/nsrddyn/Tools/Benchmark.scala
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.nsrddyn.tools
|
||||||
|
|
||||||
|
class Benchmark {
|
||||||
|
/*
|
||||||
|
* Calculate the time between the start of the execution of the function and the end
|
||||||
|
* */
|
||||||
|
def measureTime(work: => Unit): Long = {
|
||||||
|
|
||||||
|
val start = System.nanoTime()
|
||||||
|
work
|
||||||
|
val end = System.nanoTime()
|
||||||
|
end - start
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: map this to an actual precision value
|
||||||
|
def measurePrecision(work: => Boolean, expectedResult: Boolean): Unit = if work == expectedResult then println(true) else println(false)
|
||||||
|
}
|
||||||
@ -1,12 +0,0 @@
|
|||||||
package com.nsrddyn
|
|
||||||
|
|
||||||
/*
|
|
||||||
* cpu object, only one instance of an object needed
|
|
||||||
*/
|
|
||||||
|
|
||||||
object Cpu {
|
|
||||||
|
|
||||||
val name = ""
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
package com.nsrddyn
|
|
||||||
|
|
||||||
|
|
||||||
class CholeskyDecomposition {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Floating point operation to stress the cpu
|
|
||||||
* Calculate the number of KFLOPS / FLOPS
|
|
||||||
* implementation of the Cholesky decomposition
|
|
||||||
* More information on the Cholesky decomposition at:
|
|
||||||
* https://en.wikipedia.org/wiki/Cholesky_decomposition
|
|
||||||
*
|
|
||||||
* Linpack uses the cholesky decomposition
|
|
||||||
* https://www.netlib.org/linpack/
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
def choleskyDecomposition(n: Int): Unit = {
|
|
||||||
|
|
||||||
for (w <- 0 to n) {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
package com.nsrddyn
|
|
||||||
|
|
||||||
|
|
||||||
class FPU {
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
package com.nsrddyn
|
|
||||||
|
|
||||||
class Matrix {
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user