Compare commits

..

2 Commits

Author SHA1 Message Date
d6f99d058b chore: folder refactor, start of zio implementation 2025-11-26 21:01:15 +01:00
fcad65fc51 feature: cholesky decompostiion finised
i said finished but i get an out of bounds exception lololol
2025-11-25 23:28:17 +01:00
7 changed files with 58 additions and 61 deletions

View File

@ -1,9 +1,9 @@
package com.nsrddyn.alu package com.nsrddyn.alu
import com.nsrddyn.alu.Prime
import com.nsrddyn.tools.Benchmark import com.nsrddyn.tools.Benchmark
import com.nsrddyn.test
class Prime() extends Benchmark { class Prime() extends {
/* /*
* Calculate all primes up to limit * Calculate all primes up to limit
@ -40,3 +40,25 @@ class Prime() extends Benchmark {
} }
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)
}
}

View File

@ -1,6 +0,0 @@
package com.nsrddyn.Enums
enum Status:
case PASS
case FAIL

View File

@ -23,31 +23,24 @@ class CholeskyDecomposition {
* This is true because of the special case of A being a square, conjugate symmetric matrix. * This is true because of the special case of A being a square, conjugate symmetric matrix.
*/ */
def run(matrix: List[List[Int]]): Unit = { def run(matrix: Vector[Vector[Int]]): Unit = {
val n: Int = matrix.size val size: Int = matrix.size
val lower: ArrayBuffer[ArrayBuffer[Int]] = ArrayBuffer[ArrayBuffer[Int]]()
// 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
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)
} }
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
}
}

View File

@ -6,6 +6,11 @@ import java.time.Instant
import com.nsrddyn.alu.* import com.nsrddyn.alu.*
import com.nsrddyn.tools.Benchmark import com.nsrddyn.tools.Benchmark
enum Status:
case PASS
case FAIL
object Torque { object Torque {
println("hello world") println("hello world")

View File

@ -8,9 +8,12 @@ class CholeskyDecompositionTest extends CholeskyDecomposition {
def test(): Unit = { def test(): Unit = {
val cdp: CholeskyDecomposition = new CholeskyDecomposition val cdp: CholeskyDecomposition = new CholeskyDecomposition
val matrix: List[List[Int]] = List.empty[List[Int]] val matrix: Vector[Vector[Int]] = Vector(Vector(1,2,3),Vector(1,2,3),Vector(1,2,3))
println(cdp.run(matrix)) println(cdp.run(matrix))
} }
} }

View File

@ -1,29 +0,0 @@
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!")
}

View File

@ -0,0 +1,9 @@
package com.nsrddyn.Traits
import zio._
trait Workload {
def name: String
def run: ZIO[Any, Nothing, Unit]
}