mirror of
https://github.com/nasrlol/torque.git
synced 2025-11-27 23:09:21 +01:00
Compare commits
No commits in common. "d6f99d058b34d5b6fbc3f630bf491b302cdf324f" and "e70ce01ce40d4e3fc86f887913ee1c7fa6ffb50e" have entirely different histories.
d6f99d058b
...
e70ce01ce4
@ -1,9 +1,9 @@
|
||||
package com.nsrddyn.alu
|
||||
import com.nsrddyn.alu.Prime
|
||||
import com.nsrddyn.tools.Benchmark
|
||||
import com.nsrddyn.test
|
||||
|
||||
class Prime() extends {
|
||||
|
||||
import com.nsrddyn.tools.Benchmark
|
||||
|
||||
class Prime() extends Benchmark {
|
||||
|
||||
/*
|
||||
* Calculate all primes up to limit
|
||||
@ -40,25 +40,3 @@ class Prime() extends {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class PrimeRunner extends Workload {
|
||||
|
||||
def run(threads: Int): Unit = {
|
||||
|
||||
val pr = new Prime()
|
||||
val br = new Benchmark()
|
||||
|
||||
/*
|
||||
* test cases
|
||||
*
|
||||
* 7919 true
|
||||
* 2147483647 false
|
||||
*/
|
||||
|
||||
val time = pr.run(7919, true)
|
||||
println(time)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
package com.nsrddyn.Enums
|
||||
|
||||
enum Status:
|
||||
case PASS
|
||||
case FAIL
|
||||
|
||||
@ -23,24 +23,31 @@ class CholeskyDecomposition {
|
||||
* This is true because of the special case of A being a square, conjugate symmetric matrix.
|
||||
*/
|
||||
|
||||
def run(matrix: Vector[Vector[Int]]): Unit = {
|
||||
def run(matrix: List[List[Int]]): Unit = {
|
||||
|
||||
val size: Int = matrix.size
|
||||
val lower: ArrayBuffer[ArrayBuffer[Int]] = ArrayBuffer[ArrayBuffer[Int]]()
|
||||
val n: Int = matrix.size
|
||||
|
||||
for
|
||||
i <- 0 to size
|
||||
j <- 0 until i
|
||||
do
|
||||
if i == j then lower(i)(j) = getSquaredSummation(lower, i, j, matrix) else lower(j)(j) = getReversedSummation(lower, i, j, matrix)
|
||||
// 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
|
||||
|
||||
|
||||
private def getReversedSummation(lower: ArrayBuffer[ArrayBuffer[Int]], i: Int, j: Int, matrix: Vector[Vector[Int]]) = {
|
||||
math.sqrt(matrix(j)(j) - (0 until j).map { k => lower(i)(k) * lower(j)(k) }.sum).toInt
|
||||
}
|
||||
private def getSquaredSummation(lower: ArrayBuffer[ArrayBuffer[Int]], i: Int, j: Int, matrix: Vector[Vector[Int]]) = {
|
||||
((matrix(i)(j) - (0 until j).map { k => math.pow(lower(j)(k), 2)}.sum) / lower(j)(j)).toInt
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,11 +6,6 @@ import java.time.Instant
|
||||
import com.nsrddyn.alu.*
|
||||
import com.nsrddyn.tools.Benchmark
|
||||
|
||||
enum Status:
|
||||
case PASS
|
||||
case FAIL
|
||||
|
||||
|
||||
object Torque {
|
||||
|
||||
println("hello world")
|
||||
|
||||
@ -8,12 +8,9 @@ class CholeskyDecompositionTest extends CholeskyDecomposition {
|
||||
def test(): Unit = {
|
||||
|
||||
val cdp: CholeskyDecomposition = new CholeskyDecomposition
|
||||
val matrix: Vector[Vector[Int]] = Vector(Vector(1,2,3),Vector(1,2,3),Vector(1,2,3))
|
||||
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!")
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
package com.nsrddyn.Traits
|
||||
|
||||
import zio._
|
||||
|
||||
trait Workload {
|
||||
|
||||
def name: String
|
||||
def run: ZIO[Any, Nothing, Unit]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user