Skip to content

Commit 95d33c2

Browse files
authored
Merge pull request #137 from mipt-npm/dev
0.1.4
2 parents 6db921e + 139525e commit 95d33c2

File tree

105 files changed

+1468
-1029
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1468
-1029
lines changed

CHANGELOG.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# KMath
22

33
## [Unreleased]
4+
### Added
5+
6+
### Changed
7+
8+
### Deprecated
9+
10+
### Removed
11+
12+
### Fixed
13+
14+
### Security
15+
## [0.1.4]
416

517
### Added
618
- Functional Expressions API
@@ -16,17 +28,23 @@
1628
- Local coding conventions
1729
- Geometric Domains API in `kmath-core`
1830
- Blocking chains in `kmath-coroutines`
31+
- Full hyperbolic functions support and default implementations within `ExtendedField`
32+
- Norm support for `Complex`
1933

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

2845
### Fixed
2946
- Missing copy method in Memory implementation on JS (https://github.com/mipt-npm/kmath/pull/106)
3047
- D3.dim value in `kmath-dimensions`
3148
- Multiplication in integer rings in `kmath-core` (https://github.com/mipt-npm/kmath/pull/101)
3249
- Commons RNG compatibility (https://github.com/mipt-npm/kmath/issues/93)
50+
- Multiplication of BigInt by scalar

build.gradle.kts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
plugins {
22
id("scientifik.publish") apply false
3+
id("org.jetbrains.changelog") version "0.4.0"
34
}
45

5-
val kmathVersion by extra("0.1.4-dev-8")
6+
val kmathVersion by extra("0.1.4")
67

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

17-
group = "scientifik"
18+
group = "kscience.kmath"
1819
version = kmathVersion
20+
21+
afterEvaluate {
22+
extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension>()?.run {
23+
targets.all {
24+
sourceSets.all {
25+
languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
26+
}
27+
}
28+
}
29+
}
1930
}
2031

2132
subprojects {

examples/build.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,16 @@ benchmark {
5656
}
5757
}
5858

59+
kotlin.sourceSets.all {
60+
with(languageSettings) {
61+
useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
62+
useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
63+
}
64+
}
5965

6066
tasks.withType<KotlinCompile> {
6167
kotlinOptions {
6268
jvmTarget = Scientifik.JVM_TARGET.toString()
69+
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn"
6370
}
64-
}
71+
}

examples/src/benchmarks/kotlin/scientifik/kmath/structures/NDFieldBenchmark.kt

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,38 @@ import org.openjdk.jmh.annotations.Benchmark
44
import org.openjdk.jmh.annotations.Scope
55
import org.openjdk.jmh.annotations.State
66
import scientifik.kmath.operations.RealField
7+
import scientifik.kmath.operations.invoke
78

89
@State(Scope.Benchmark)
910
class NDFieldBenchmark {
10-
1111
@Benchmark
1212
fun autoFieldAdd() {
13-
bufferedField.run {
13+
bufferedField {
1414
var res: NDBuffer<Double> = one
15-
repeat(n) {
16-
res += one
17-
}
15+
repeat(n) { res += one }
1816
}
1917
}
2018

2119
@Benchmark
2220
fun autoElementAdd() {
2321
var res = genericField.one
24-
repeat(n) {
25-
res += 1.0
26-
}
22+
repeat(n) { res += 1.0 }
2723
}
2824

2925
@Benchmark
3026
fun specializedFieldAdd() {
31-
specializedField.run {
27+
specializedField {
3228
var res: NDBuffer<Double> = one
33-
repeat(n) {
34-
res += 1.0
35-
}
29+
repeat(n) { res += 1.0 }
3630
}
3731
}
3832

3933

4034
@Benchmark
4135
fun boxingFieldAdd() {
42-
genericField.run {
36+
genericField {
4337
var res: NDBuffer<Double> = one
44-
repeat(n) {
45-
res += one
46-
}
38+
repeat(n) { res += one }
4739
}
4840
}
4941

examples/src/benchmarks/kotlin/scientifik/kmath/structures/ViktorBenchmark.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,30 @@ import org.openjdk.jmh.annotations.Benchmark
55
import org.openjdk.jmh.annotations.Scope
66
import org.openjdk.jmh.annotations.State
77
import scientifik.kmath.operations.RealField
8+
import scientifik.kmath.operations.invoke
89
import scientifik.kmath.viktor.ViktorNDField
910

10-
1111
@State(Scope.Benchmark)
1212
class ViktorBenchmark {
1313
final val dim = 1000
1414
final val n = 100
1515

1616
// automatically build context most suited for given type.
17-
final val autoField = NDField.auto(RealField, dim, dim)
18-
final val realField = NDField.real(dim, dim)
19-
20-
final val viktorField = ViktorNDField(intArrayOf(dim, dim))
17+
final val autoField: BufferedNDField<Double, RealField> = NDField.auto(RealField, dim, dim)
18+
final val realField: RealNDField = NDField.real(dim, dim)
19+
final val viktorField: ViktorNDField = ViktorNDField(intArrayOf(dim, dim))
2120

2221
@Benchmark
2322
fun automaticFieldAddition() {
24-
autoField.run {
23+
autoField {
2524
var res = one
2625
repeat(n) { res += one }
2726
}
2827
}
2928

3029
@Benchmark
3130
fun viktorFieldAddition() {
32-
viktorField.run {
31+
viktorField {
3332
var res = one
3433
repeat(n) { res += one }
3534
}
@@ -44,7 +43,7 @@ class ViktorBenchmark {
4443

4544
@Benchmark
4645
fun realdFieldLog() {
47-
realField.run {
46+
realField {
4847
val fortyTwo = produce { 42.0 }
4948
var res = one
5049
repeat(n) { res = ln(fortyTwo) }
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package scientifik.kmath.utils
22

3+
import kotlin.contracts.InvocationKind
4+
import kotlin.contracts.contract
35
import kotlin.system.measureTimeMillis
46

57
internal inline fun measureAndPrint(title: String, block: () -> Unit) {
8+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
69
val time = measureTimeMillis(block)
710
println("$title completed in $time millis")
8-
}
11+
}

examples/src/main/kotlin/scientifik/kmath/linear/LinearAlgebraBenchmark.kt

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import scientifik.kmath.commons.linear.CMMatrixContext
55
import scientifik.kmath.commons.linear.inverse
66
import scientifik.kmath.commons.linear.toCM
77
import scientifik.kmath.operations.RealField
8+
import scientifik.kmath.operations.invoke
89
import scientifik.kmath.structures.Matrix
910
import kotlin.contracts.ExperimentalContracts
1011
import kotlin.random.Random
@@ -21,29 +22,18 @@ fun main() {
2122

2223
val n = 5000 // iterations
2324

24-
MatrixContext.real.run {
25-
26-
repeat(50) {
27-
val res = inverse(matrix)
28-
}
29-
30-
val inverseTime = measureTimeMillis {
31-
repeat(n) {
32-
val res = inverse(matrix)
33-
}
34-
}
35-
25+
MatrixContext.real {
26+
repeat(50) { val res = inverse(matrix) }
27+
val inverseTime = measureTimeMillis { repeat(n) { val res = inverse(matrix) } }
3628
println("[kmath] Inversion of $n matrices $dim x $dim finished in $inverseTime millis")
3729
}
3830

3931
//commons-math
4032

4133
val commonsTime = measureTimeMillis {
42-
CMMatrixContext.run {
34+
CMMatrixContext {
4335
val cm = matrix.toCM() //avoid overhead on conversion
44-
repeat(n) {
45-
val res = inverse(cm)
46-
}
36+
repeat(n) { val res = inverse(cm) }
4737
}
4838
}
4939

@@ -53,7 +43,7 @@ fun main() {
5343
//koma-ejml
5444

5545
val komaTime = measureTimeMillis {
56-
KomaMatrixContext(EJMLMatrixFactory(), RealField).run {
46+
(KomaMatrixContext(EJMLMatrixFactory(), RealField)) {
5747
val km = matrix.toKoma() //avoid overhead on conversion
5848
repeat(n) {
5949
val res = inverse(km)

examples/src/main/kotlin/scientifik/kmath/linear/MultiplicationBenchmark.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import koma.matrix.ejml.EJMLMatrixFactory
44
import scientifik.kmath.commons.linear.CMMatrixContext
55
import scientifik.kmath.commons.linear.toCM
66
import scientifik.kmath.operations.RealField
7+
import scientifik.kmath.operations.invoke
78
import scientifik.kmath.structures.Matrix
89
import kotlin.random.Random
910
import kotlin.system.measureTimeMillis
@@ -18,7 +19,7 @@ fun main() {
1819
// //warmup
1920
// matrix1 dot matrix2
2021

21-
CMMatrixContext.run {
22+
CMMatrixContext {
2223
val cmMatrix1 = matrix1.toCM()
2324
val cmMatrix2 = matrix2.toCM()
2425

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

32-
33-
KomaMatrixContext(EJMLMatrixFactory(), RealField).run {
33+
(KomaMatrixContext(EJMLMatrixFactory(), RealField)) {
3434
val komaMatrix1 = matrix1.toKoma()
3535
val komaMatrix2 = matrix2.toKoma()
3636

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package scientifik.kmath.operations
2+
3+
fun main() {
4+
val res = BigIntField {
5+
number(1) * 2
6+
}
7+
println("bigint:$res")
8+
}

examples/src/main/kotlin/scientifik/kmath/operations/ComplexDemo.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ fun main() {
99
Complex(index[0].toDouble() - index[1].toDouble(), index[0].toDouble() + index[1].toDouble())
1010
}
1111

12-
13-
val compute = NDField.complex(8).run {
12+
val compute = (NDField.complex(8)) {
1413
val a = produce { (it) -> i * it - it.toDouble() }
1514
val b = 3
1615
val c = Complex(1.0, 1.0)
1716

1817
(a pow b) + c
1918
}
20-
21-
}
19+
}

0 commit comments

Comments
 (0)