Skip to content

Commit

Permalink
Add ojalgo module
Browse files Browse the repository at this point in the history
  • Loading branch information
altavir committed Jan 12, 2025
1 parent da96081 commit d8af4e3
Show file tree
Hide file tree
Showing 28 changed files with 440 additions and 137 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@

### Added
- Metropolis-Hastings sampler
- Ojalgo `LinearSpace` implementation.

### Changed
- attributes-kt moved to a separate project, and the version used is 0.3.0
- Kotlin 2.1. Now use cross-compilation to deploy macOS targets.
- Changed `origin` to `cmMatrix` in kmath-commons to avoid property name clash. Expose bidirectional conversion in `CMLinearSpace`

### Deprecated

### Removed

### Fixed
- Fix EJML to properly treat vectors as columns
- (BREAKING CHANGE) Fix EJML to properly treat vectors as columns

### Security

Expand Down
14 changes: 7 additions & 7 deletions benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ kotlin {
implementation(project(":kmath-dimensions"))
implementation(project(":kmath-for-real"))
implementation(project(":kmath-tensors"))
implementation(project(":kmath-multik"))
implementation(libs.multik.default)
implementation(spclibs.kotlinx.benchmark.runtime)
}
}

val jvmMain by getting {
dependencies {
implementation(project(":kmath-commons"))
implementation(project(":kmath-ejml"))
implementation(project(":kmath-nd4j"))
implementation(project(":kmath-kotlingrad"))
implementation(project(":kmath-viktor"))
// implementation(project(":kmath-jafama"))
implementation(projects.kmathCommons)
implementation(projects.kmathEjml)
implementation(projects.kmathNd4j)
implementation(projects.kmathKotlingrad)
implementation(projects.kmathViktor)
implementation(projects.kmathOjalgo)
implementation(projects.kmath.kmathTensorflow)
implementation(projects.kmathMultik)
implementation("org.tensorflow:tensorflow-core-platform:0.4.0")
implementation("org.nd4j:nd4j-native:1.0.0-M1")
// uncomment if your system supports AVX2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import kotlinx.benchmark.Blackhole
import kotlinx.benchmark.Scope
import kotlinx.benchmark.State
import space.kscience.kmath.commons.linear.CMLinearSpace
import space.kscience.kmath.commons.linear.CMLinearSpace.dot
import space.kscience.kmath.ejml.EjmlLinearSpaceDDRM
import space.kscience.kmath.linear.Float64ParallelLinearSpace
import space.kscience.kmath.linear.invoke
import space.kscience.kmath.linear.linearSpace
import space.kscience.kmath.ojalgo.Ojalgo
import space.kscience.kmath.ojalgo.linearSpace
import space.kscience.kmath.operations.Float64Field
import space.kscience.kmath.tensorflow.produceWithTF
import space.kscience.kmath.tensors.core.tensorAlgebra
Expand Down Expand Up @@ -70,6 +73,11 @@ internal class DotBenchmark {
blackhole.consume(matrix1 dot matrix2)
}

@Benchmark
fun ojalgoDot(blackhole: Blackhole) = Ojalgo.R064.linearSpace {
blackhole.consume(matrix1 dot matrix2)
}

@Benchmark
fun multikDot(blackhole: Blackhole) = with(multikAlgebra) {
blackhole.consume(matrix1 dot matrix2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import kotlinx.benchmark.State
import space.kscience.kmath.commons.linear.CMLinearSpace
import space.kscience.kmath.commons.linear.lupSolver
import space.kscience.kmath.ejml.EjmlLinearSpaceDDRM
import space.kscience.kmath.linear.invoke
import space.kscience.kmath.linear.linearSpace
import space.kscience.kmath.linear.lupSolver
import space.kscience.kmath.linear.parallel
import space.kscience.kmath.linear.*
import space.kscience.kmath.ojalgo.Ojalgo
import space.kscience.kmath.ojalgo.linearSpace
import space.kscience.kmath.operations.algebra
import kotlin.random.Random

Expand Down Expand Up @@ -48,10 +47,14 @@ internal class MatrixInverseBenchmark {
blackhole.consume(lupSolver().inverse(matrix))
}


@Benchmark
fun ejmlInverse(blackhole: Blackhole) = EjmlLinearSpaceDDRM {
blackhole.consume(matrix.toEjml().inverted())
blackhole.consume(matrix.inverted())
}

@Benchmark
fun ojalgoInverse(blackhole: Blackhole) = Ojalgo.R064.linearSpace {
blackhole.consume(matrix.getOrComputeAttribute(Inverted))
}

}
4 changes: 1 addition & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ plugins {
alias(spclibs.plugins.kotlinx.kover)
}

val attributesVersion by extra("0.2.0")

allprojects {
repositories {
maven("https://repo.kotlin.link")
Expand Down Expand Up @@ -72,7 +70,7 @@ ksciencePublish {
useSPCTeam()
}
repository("spc", "https://maven.sciprog.center/kscience")
sonatype("https://oss.sonatype.org")
central()
}

apiValidation.nonPublicMarkers.add("space.kscience.kmath.UnstableKMathAPI")
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

package space.kscience.kmath.linear

import space.kscience.kmath.PerformancePitfall
import space.kscience.kmath.commons.linear.CMLinearSpace
import space.kscience.kmath.ejml.EjmlLinearSpaceDDRM
import space.kscience.kmath.nd.StructureND
import space.kscience.kmath.operations.algebra
import space.kscience.kmath.structures.Float64
import kotlin.random.Random

@OptIn(PerformancePitfall::class)
fun main() {
val dim = 46

Expand All @@ -21,7 +23,7 @@ fun main() {

listOf(CMLinearSpace, EjmlLinearSpaceDDRM).forEach { algebra ->
with(algebra) {
//create a simmetric matrix
//create a symmetric matrix
val matrix = buildMatrix(dim, dim) { row, col ->
if (row >= col) u[row, col] else u[col, row]
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ org.gradle.workers.max=4
kotlin.code.style=official
kotlin.mpp.stability.nowarn=true
kotlin.native.ignoreDisabledTargets=true
org.jetbrains.dokka.experimental.gradle.pluginMode=V2EnabledWithHelpers
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
kotlin.native.enableKlibsCrossCompilation=true

toolsVersion=0.16.0-kotlin-2.1.0
toolsVersion=0.16.1-kotlin-2.1.0
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ commons-rng = "1.6"
multik = "0.2.3"

[libraries]
attributes = "space.kscience:attributes-kt:0.3.0"

commons-math = "org.apache.commons:commons-math3:3.6.1"

commons-rng-simple = { module = "org.apache.commons:commons-rng-simple", version.ref = "commons-rng" }
commons-rng-sampling = { module = "org.apache.commons:commons-rng-sampling", version.ref = "commons-rng" }

multik-core = { module = "org.jetbrains.kotlinx:multik-core", version.ref = "multik" }
multik-default = { module = "org.jetbrains.kotlinx:multik-default", version.ref = "multik" }

ojalgo = "org.ojalgo:ojalgo:55.1.0"

[plugins]
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions kmath-ast/src/jsTest/kotlin/space/kscience/kmath/ast/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import space.kscience.kmath.wasm.compile as wasmCompile
import space.kscience.kmath.wasm.compileToExpression as wasmCompileToExpression

@OptIn(UnstableKMathAPI::class)
private object WasmCompilerTestContext : CompilerTestContext {
internal object WasmCompilerTestContext : CompilerTestContext {
override fun MST.compileToExpression(algebra: Int32Ring): Expression<Int> = wasmCompileToExpression(algebra)
override fun MST.compile(algebra: Int32Ring, arguments: Map<Symbol, Int>): Int = wasmCompile(algebra, arguments)
override fun MST.compileToExpression(algebra: Float64Field): Expression<Float64> = wasmCompileToExpression(algebra)
Expand All @@ -31,7 +31,7 @@ private object WasmCompilerTestContext : CompilerTestContext {
wasmCompile(algebra, arguments)
}

private object ESTreeCompilerTestContext : CompilerTestContext {
internal object ESTreeCompilerTestContext : CompilerTestContext {
override fun MST.compileToExpression(algebra: Int32Ring): Expression<Int> = estreeCompileToExpression(algebra)
override fun MST.compile(algebra: Int32Ring, arguments: Map<Symbol, Int>): Int = estreeCompile(algebra, arguments)
override fun MST.compileToExpression(algebra: Float64Field): Expression<Float64> = estreeCompileToExpression(algebra)
Expand Down
2 changes: 1 addition & 1 deletion kmath-commons/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ kscience {
api(projects.kmathOptimization)
api(projects.kmathStat)
api(projects.kmathFunctions)
api("org.apache.commons:commons-math3:3.6.1")
api(libs.commons.math)
}
}

Expand Down
Loading

0 comments on commit d8af4e3

Please sign in to comment.