2021-06-05 08:44:02 +03:00
# Module kmath-jafama
2021-06-14 17:51:06 +03:00
Integration with [Jafama ](https://github.com/jeffhain/jafama ).
2021-06-05 08:44:02 +03:00
2021-06-14 17:51:06 +03:00
- [jafama-double ](src/main/kotlin/space/kscience/kmath/jafama/ ) : Double ExtendedField implementations based on Jafama
2021-06-05 08:44:02 +03:00
2021-06-14 17:51:06 +03:00
## Artifact:
2021-06-05 08:44:02 +03:00
2021-06-14 17:51:06 +03:00
The Maven coordinates of this project are `space.kscience:kmath-jafama:0.3.0-dev-13` .
**Gradle:**
```gradle
repositories {
maven { url 'https://repo.kotlin.link' }
mavenCentral()
}
dependencies {
implementation 'space.kscience:kmath-jafama:0.3.0-dev-13'
}
```
**Gradle Kotlin DSL:**
2021-06-05 08:44:02 +03:00
```kotlin
2021-06-14 17:51:06 +03:00
repositories {
maven("https://repo.kotlin.link")
mavenCentral()
}
dependencies {
implementation("space.kscience:kmath-jafama:0.3.0-dev-13")
}
```
2021-06-05 08:44:02 +03:00
2021-06-14 17:51:06 +03:00
## Example usage
2021-06-05 08:44:02 +03:00
2021-06-14 17:51:06 +03:00
All the `DoubleField` uses can be replaced with `JafamaDoubleField` or `StrictJafamaDoubleField` .
2021-06-05 08:44:02 +03:00
2021-06-14 17:51:06 +03:00
```kotlin
import space.kscience.kmath.jafama.*
import space.kscience.kmath.operations.*
fun main() {
val a = 2.0
val b = StrictJafamaDoubleField { exp(a) }
println(JafamaDoubleField { b + a })
println(StrictJafamaDoubleField { ln(b) })
2021-06-05 08:44:02 +03:00
}
```
2021-06-08 16:58:34 +03:00
2021-06-14 17:51:06 +03:00
## Performance
2021-06-15 09:18:40 +03:00
According to KMath benchmarks on GraalVM, Jafama functions are slower than JDK math; however, there are indications that on Hotspot Jafama is a bit faster.
2021-06-14 17:51:06 +03:00
< details >
2021-06-15 09:18:40 +03:00
< summary >
Report for benchmark configuration < code > jafamaDouble< / code >
< / summary >
2021-06-14 17:51:06 +03:00
2021-06-15 09:18:40 +03:00
* Run on OpenJDK 64-Bit Server VM (build 11.0.11+8-jvmci-21.1-b05) with Java process:
2021-06-14 17:51:06 +03:00
```
2021-06-15 09:18:40 +03:00
/home/commandertvis/graalvm-ce-java11/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCIProduct -XX:-UnlockExperimentalVMOptions -XX:ThreadPriorityPolicy=1 -javaagent:/home/commandertvis/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core-jvm/1.5.0/d8cebccdcddd029022aa8646a5a953ff88b13ac8/kotlinx-coroutines-core-jvm-1.5.0.jar -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -ea
2021-06-08 16:58:34 +03:00
```
2021-06-15 09:18:40 +03:00
* JMH 1.21 was used in `thrpt` mode with 1 warmup iteration by 1000 ms and 5 measurement iterations by 1000 ms.
2021-06-14 17:51:06 +03:00
2021-06-15 09:18:40 +03:00
| Benchmark | Score |
|:---------:|:-----:|
|`space.kscience.kmath.benchmarks.JafamaBenchmark.core`|14.296120859512893 ± 0.36462633435888736 ops/s|
|`space.kscience.kmath.benchmarks.JafamaBenchmark.jafama`|11.431566395649781 ± 2.570896777898243 ops/s|
|`space.kscience.kmath.benchmarks.JafamaBenchmark.strictJafama`|11.746020495694117 ± 6.205909559197869 ops/s|
2021-06-14 17:51:06 +03:00
< / details >
2021-06-15 09:18:40 +03:00