kmath/kmath-nd4j/README.md

61 lines
1.3 KiB
Markdown
Raw Permalink Normal View History

2021-03-22 14:32:08 +03:00
# Module kmath-nd4j
2020-06-29 18:06:13 +03:00
2021-03-22 14:32:08 +03:00
ND4J based implementations of KMath abstractions.
2020-06-29 18:06:13 +03:00
2024-03-27 09:51:23 +03:00
- [nd4jarraystructure](#) : NDStructure wrapper for INDArray
- [nd4jarrayrings](#) : Rings over Nd4jArrayStructure of Int and Long
- [nd4jarrayfields](#) : Fields over Nd4jArrayStructure of Float and Double
2020-06-29 18:06:13 +03:00
2021-03-22 14:32:08 +03:00
## Artifact:
2024-03-27 09:51:23 +03:00
The Maven coordinates of this project are `space.kscience:kmath-nd4j:0.4.0`.
2021-03-22 14:32:08 +03:00
**Gradle Kotlin DSL:**
```kotlin
repositories {
maven("https://repo.kotlin.link")
mavenCentral()
2021-03-22 14:32:08 +03:00
}
dependencies {
2024-03-27 09:51:23 +03:00
implementation("space.kscience:kmath-nd4j:0.4.0")
2021-03-22 14:32:08 +03:00
}
```
2020-06-29 18:06:13 +03:00
## Examples
NDStructure wrapper for INDArray:
```kotlin
import org.nd4j.linalg.factory.*
import scientifik.kmath.nd4j.*
import scientifik.kmath.structures.*
2021-03-16 22:46:22 +03:00
val array = Nd4j.ones(2, 2).asDoubleStructure()
2020-06-29 18:06:13 +03:00
println(array[0, 0]) // 1.0
array[intArrayOf(0, 0)] = 24.0
println(array[0, 0]) // 24.0
```
2020-06-29 18:30:08 +03:00
Fast element-wise and in-place arithmetics for INDArray:
2020-06-29 18:06:13 +03:00
```kotlin
import org.nd4j.linalg.factory.*
import scientifik.kmath.nd4j.*
import scientifik.kmath.operations.*
2021-03-16 22:46:22 +03:00
val field = DoubleNd4jArrayField(intArrayOf(2, 2))
val array = Nd4j.rand(2, 2).asDoubleStructure()
2020-06-29 18:06:13 +03:00
val res = field {
(25.0 / array + 20) * 4
}
println(res.ndArray)
// [[ 250.6449, 428.5840],
// [ 269.7913, 202.2077]]
```
Contributed by [Iaroslav Postovalov](https://github.com/CommanderTvis).