kmath/kmath-nd4j/README.md

83 lines
2.4 KiB
Markdown
Raw Normal View History

2020-06-29 18:06:13 +03:00
# ND4J NDStructure implementation (`kmath-nd4j`)
This subproject implements the following features:
2020-11-29 13:32:20 +03:00
- [nd4jarraystructure](src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : NDStructure wrapper for INDArray
2020-10-29 11:44:30 +03:00
- [nd4jarrayrings](src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt) : Rings over Nd4jArrayStructure of Int and Long
- [nd4jarrayfields](src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt) : Fields over Nd4jArrayStructure of Float and Double
2020-06-29 18:06:13 +03:00
> #### Artifact:
2020-10-29 11:44:30 +03:00
>
2021-01-22 14:29:46 +03:00
> This module artifact: `kscience.kmath:kmath-nd4j:0.2.0-dev-5`.
2020-10-29 11:44:30 +03:00
>
> Bintray release version: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/kmath-nd4j/images/download.svg) ](https://bintray.com/mipt-npm/kscience/kmath-nd4j/_latestVersion)
>
> Bintray development version: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-nd4j/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-nd4j/_latestVersion)
>
2020-06-29 18:06:13 +03:00
> **Gradle:**
>
> ```gradle
> repositories {
2020-10-29 11:44:30 +03:00
> maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
> maven { url 'https://dl.bintray.com/mipt-npm/kscience' }
2020-06-29 18:06:13 +03:00
> maven { url 'https://dl.bintray.com/mipt-npm/dev' }
2020-10-29 11:44:30 +03:00
> maven { url 'https://dl.bintray.com/hotkeytlt/maven' }
2021-01-05 16:16:42 +03:00
>
2020-06-29 18:06:13 +03:00
> }
>
> dependencies {
2021-01-22 14:29:46 +03:00
> implementation 'kscience.kmath:kmath-nd4j:0.2.0-dev-5'
2020-06-29 18:06:13 +03:00
> }
> ```
> **Gradle Kotlin DSL:**
>
> ```kotlin
> repositories {
2020-10-29 11:44:30 +03:00
> maven("https://dl.bintray.com/kotlin/kotlin-eap")
> maven("https://dl.bintray.com/mipt-npm/kscience")
2020-06-29 18:06:13 +03:00
> maven("https://dl.bintray.com/mipt-npm/dev")
2020-10-29 11:44:30 +03:00
> maven("https://dl.bintray.com/hotkeytlt/maven")
2020-06-29 18:06:13 +03:00
> }
>
> dependencies {
2021-01-22 14:29:46 +03:00
> implementation("kscience.kmath:kmath-nd4j:0.2.0-dev-5")
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.*
val array = Nd4j.ones(2, 2).asRealStructure()
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.*
2020-10-29 11:44:30 +03:00
val field = RealNd4jArrayField(intArrayOf(2, 2))
val array = Nd4j.rand(2, 2).asRealStructure()
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).