Skip to content

Commit

Permalink
Merge pull request SciProgCentre#137 from mipt-npm/dev
Browse files Browse the repository at this point in the history
0.1.4
  • Loading branch information
altavir committed Sep 14, 2020
2 parents 6db921e + 139525e commit 95d33c2
Show file tree
Hide file tree
Showing 105 changed files with 1,468 additions and 1,029 deletions.
22 changes: 20 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# KMath

## [Unreleased]
### Added

### Changed

### Deprecated

### Removed

### Fixed

### Security
## [0.1.4]

### Added
- Functional Expressions API
Expand All @@ -16,17 +28,23 @@
- Local coding conventions
- Geometric Domains API in `kmath-core`
- Blocking chains in `kmath-coroutines`
- Full hyperbolic functions support and default implementations within `ExtendedField`
- Norm support for `Complex`

### Changed
- `readAsMemory` now has `throws IOException` in JVM signature.
- Several functions taking functional types were made `inline`.
- Several functions taking functional types now have `callsInPlace` contracts.
- BigInteger and BigDecimal algebra: JBigDecimalField has companion object with default math context; minor optimizations
- `power(T, Int)` extension function has preconditions and supports `Field<T>`
- Memory objects have more preconditions (overflow checking)
- `tg` function is renamed to `tan` (https://github.com/mipt-npm/kmath/pull/114)
- Gradle version: 6.3 -> 6.5.1
- Moved probability distributions to commons-rng and to `kmath-prob`.
- Gradle version: 6.3 -> 6.6
- Moved probability distributions to commons-rng and to `kmath-prob`

### Fixed
- Missing copy method in Memory implementation on JS (https://github.com/mipt-npm/kmath/pull/106)
- D3.dim value in `kmath-dimensions`
- Multiplication in integer rings in `kmath-core` (https://github.com/mipt-npm/kmath/pull/101)
- Commons RNG compatibility (https://github.com/mipt-npm/kmath/issues/93)
- Multiplication of BigInt by scalar
15 changes: 13 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
plugins {
id("scientifik.publish") apply false
id("org.jetbrains.changelog") version "0.4.0"
}

val kmathVersion by extra("0.1.4-dev-8")
val kmathVersion by extra("0.1.4")

val bintrayRepo by extra("scientifik")
val githubProject by extra("kmath")
Expand All @@ -14,8 +15,18 @@ allprojects {
maven("https://dl.bintray.com/hotkeytlt/maven")
}

group = "scientifik"
group = "kscience.kmath"
version = kmathVersion

afterEvaluate {
extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension>()?.run {
targets.all {
sourceSets.all {
languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
}
}
}
}
}

subprojects {
Expand Down
9 changes: 8 additions & 1 deletion examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ benchmark {
}
}

kotlin.sourceSets.all {
with(languageSettings) {
useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
}
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = Scientifik.JVM_TARGET.toString()
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,38 @@ import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import scientifik.kmath.operations.RealField
import scientifik.kmath.operations.invoke

@State(Scope.Benchmark)
class NDFieldBenchmark {

@Benchmark
fun autoFieldAdd() {
bufferedField.run {
bufferedField {
var res: NDBuffer<Double> = one
repeat(n) {
res += one
}
repeat(n) { res += one }
}
}

@Benchmark
fun autoElementAdd() {
var res = genericField.one
repeat(n) {
res += 1.0
}
repeat(n) { res += 1.0 }
}

@Benchmark
fun specializedFieldAdd() {
specializedField.run {
specializedField {
var res: NDBuffer<Double> = one
repeat(n) {
res += 1.0
}
repeat(n) { res += 1.0 }
}
}


@Benchmark
fun boxingFieldAdd() {
genericField.run {
genericField {
var res: NDBuffer<Double> = one
repeat(n) {
res += one
}
repeat(n) { res += one }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@ import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import scientifik.kmath.operations.RealField
import scientifik.kmath.operations.invoke
import scientifik.kmath.viktor.ViktorNDField


@State(Scope.Benchmark)
class ViktorBenchmark {
final val dim = 1000
final val n = 100

// automatically build context most suited for given type.
final val autoField = NDField.auto(RealField, dim, dim)
final val realField = NDField.real(dim, dim)

final val viktorField = ViktorNDField(intArrayOf(dim, dim))
final val autoField: BufferedNDField<Double, RealField> = NDField.auto(RealField, dim, dim)
final val realField: RealNDField = NDField.real(dim, dim)
final val viktorField: ViktorNDField = ViktorNDField(intArrayOf(dim, dim))

@Benchmark
fun automaticFieldAddition() {
autoField.run {
autoField {
var res = one
repeat(n) { res += one }
}
}

@Benchmark
fun viktorFieldAddition() {
viktorField.run {
viktorField {
var res = one
repeat(n) { res += one }
}
Expand All @@ -44,7 +43,7 @@ class ViktorBenchmark {

@Benchmark
fun realdFieldLog() {
realField.run {
realField {
val fortyTwo = produce { 42.0 }
var res = one
repeat(n) { res = ln(fortyTwo) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package scientifik.kmath.utils

import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.system.measureTimeMillis

internal inline fun measureAndPrint(title: String, block: () -> Unit) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
val time = measureTimeMillis(block)
println("$title completed in $time millis")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import scientifik.kmath.commons.linear.CMMatrixContext
import scientifik.kmath.commons.linear.inverse
import scientifik.kmath.commons.linear.toCM
import scientifik.kmath.operations.RealField
import scientifik.kmath.operations.invoke
import scientifik.kmath.structures.Matrix
import kotlin.contracts.ExperimentalContracts
import kotlin.random.Random
Expand All @@ -21,29 +22,18 @@ fun main() {

val n = 5000 // iterations

MatrixContext.real.run {

repeat(50) {
val res = inverse(matrix)
}

val inverseTime = measureTimeMillis {
repeat(n) {
val res = inverse(matrix)
}
}

MatrixContext.real {
repeat(50) { val res = inverse(matrix) }
val inverseTime = measureTimeMillis { repeat(n) { val res = inverse(matrix) } }
println("[kmath] Inversion of $n matrices $dim x $dim finished in $inverseTime millis")
}

//commons-math

val commonsTime = measureTimeMillis {
CMMatrixContext.run {
CMMatrixContext {
val cm = matrix.toCM() //avoid overhead on conversion
repeat(n) {
val res = inverse(cm)
}
repeat(n) { val res = inverse(cm) }
}
}

Expand All @@ -53,7 +43,7 @@ fun main() {
//koma-ejml

val komaTime = measureTimeMillis {
KomaMatrixContext(EJMLMatrixFactory(), RealField).run {
(KomaMatrixContext(EJMLMatrixFactory(), RealField)) {
val km = matrix.toKoma() //avoid overhead on conversion
repeat(n) {
val res = inverse(km)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import koma.matrix.ejml.EJMLMatrixFactory
import scientifik.kmath.commons.linear.CMMatrixContext
import scientifik.kmath.commons.linear.toCM
import scientifik.kmath.operations.RealField
import scientifik.kmath.operations.invoke
import scientifik.kmath.structures.Matrix
import kotlin.random.Random
import kotlin.system.measureTimeMillis
Expand All @@ -18,7 +19,7 @@ fun main() {
// //warmup
// matrix1 dot matrix2

CMMatrixContext.run {
CMMatrixContext {
val cmMatrix1 = matrix1.toCM()
val cmMatrix2 = matrix2.toCM()

Expand All @@ -29,8 +30,7 @@ fun main() {
println("CM implementation time: $cmTime")
}


KomaMatrixContext(EJMLMatrixFactory(), RealField).run {
(KomaMatrixContext(EJMLMatrixFactory(), RealField)) {
val komaMatrix1 = matrix1.toKoma()
val komaMatrix2 = matrix2.toKoma()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package scientifik.kmath.operations

fun main() {
val res = BigIntField {
number(1) * 2
}
println("bigint:$res")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ fun main() {
Complex(index[0].toDouble() - index[1].toDouble(), index[0].toDouble() + index[1].toDouble())
}


val compute = NDField.complex(8).run {
val compute = (NDField.complex(8)) {
val a = produce { (it) -> i * it - it.toDouble() }
val b = 3
val c = Complex(1.0, 1.0)

(a pow b) + c
}

}
}
15 changes: 4 additions & 11 deletions examples/src/main/kotlin/scientifik/kmath/structures/ComplexND.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ fun main() {
val realField = NDField.real(dim, dim)
val complexField = NDField.complex(dim, dim)


val realTime = measureTimeMillis {
realField.run {
realField {
var res: NDBuffer<Double> = one
repeat(n) {
res += 1.0
Expand All @@ -26,18 +25,15 @@ fun main() {
println("Real addition completed in $realTime millis")

val complexTime = measureTimeMillis {
complexField.run {
complexField {
var res: NDBuffer<Complex> = one
repeat(n) {
res += 1.0
}
repeat(n) { res += 1.0 }
}
}

println("Complex addition completed in $complexTime millis")
}


fun complexExample() {
//Create a context for 2-d structure with complex values
ComplexField {
Expand All @@ -46,10 +42,7 @@ fun complexExample() {
val x = one * 2.5
operator fun Number.plus(other: Complex) = Complex(this.toDouble() + other.re, other.im)
//a structure generator specific to this context
val matrix = produce { (k, l) ->
k + l * i
}

val matrix = produce { (k, l) -> k + l * i }
//Perform sum
val sum = matrix + x + 1.0

Expand Down
Loading

0 comments on commit 95d33c2

Please sign in to comment.