diff --git a/README.md b/README.md
index afab32dcf..2df9d3246 100644
--- a/README.md
+++ b/README.md
@@ -8,41 +8,50 @@ Bintray: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience
Bintray-dev: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-core/_latestVersion)
# KMath
-Could be pronounced as `key-math`.
-The Kotlin MATHematics library was initially intended as a Kotlin-based analog to Python's `numpy` library. Later we found that kotlin is much more flexible language and allows superior architecture designs. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. The `numpy`-like experience could be achieved with [kmath-for-real](/kmath-for-real) extension module.
+
+Could be pronounced as `key-math`. The Kotlin MATHematics library was initially intended as a Kotlin-based analog to
+Python's NumPy library. Later we found that kotlin is much more flexible language and allows superior architecture
+designs. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. The `numpy`-like experience could
+be achieved with [kmath-for-real](/kmath-for-real) extension module.
## Publications and talks
+
* [A conceptual article about context-oriented design](https://proandroiddev.com/an-introduction-context-oriented-programming-in-kotlin-2e79d316b0a2)
* [Another article about context-oriented design](https://proandroiddev.com/diving-deeper-into-context-oriented-programming-in-kotlin-3ecb4ec38814)
* [ACAT 2019 conference paper](https://aip.scitation.org/doi/abs/10.1063/1.5130103)
# Goal
-* Provide a flexible and powerful API to work with mathematics abstractions in Kotlin-multiplatform (JVM and JS for now and Native in future).
+
+* Provide a flexible and powerful API to work with mathematics abstractions in Kotlin-multiplatform (JVM, JS and Native).
* Provide basic multiplatform implementations for those abstractions (without significant performance optimization).
* Provide bindings and wrappers with those abstractions for popular optimized platform libraries.
## Non-goals
-* Be like Numpy. It was the idea at the beginning, but we decided that we can do better in terms of API.
-* Provide best performance out of the box. We have specialized libraries for that. Need only API wrappers for them.
+
+* Be like NumPy. It was the idea at the beginning, but we decided that we can do better in terms of API.
+* Provide the best performance out of the box. We have specialized libraries for that. Need only API wrappers for them.
* Cover all cases as immediately and in one bundle. We will modularize everything and add new features gradually.
-* Provide specialized behavior in the core. API is made generic on purpose, so one needs to specialize for types, like for `Double` in the core. For that we will have specialization modules like `for-real`, which will give better experience for those, who want to work with specific types.
+* Provide specialized behavior in the core. API is made generic on purpose, so one needs to specialize for types, like
+for `Double` in the core. For that we will have specialization modules like `for-real`, which will give better
+experience for those, who want to work with specific types.
## Features
-Actual feature list is [here](/docs/features.md)
+Current feature list is [here](/docs/features.md)
* **Algebra**
- * Algebraic structures like rings, spaces and field (**TODO** add example to wiki)
+ * Algebraic structures like rings, spaces and fields (**TODO** add example to wiki)
* Basic linear algebra operations (sums, products, etc.), backed by the `Space` API.
- * Complex numbers backed by the `Field` API (meaning that they will be usable in any structure like vectors and N-dimensional arrays).
+ * Complex numbers backed by the `Field` API (meaning they will be usable in any structure like vectors and
+ N-dimensional arrays).
* Advanced linear algebra operations like matrix inversion and LU decomposition.
* **Array-like structures** Full support of many-dimensional array-like structures
including mixed arithmetic operations and function operations over arrays and numbers (with the added benefit of static type checking).
-* **Expressions** By writing a single mathematical expression
-once, users will be able to apply different types of objects to the expression by providing a context. Expressions
-can be used for a wide variety of purposes from high performance calculations to code generation.
+* **Expressions** By writing a single mathematical expression once, users will be able to apply different types of
+objects to the expression by providing a context. Expressions can be used for a wide variety of purposes from high
+performance calculations to code generation.
* **Histograms** Fast multi-dimensional histograms.
@@ -50,9 +59,10 @@ can be used for a wide variety of purposes from high performance calculations to
* **Type-safe dimensions** Type-safe dimensions for matrix operations.
-* **Commons-math wrapper** It is planned to gradually wrap most parts of [Apache commons-math](http://commons.apache.org/proper/commons-math/)
- library in Kotlin code and maybe rewrite some parts to better suit the Kotlin programming paradigm, however there is no fixed roadmap for that. Feel free
- to submit a feature request if you want something to be done first.
+* **Commons-math wrapper** It is planned to gradually wrap most parts of
+[Apache commons-math](http://commons.apache.org/proper/commons-math/) library in Kotlin code and maybe rewrite some
+parts to better suit the Kotlin programming paradigm, however there is no established roadmap for that. Feel free to
+submit a feature request if you want something to be implemented first.
## Planned features
@@ -151,6 +161,18 @@ can be used for a wide variety of purposes from high performance calculations to
> **Maturity**: EXPERIMENTAL
+* ### [kmath-nd4j](kmath-nd4j)
+> ND4J NDStructure implementation and according NDAlgebra classes
+>
+> **Maturity**: EXPERIMENTAL
+>
+> **Features:**
+> - [nd4jarraystrucure](kmath-nd4j/src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt) : NDStructure wrapper for INDArray
+> - [nd4jarrayrings](kmath-nd4j/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt) : Rings over Nd4jArrayStructure of Int and Long
+> - [nd4jarrayfields](kmath-nd4j/src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt) : Fields over Nd4jArrayStructure of Float and Double
+
+
+
* ### [kmath-stat](kmath-stat)
>
>
@@ -166,39 +188,53 @@ can be used for a wide variety of purposes from high performance calculations to
## Multi-platform support
-KMath is developed as a multi-platform library, which means that most of the interfaces are declared in the [common module](/kmath-core/src/commonMain). Implementation is also done in the common module wherever possible. In some cases, features are delegated to platform-specific implementations even if they could be done in the common module for performance reasons. Currently, the JVM is the main focus of development, however Kotlin/Native and Kotlin/JS contributions are also welcome.
+KMath is developed as a multi-platform library, which means that most of the interfaces are declared in the
+[common source sets](/kmath-core/src/commonMain) and implemented there wherever it is possible. In some cases, features
+are delegated to platform-specific implementations even if they could be provided in the common module for performance
+reasons. Currently, the Kotlin/JVM is the primary platform, however Kotlin/Native and Kotlin/JS contributions and
+feedback are also welcome.
## Performance
-Calculation performance is one of major goals of KMath in the future, but in some cases it is not possible to achieve both performance and flexibility. We expect to focus on creating convenient universal API first and then work on increasing performance for specific cases. We expect the worst KMath benchmarks will perform better than native Python, but worse than optimized native/SciPy (mostly due to boxing operations on primitive numbers). The best performance of optimized parts could be better than SciPy.
+Calculation performance is one of major goals of KMath in the future, but in some cases it is impossible to achieve
+both performance and flexibility.
-### Dependency
+We expect to focus on creating convenient universal API first and then work on increasing performance for specific
+cases. We expect the worst KMath benchmarks will perform better than native Python, but worse than optimized
+native/SciPy (mostly due to boxing operations on primitive numbers). The best performance of optimized parts could be
+better than SciPy.
-Release artifacts are accessible from bintray with following configuration (see documentation for [kotlin-multiplatform](https://kotlinlang.org/docs/reference/multiplatform.html) form more details):
+### Repositories
+
+Release artifacts are accessible from bintray with following configuration (see documentation of
+[Kotlin Multiplatform](https://kotlinlang.org/docs/reference/multiplatform.html) for more details):
```kotlin
-repositories{
+repositories {
maven("https://dl.bintray.com/mipt-npm/kscience")
}
-dependencies{
- api("kscience.kmath:kmath-core:0.2.0-dev-2")
- //api("kscience.kmath:kmath-core-jvm:0.2.0-dev-2") for jvm-specific version
+dependencies {
+ api("kscience.kmath:kmath-core:0.2.0-dev-3")
+ // api("kscience.kmath:kmath-core-jvm:0.2.0-dev-3") for jvm-specific version
}
```
Gradle `6.0+` is required for multiplatform artifacts.
-### Development
+#### Development
+
+Development builds are uploaded to the separate repository:
-Development builds are accessible from the reposirtory
```kotlin
-repositories{
+repositories {
maven("https://dl.bintray.com/mipt-npm/dev")
}
```
-with the same artifact names.
## Contributing
-The project requires a lot of additional work. The most important thing we need is a feedback about what features are required the most. Feel free to open feature issues with requests. We are also welcome to code contributions, especially in issues marked as [waiting for a hero](https://github.com/mipt-npm/kmath/labels/waiting%20for%20a%20hero).
\ No newline at end of file
+The project requires a lot of additional work. The most important thing we need is a feedback about what features are
+required the most. Feel free to create feature requests. We are also welcome to code contributions,
+especially in issues marked with
+[waiting for a hero](https://github.com/mipt-npm/kmath/labels/waiting%20for%20a%20hero) label.
diff --git a/build.gradle.kts b/build.gradle.kts
index b03c03ab8..de0714543 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -2,16 +2,15 @@ plugins {
id("ru.mipt.npm.project")
}
-val kmathVersion: String by extra("0.2.0-dev-3")
-val bintrayRepo: String by extra("kscience")
-val githubProject: String by extra("kmath")
+internal val kmathVersion: String by extra("0.2.0-dev-3")
+internal val bintrayRepo: String by extra("kscience")
+internal val githubProject: String by extra("kmath")
allprojects {
repositories {
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://dl.bintray.com/kotlin/kotlinx")
- mavenCentral()
maven("https://dl.bintray.com/hotkeytlt/maven")
}
@@ -27,6 +26,6 @@ readme {
readmeTemplate = file("docs/templates/README-TEMPLATE.md")
}
-apiValidation{
+apiValidation {
validationDisabled = true
-}
\ No newline at end of file
+}
diff --git a/docs/templates/README-TEMPLATE.md b/docs/templates/README-TEMPLATE.md
index 5117e0694..ee1df818c 100644
--- a/docs/templates/README-TEMPLATE.md
+++ b/docs/templates/README-TEMPLATE.md
@@ -8,41 +8,50 @@ Bintray: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience
Bintray-dev: [ ![Download](https://api.bintray.com/packages/mipt-npm/dev/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/dev/kmath-core/_latestVersion)
# KMath
-Could be pronounced as `key-math`.
-The Kotlin MATHematics library was initially intended as a Kotlin-based analog to Python's `numpy` library. Later we found that kotlin is much more flexible language and allows superior architecture designs. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. The `numpy`-like experience could be achieved with [kmath-for-real](/kmath-for-real) extension module.
+
+Could be pronounced as `key-math`. The Kotlin MATHematics library was initially intended as a Kotlin-based analog to
+Python's NumPy library. Later we found that kotlin is much more flexible language and allows superior architecture
+designs. In contrast to `numpy` and `scipy` it is modular and has a lightweight core. The `numpy`-like experience could
+be achieved with [kmath-for-real](/kmath-for-real) extension module.
## Publications and talks
+
* [A conceptual article about context-oriented design](https://proandroiddev.com/an-introduction-context-oriented-programming-in-kotlin-2e79d316b0a2)
* [Another article about context-oriented design](https://proandroiddev.com/diving-deeper-into-context-oriented-programming-in-kotlin-3ecb4ec38814)
* [ACAT 2019 conference paper](https://aip.scitation.org/doi/abs/10.1063/1.5130103)
# Goal
-* Provide a flexible and powerful API to work with mathematics abstractions in Kotlin-multiplatform (JVM and JS for now and Native in future).
+
+* Provide a flexible and powerful API to work with mathematics abstractions in Kotlin-multiplatform (JVM, JS and Native).
* Provide basic multiplatform implementations for those abstractions (without significant performance optimization).
* Provide bindings and wrappers with those abstractions for popular optimized platform libraries.
## Non-goals
-* Be like Numpy. It was the idea at the beginning, but we decided that we can do better in terms of API.
-* Provide best performance out of the box. We have specialized libraries for that. Need only API wrappers for them.
+
+* Be like NumPy. It was the idea at the beginning, but we decided that we can do better in terms of API.
+* Provide the best performance out of the box. We have specialized libraries for that. Need only API wrappers for them.
* Cover all cases as immediately and in one bundle. We will modularize everything and add new features gradually.
-* Provide specialized behavior in the core. API is made generic on purpose, so one needs to specialize for types, like for `Double` in the core. For that we will have specialization modules like `for-real`, which will give better experience for those, who want to work with specific types.
+* Provide specialized behavior in the core. API is made generic on purpose, so one needs to specialize for types, like
+for `Double` in the core. For that we will have specialization modules like `for-real`, which will give better
+experience for those, who want to work with specific types.
## Features
-Actual feature list is [here](/docs/features.md)
+Current feature list is [here](/docs/features.md)
* **Algebra**
- * Algebraic structures like rings, spaces and field (**TODO** add example to wiki)
+ * Algebraic structures like rings, spaces and fields (**TODO** add example to wiki)
* Basic linear algebra operations (sums, products, etc.), backed by the `Space` API.
- * Complex numbers backed by the `Field` API (meaning that they will be usable in any structure like vectors and N-dimensional arrays).
+ * Complex numbers backed by the `Field` API (meaning they will be usable in any structure like vectors and
+ N-dimensional arrays).
* Advanced linear algebra operations like matrix inversion and LU decomposition.
* **Array-like structures** Full support of many-dimensional array-like structures
including mixed arithmetic operations and function operations over arrays and numbers (with the added benefit of static type checking).
-* **Expressions** By writing a single mathematical expression
-once, users will be able to apply different types of objects to the expression by providing a context. Expressions
-can be used for a wide variety of purposes from high performance calculations to code generation.
+* **Expressions** By writing a single mathematical expression once, users will be able to apply different types of
+objects to the expression by providing a context. Expressions can be used for a wide variety of purposes from high
+performance calculations to code generation.
* **Histograms** Fast multi-dimensional histograms.
@@ -50,9 +59,10 @@ can be used for a wide variety of purposes from high performance calculations to
* **Type-safe dimensions** Type-safe dimensions for matrix operations.
-* **Commons-math wrapper** It is planned to gradually wrap most parts of [Apache commons-math](http://commons.apache.org/proper/commons-math/)
- library in Kotlin code and maybe rewrite some parts to better suit the Kotlin programming paradigm, however there is no fixed roadmap for that. Feel free
- to submit a feature request if you want something to be done first.
+* **Commons-math wrapper** It is planned to gradually wrap most parts of
+[Apache commons-math](http://commons.apache.org/proper/commons-math/) library in Kotlin code and maybe rewrite some
+parts to better suit the Kotlin programming paradigm, however there is no established roadmap for that. Feel free to
+submit a feature request if you want something to be implemented first.
## Planned features
@@ -72,39 +82,53 @@ $modules
## Multi-platform support
-KMath is developed as a multi-platform library, which means that most of the interfaces are declared in the [common module](/kmath-core/src/commonMain). Implementation is also done in the common module wherever possible. In some cases, features are delegated to platform-specific implementations even if they could be done in the common module for performance reasons. Currently, the JVM is the main focus of development, however Kotlin/Native and Kotlin/JS contributions are also welcome.
+KMath is developed as a multi-platform library, which means that most of the interfaces are declared in the
+[common source sets](/kmath-core/src/commonMain) and implemented there wherever it is possible. In some cases, features
+are delegated to platform-specific implementations even if they could be provided in the common module for performance
+reasons. Currently, the Kotlin/JVM is the primary platform, however Kotlin/Native and Kotlin/JS contributions and
+feedback are also welcome.
## Performance
-Calculation performance is one of major goals of KMath in the future, but in some cases it is not possible to achieve both performance and flexibility. We expect to focus on creating convenient universal API first and then work on increasing performance for specific cases. We expect the worst KMath benchmarks will perform better than native Python, but worse than optimized native/SciPy (mostly due to boxing operations on primitive numbers). The best performance of optimized parts could be better than SciPy.
+Calculation performance is one of major goals of KMath in the future, but in some cases it is impossible to achieve
+both performance and flexibility.
-### Dependency
+We expect to focus on creating convenient universal API first and then work on increasing performance for specific
+cases. We expect the worst KMath benchmarks will perform better than native Python, but worse than optimized
+native/SciPy (mostly due to boxing operations on primitive numbers). The best performance of optimized parts could be
+better than SciPy.
-Release artifacts are accessible from bintray with following configuration (see documentation for [kotlin-multiplatform](https://kotlinlang.org/docs/reference/multiplatform.html) form more details):
+### Repositories
+
+Release artifacts are accessible from bintray with following configuration (see documentation of
+[Kotlin Multiplatform](https://kotlinlang.org/docs/reference/multiplatform.html) for more details):
```kotlin
-repositories{
+repositories {
maven("https://dl.bintray.com/mipt-npm/kscience")
}
-dependencies{
+dependencies {
api("kscience.kmath:kmath-core:$version")
- //api("kscience.kmath:kmath-core-jvm:$version") for jvm-specific version
+ // api("kscience.kmath:kmath-core-jvm:$version") for jvm-specific version
}
```
Gradle `6.0+` is required for multiplatform artifacts.
-### Development
+#### Development
+
+Development builds are uploaded to the separate repository:
-Development builds are accessible from the reposirtory
```kotlin
-repositories{
+repositories {
maven("https://dl.bintray.com/mipt-npm/dev")
}
```
-with the same artifact names.
## Contributing
-The project requires a lot of additional work. The most important thing we need is a feedback about what features are required the most. Feel free to open feature issues with requests. We are also welcome to code contributions, especially in issues marked as [waiting for a hero](https://github.com/mipt-npm/kmath/labels/waiting%20for%20a%20hero).
\ No newline at end of file
+The project requires a lot of additional work. The most important thing we need is a feedback about what features are
+required the most. Feel free to create feature requests. We are also welcome to code contributions,
+especially in issues marked with
+[waiting for a hero](https://github.com/mipt-npm/kmath/labels/waiting%20for%20a%20hero) label.
diff --git a/kmath-core/README.md b/kmath-core/README.md
index 5501b1d7a..42a513a10 100644
--- a/kmath-core/README.md
+++ b/kmath-core/README.md
@@ -12,7 +12,7 @@ The core features of KMath:
> #### Artifact:
>
-> This module artifact: `kscience.kmath:kmath-core:0.2.0-dev-2`.
+> This module artifact: `kscience.kmath:kmath-core:0.2.0-dev-3`.
>
> Bintray release version: [ ![Download](https://api.bintray.com/packages/mipt-npm/kscience/kmath-core/images/download.svg) ](https://bintray.com/mipt-npm/kscience/kmath-core/_latestVersion)
>
@@ -30,7 +30,7 @@ The core features of KMath:
> }
>
> dependencies {
-> implementation 'kscience.kmath:kmath-core:0.2.0-dev-2'
+> implementation 'kscience.kmath:kmath-core:0.2.0-dev-3'
> }
> ```
> **Gradle Kotlin DSL:**
@@ -44,6 +44,6 @@ The core features of KMath:
> }
>
> dependencies {
-> implementation("kscience.kmath:kmath-core:0.2.0-dev-2")
+> implementation("kscience.kmath:kmath-core:0.2.0-dev-3")
> }
> ```
diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts
index b0849eca5..7f889d9b4 100644
--- a/kmath-core/build.gradle.kts
+++ b/kmath-core/build.gradle.kts
@@ -1,3 +1,5 @@
+import ru.mipt.npm.gradle.Maturity
+
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.native")
@@ -11,36 +13,42 @@ kotlin.sourceSets.commonMain {
readme {
description = "Core classes, algebra definitions, basic linear algebra"
- maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT
+ maturity = Maturity.DEVELOPMENT
propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md"))
+
feature(
id = "algebras",
description = "Algebraic structures: contexts and elements",
ref = "src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt"
)
+
feature(
id = "nd",
description = "Many-dimensional structures",
ref = "src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt"
)
+
feature(
id = "buffers",
description = "One-dimensional structure",
ref = "src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt"
)
+
feature(
id = "expressions",
description = "Functional Expressions",
ref = "src/commonMain/kotlin/kscience/kmath/expressions"
)
+
feature(
id = "domains",
description = "Domains",
ref = "src/commonMain/kotlin/kscience/kmath/domains"
)
+
feature(
id = "autodif",
description = "Automatic differentiation",
ref = "src/commonMain/kotlin/kscience/kmath/expressions/SimpleAutoDiff.kt"
)
-}
\ No newline at end of file
+}
diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/Expression.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/Expression.kt
index ab9ff0e72..568de255e 100644
--- a/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/Expression.kt
+++ b/kmath-core/src/commonMain/kotlin/kscience/kmath/expressions/Expression.kt
@@ -35,20 +35,27 @@ public fun interface Expression {
}
/**
- * Invoke an expression without parameters
+ * Calls this expression without providing any arguments.
+ *
+ * @return a value.
*/
public operator fun Expression.invoke(): T = invoke(emptyMap())
-//This method exists to avoid resolution ambiguity of vararg methods
/**
* Calls this expression from arguments.
*
- * @param pairs the pair of arguments' names to values.
- * @return the value.
+ * @param pairs the pairs of arguments to values.
+ * @return a value.
*/
@JvmName("callBySymbol")
public operator fun Expression.invoke(vararg pairs: Pair): T = invoke(mapOf(*pairs))
+/**
+ * Calls this expression from arguments.
+ *
+ * @param pairs the pairs of arguments' names to values.
+ * @return a value.
+ */
@JvmName("callByString")
public operator fun Expression.invoke(vararg pairs: Pair): T =
invoke(mapOf(*pairs).mapKeys { StringSymbol(it.key) })
@@ -61,7 +68,6 @@ public operator fun Expression.invoke(vararg pairs: Pair): T =
* @param E type of the actual expression state
*/
public interface ExpressionAlgebra : Algebra {
-
/**
* Bind a given [Symbol] to this context variable and produce context-specific object. Return null if symbol could not be bound in current context.
*/
@@ -87,7 +93,7 @@ public fun ExpressionAlgebra.bind(symbol: Symbol): E =
/**
* A delegate to create a symbol with a string identity in this scope
*/
-public val symbol: ReadOnlyProperty = ReadOnlyProperty { thisRef, property ->
+public val symbol: ReadOnlyProperty = ReadOnlyProperty { _, property ->
StringSymbol(property.name)
}
@@ -96,4 +102,4 @@ public val symbol: ReadOnlyProperty = ReadOnlyProperty {
*/
public fun ExpressionAlgebra.binding(): ReadOnlyProperty = ReadOnlyProperty { _, property ->
bind(StringSymbol(property.name)) ?: error("A variable with name ${property.name} does not exist")
-}
\ No newline at end of file
+}
diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt
index c1cfcbe49..d7b019c65 100644
--- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt
+++ b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt
@@ -73,7 +73,7 @@ public interface NDAlgebra> {
public fun check(vararg elements: N): Array = elements
.map(NDStructure::shape)
.singleOrNull { !shape.contentEquals(it) }
- ?.let { throw ShapeMismatchException(shape, it) }
+ ?.let> { throw ShapeMismatchException(shape, it) }
?: elements
/**
diff --git a/kmath-nd4j/build.gradle.kts b/kmath-nd4j/build.gradle.kts
index 67569b870..953530b01 100644
--- a/kmath-nd4j/build.gradle.kts
+++ b/kmath-nd4j/build.gradle.kts
@@ -1,3 +1,5 @@
+import ru.mipt.npm.gradle.Maturity
+
plugins {
id("ru.mipt.npm.jvm")
}
@@ -9,3 +11,27 @@ dependencies {
testImplementation("org.nd4j:nd4j-native-platform:1.0.0-beta7")
testImplementation("org.slf4j:slf4j-simple:1.7.30")
}
+
+readme {
+ description = "ND4J NDStructure implementation and according NDAlgebra classes"
+ maturity = Maturity.EXPERIMENTAL
+ propertyByTemplate("artifact", rootProject.file("docs/templates/ARTIFACT-TEMPLATE.md"))
+
+ feature(
+ id = "nd4jarraystrucure",
+ description = "NDStructure wrapper for INDArray",
+ ref = "src/commonMain/kotlin/kscience/kmath/operations/Algebra.kt"
+ )
+
+ feature(
+ id = "nd4jarrayrings",
+ description = "Rings over Nd4jArrayStructure of Int and Long",
+ ref = "src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt"
+ )
+
+ feature(
+ id = "nd4jarrayfields",
+ description = "Fields over Nd4jArrayStructure of Float and Double",
+ ref = "src/commonMain/kotlin/kscience/kmath/structures/Buffers.kt"
+ )
+}
diff --git a/kmath-nd4j/docs/README-TEMPLATE.md b/kmath-nd4j/docs/README-TEMPLATE.md
new file mode 100644
index 000000000..76ce8c9a7
--- /dev/null
+++ b/kmath-nd4j/docs/README-TEMPLATE.md
@@ -0,0 +1,43 @@
+# ND4J NDStructure implementation (`kmath-nd4j`)
+
+This subproject implements the following features:
+
+${features}
+
+${artifact}
+
+## 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()
+println(array[0, 0]) // 1.0
+array[intArrayOf(0, 0)] = 24.0
+println(array[0, 0]) // 24.0
+```
+
+Fast element-wise and in-place arithmetics for INDArray:
+
+```kotlin
+import org.nd4j.linalg.factory.*
+import scientifik.kmath.nd4j.*
+import scientifik.kmath.operations.*
+
+val field = RealNd4jArrayField(intArrayOf(2, 2))
+val array = Nd4j.rand(2, 2).asRealStructure()
+
+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).
diff --git a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/INDArrayAlgebra.kt b/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/INDArrayAlgebra.kt
deleted file mode 100644
index 728ce3773..000000000
--- a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/INDArrayAlgebra.kt
+++ /dev/null
@@ -1,284 +0,0 @@
-package kscience.kmath.nd4j
-
-import org.nd4j.linalg.api.ndarray.INDArray
-import org.nd4j.linalg.factory.Nd4j
-import kscience.kmath.operations.*
-import kscience.kmath.structures.*
-
-/**
- * Represents [NDAlgebra] over [INDArrayAlgebra].
- *
- * @param T the type of ND-structure element.
- * @param C the type of the element context.
- */
-public interface INDArrayAlgebra : NDAlgebra> {
- /**
- * Wraps [INDArray] to [N].
- */
- public fun INDArray.wrap(): INDArrayStructure
-
- public override fun produce(initializer: C.(IntArray) -> T): INDArrayStructure {
- val struct = Nd4j.create(*shape)!!.wrap()
- struct.indicesIterator().forEach { struct[it] = elementContext.initializer(it) }
- return struct
- }
-
- public override fun map(arg: INDArrayStructure, transform: C.(T) -> T): INDArrayStructure {
- check(arg)
- val newStruct = arg.ndArray.dup().wrap()
- newStruct.elements().forEach { (idx, value) -> newStruct[idx] = elementContext.transform(value) }
- return newStruct
- }
-
- public override fun mapIndexed(
- arg: INDArrayStructure,
- transform: C.(index: IntArray, T) -> T
- ): INDArrayStructure {
- check(arg)
- val new = Nd4j.create(*shape).wrap()
- new.indicesIterator().forEach { idx -> new[idx] = elementContext.transform(idx, arg[idx]) }
- return new
- }
-
- public override fun combine(
- a: INDArrayStructure,
- b: INDArrayStructure,
- transform: C.(T, T) -> T
- ): INDArrayStructure {
- check(a, b)
- val new = Nd4j.create(*shape).wrap()
- new.indicesIterator().forEach { idx -> new[idx] = elementContext.transform(a[idx], b[idx]) }
- return new
- }
-}
-
-/**
- * Represents [NDSpace] over [INDArrayStructure].
- *
- * @param T the type of the element contained in ND structure.
- * @param S the type of space of structure elements.
- */
-public interface INDArraySpace : NDSpace>, INDArrayAlgebra where S : Space {
- public override val zero: INDArrayStructure
- get() = Nd4j.zeros(*shape).wrap()
-
- public override fun add(a: INDArrayStructure, b: INDArrayStructure): INDArrayStructure {
- check(a, b)
- return a.ndArray.add(b.ndArray).wrap()
- }
-
- public override operator fun INDArrayStructure.minus(b: INDArrayStructure): INDArrayStructure {
- check(this, b)
- return ndArray.sub(b.ndArray).wrap()
- }
-
- public override operator fun INDArrayStructure.unaryMinus(): INDArrayStructure {
- check(this)
- return ndArray.neg().wrap()
- }
-
- public override fun multiply(a: INDArrayStructure, k: Number): INDArrayStructure {
- check(a)
- return a.ndArray.mul(k).wrap()
- }
-
- public override operator fun INDArrayStructure.div(k: Number): INDArrayStructure {
- check(this)
- return ndArray.div(k).wrap()
- }
-
- public override operator fun INDArrayStructure.times(k: Number): INDArrayStructure {
- check(this)
- return ndArray.mul(k).wrap()
- }
-}
-
-/**
- * Represents [NDRing] over [INDArrayStructure].
- *
- * @param T the type of the element contained in ND structure.
- * @param R the type of ring of structure elements.
- */
-public interface INDArrayRing : NDRing>, INDArraySpace where R : Ring {
- public override val one: INDArrayStructure
- get() = Nd4j.ones(*shape).wrap()
-
- public override fun multiply(a: INDArrayStructure, b: INDArrayStructure): INDArrayStructure {
- check(a, b)
- return a.ndArray.mul(b.ndArray).wrap()
- }
-
- public override operator fun INDArrayStructure.minus(b: Number): INDArrayStructure {
- check(this)
- return ndArray.sub(b).wrap()
- }
-
- public override operator fun INDArrayStructure.plus(b: Number): INDArrayStructure {
- check(this)
- return ndArray.add(b).wrap()
- }
-
- public override operator fun Number.minus(b: INDArrayStructure): INDArrayStructure {
- check(b)
- return b.ndArray.rsub(this).wrap()
- }
-}
-
-/**
- * Represents [NDField] over [INDArrayStructure].
- *
- * @param T the type of the element contained in ND structure.
- * @param N the type of ND structure.
- * @param F the type field of structure elements.
- */
-public interface INDArrayField : NDField>, INDArrayRing where F : Field {
- public override fun divide(a: INDArrayStructure, b: INDArrayStructure): INDArrayStructure {
- check(a, b)
- return a.ndArray.div(b.ndArray).wrap()
- }
-
- public override operator fun Number.div(b: INDArrayStructure): INDArrayStructure {
- check(b)
- return b.ndArray.rdiv(this).wrap()
- }
-}
-
-/**
- * Represents [NDField] over [INDArrayRealStructure].
- */
-public class RealINDArrayField(public override val shape: IntArray) : INDArrayField {
- public override val elementContext: RealField
- get() = RealField
-
- public override fun INDArray.wrap(): INDArrayStructure = check(asRealStructure())
-
- public override operator fun INDArrayStructure.div(arg: Double): INDArrayStructure {
- check(this)
- return ndArray.div(arg).wrap()
- }
-
- public override operator fun INDArrayStructure.plus(arg: Double): INDArrayStructure {
- check(this)
- return ndArray.add(arg).wrap()
- }
-
- public override operator fun INDArrayStructure.minus(arg: Double): INDArrayStructure {
- check(this)
- return ndArray.sub(arg).wrap()
- }
-
- public override operator fun INDArrayStructure.times(arg: Double): INDArrayStructure {
- check(this)
- return ndArray.mul(arg).wrap()
- }
-
- public override operator fun Double.div(arg: INDArrayStructure): INDArrayStructure {
- check(arg)
- return arg.ndArray.rdiv(this).wrap()
- }
-
- public override operator fun Double.minus(arg: INDArrayStructure): INDArrayStructure {
- check(arg)
- return arg.ndArray.rsub(this).wrap()
- }
-}
-
-/**
- * Represents [NDField] over [INDArrayStructure] of [Float].
- */
-public class FloatINDArrayField(public override val shape: IntArray) : INDArrayField {
- public override val elementContext: FloatField
- get() = FloatField
-
- public override fun INDArray.wrap(): INDArrayStructure = check(asFloatStructure())
-
- public override operator fun INDArrayStructure.div(arg: Float): INDArrayStructure {
- check(this)
- return ndArray.div(arg).wrap()
- }
-
- public override operator fun INDArrayStructure.plus(arg: Float): INDArrayStructure {
- check(this)
- return ndArray.add(arg).wrap()
- }
-
- public override operator fun INDArrayStructure.minus(arg: Float): INDArrayStructure {
- check(this)
- return ndArray.sub(arg).wrap()
- }
-
- public override operator fun INDArrayStructure.times(arg: Float): INDArrayStructure {
- check(this)
- return ndArray.mul(arg).wrap()
- }
-
- public override operator fun Float.div(arg: INDArrayStructure): INDArrayStructure {
- check(arg)
- return arg.ndArray.rdiv(this).wrap()
- }
-
- public override operator fun Float.minus(arg: INDArrayStructure): INDArrayStructure {
- check(arg)
- return arg.ndArray.rsub(this).wrap()
- }
-}
-
-/**
- * Represents [NDRing] over [INDArrayIntStructure].
- */
-public class IntINDArrayRing(public override val shape: IntArray) : INDArrayRing {
- public override val elementContext: IntRing
- get() = IntRing
-
- public override fun INDArray.wrap(): INDArrayStructure = check(asIntStructure())
-
- public override operator fun INDArrayStructure.plus(arg: Int): INDArrayStructure {
- check(this)
- return ndArray.add(arg).wrap()
- }
-
- public override operator fun INDArrayStructure.minus(arg: Int): INDArrayStructure {
- check(this)
- return ndArray.sub(arg).wrap()
- }
-
- public override operator fun INDArrayStructure.times(arg: Int): INDArrayStructure {
- check(this)
- return ndArray.mul(arg).wrap()
- }
-
- public override operator fun Int.minus(arg: INDArrayStructure): INDArrayStructure {
- check(arg)
- return arg.ndArray.rsub(this).wrap()
- }
-}
-
-/**
- * Represents [NDRing] over [INDArrayStructure] of [Long].
- */
-public class LongINDArrayRing(public override val shape: IntArray) : INDArrayRing {
- public override val elementContext: LongRing
- get() = LongRing
-
- public override fun INDArray.wrap(): INDArrayStructure = check(asLongStructure())
-
- public override operator fun INDArrayStructure.plus(arg: Long): INDArrayStructure {
- check(this)
- return ndArray.add(arg).wrap()
- }
-
- public override operator fun INDArrayStructure.minus(arg: Long): INDArrayStructure {
- check(this)
- return ndArray.sub(arg).wrap()
- }
-
- public override operator fun INDArrayStructure.times(arg: Long): INDArrayStructure {
- check(this)
- return ndArray.mul(arg).wrap()
- }
-
- public override operator fun Long.minus(arg: INDArrayStructure): INDArrayStructure {
- check(arg)
- return arg.ndArray.rsub(this).wrap()
- }
-}
diff --git a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayAlgebra.kt b/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayAlgebra.kt
new file mode 100644
index 000000000..2093a3cb3
--- /dev/null
+++ b/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayAlgebra.kt
@@ -0,0 +1,288 @@
+package kscience.kmath.nd4j
+
+import kscience.kmath.operations.*
+import kscience.kmath.structures.NDAlgebra
+import kscience.kmath.structures.NDField
+import kscience.kmath.structures.NDRing
+import kscience.kmath.structures.NDSpace
+import org.nd4j.linalg.api.ndarray.INDArray
+import org.nd4j.linalg.factory.Nd4j
+
+/**
+ * Represents [NDAlgebra] over [Nd4jArrayAlgebra].
+ *
+ * @param T the type of ND-structure element.
+ * @param C the type of the element context.
+ */
+public interface Nd4jArrayAlgebra : NDAlgebra> {
+ /**
+ * Wraps [INDArray] to [N].
+ */
+ public fun INDArray.wrap(): Nd4jArrayStructure
+
+ public override fun produce(initializer: C.(IntArray) -> T): Nd4jArrayStructure {
+ val struct = Nd4j.create(*shape)!!.wrap()
+ struct.indicesIterator().forEach { struct[it] = elementContext.initializer(it) }
+ return struct
+ }
+
+ public override fun map(arg: Nd4jArrayStructure, transform: C.(T) -> T): Nd4jArrayStructure {
+ check(arg)
+ val newStruct = arg.ndArray.dup().wrap()
+ newStruct.elements().forEach { (idx, value) -> newStruct[idx] = elementContext.transform(value) }
+ return newStruct
+ }
+
+ public override fun mapIndexed(
+ arg: Nd4jArrayStructure,
+ transform: C.(index: IntArray, T) -> T
+ ): Nd4jArrayStructure {
+ check(arg)
+ val new = Nd4j.create(*shape).wrap()
+ new.indicesIterator().forEach { idx -> new[idx] = elementContext.transform(idx, arg[idx]) }
+ return new
+ }
+
+ public override fun combine(
+ a: Nd4jArrayStructure,
+ b: Nd4jArrayStructure,
+ transform: C.(T, T) -> T
+ ): Nd4jArrayStructure {
+ check(a, b)
+ val new = Nd4j.create(*shape).wrap()
+ new.indicesIterator().forEach { idx -> new[idx] = elementContext.transform(a[idx], b[idx]) }
+ return new
+ }
+}
+
+/**
+ * Represents [NDSpace] over [Nd4jArrayStructure].
+ *
+ * @param T the type of the element contained in ND structure.
+ * @param S the type of space of structure elements.
+ */
+public interface Nd4jArraySpace : NDSpace>,
+ Nd4jArrayAlgebra where S : Space {
+ public override val zero: Nd4jArrayStructure
+ get() = Nd4j.zeros(*shape).wrap()
+
+ public override fun add(a: Nd4jArrayStructure, b: Nd4jArrayStructure): Nd4jArrayStructure {
+ check(a, b)
+ return a.ndArray.add(b.ndArray).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.minus(b: Nd4jArrayStructure): Nd4jArrayStructure {
+ check(this, b)
+ return ndArray.sub(b.ndArray).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.unaryMinus(): Nd4jArrayStructure {
+ check(this)
+ return ndArray.neg().wrap()
+ }
+
+ public override fun multiply(a: Nd4jArrayStructure, k: Number): Nd4jArrayStructure {
+ check(a)
+ return a.ndArray.mul(k).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.div(k: Number): Nd4jArrayStructure {
+ check(this)
+ return ndArray.div(k).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.times(k: Number): Nd4jArrayStructure {
+ check(this)
+ return ndArray.mul(k).wrap()
+ }
+}
+
+/**
+ * Represents [NDRing] over [Nd4jArrayStructure].
+ *
+ * @param T the type of the element contained in ND structure.
+ * @param R the type of ring of structure elements.
+ */
+public interface Nd4jArrayRing : NDRing>, Nd4jArraySpace where R : Ring {
+ public override val one: Nd4jArrayStructure
+ get() = Nd4j.ones(*shape).wrap()
+
+ public override fun multiply(a: Nd4jArrayStructure, b: Nd4jArrayStructure): Nd4jArrayStructure {
+ check(a, b)
+ return a.ndArray.mul(b.ndArray).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.minus(b: Number): Nd4jArrayStructure {
+ check(this)
+ return ndArray.sub(b).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.plus(b: Number): Nd4jArrayStructure {
+ check(this)
+ return ndArray.add(b).wrap()
+ }
+
+ public override operator fun Number.minus(b: Nd4jArrayStructure): Nd4jArrayStructure {
+ check(b)
+ return b.ndArray.rsub(this).wrap()
+ }
+}
+
+/**
+ * Represents [NDField] over [Nd4jArrayStructure].
+ *
+ * @param T the type of the element contained in ND structure.
+ * @param N the type of ND structure.
+ * @param F the type field of structure elements.
+ */
+public interface Nd4jArrayField : NDField>, Nd4jArrayRing where F : Field {
+ public override fun divide(a: Nd4jArrayStructure, b: Nd4jArrayStructure): Nd4jArrayStructure {
+ check(a, b)
+ return a.ndArray.div(b.ndArray).wrap()
+ }
+
+ public override operator fun Number.div(b: Nd4jArrayStructure): Nd4jArrayStructure {
+ check(b)
+ return b.ndArray.rdiv(this).wrap()
+ }
+}
+
+/**
+ * Represents [NDField] over [Nd4jArrayRealStructure].
+ */
+public class RealNd4jArrayField(public override val shape: IntArray) : Nd4jArrayField {
+ public override val elementContext: RealField
+ get() = RealField
+
+ public override fun INDArray.wrap(): Nd4jArrayStructure = check(asRealStructure())
+
+ public override operator fun Nd4jArrayStructure.div(arg: Double): Nd4jArrayStructure {
+ check(this)
+ return ndArray.div(arg).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.plus(arg: Double): Nd4jArrayStructure {
+ check(this)
+ return ndArray.add(arg).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.minus(arg: Double): Nd4jArrayStructure {
+ check(this)
+ return ndArray.sub(arg).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.times(arg: Double): Nd4jArrayStructure {
+ check(this)
+ return ndArray.mul(arg).wrap()
+ }
+
+ public override operator fun Double.div(arg: Nd4jArrayStructure): Nd4jArrayStructure {
+ check(arg)
+ return arg.ndArray.rdiv(this).wrap()
+ }
+
+ public override operator fun Double.minus(arg: Nd4jArrayStructure): Nd4jArrayStructure {
+ check(arg)
+ return arg.ndArray.rsub(this).wrap()
+ }
+}
+
+/**
+ * Represents [NDField] over [Nd4jArrayStructure] of [Float].
+ */
+public class FloatNd4jArrayField(public override val shape: IntArray) : Nd4jArrayField {
+ public override val elementContext: FloatField
+ get() = FloatField
+
+ public override fun INDArray.wrap(): Nd4jArrayStructure = check(asFloatStructure())
+
+ public override operator fun Nd4jArrayStructure.div(arg: Float): Nd4jArrayStructure {
+ check(this)
+ return ndArray.div(arg).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.plus(arg: Float): Nd4jArrayStructure {
+ check(this)
+ return ndArray.add(arg).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.minus(arg: Float): Nd4jArrayStructure {
+ check(this)
+ return ndArray.sub(arg).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.times(arg: Float): Nd4jArrayStructure {
+ check(this)
+ return ndArray.mul(arg).wrap()
+ }
+
+ public override operator fun Float.div(arg: Nd4jArrayStructure): Nd4jArrayStructure {
+ check(arg)
+ return arg.ndArray.rdiv(this).wrap()
+ }
+
+ public override operator fun Float.minus(arg: Nd4jArrayStructure): Nd4jArrayStructure {
+ check(arg)
+ return arg.ndArray.rsub(this).wrap()
+ }
+}
+
+/**
+ * Represents [NDRing] over [Nd4jArrayIntStructure].
+ */
+public class IntNd4jArrayRing(public override val shape: IntArray) : Nd4jArrayRing {
+ public override val elementContext: IntRing
+ get() = IntRing
+
+ public override fun INDArray.wrap(): Nd4jArrayStructure = check(asIntStructure())
+
+ public override operator fun Nd4jArrayStructure.plus(arg: Int): Nd4jArrayStructure {
+ check(this)
+ return ndArray.add(arg).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.minus(arg: Int): Nd4jArrayStructure {
+ check(this)
+ return ndArray.sub(arg).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.times(arg: Int): Nd4jArrayStructure {
+ check(this)
+ return ndArray.mul(arg).wrap()
+ }
+
+ public override operator fun Int.minus(arg: Nd4jArrayStructure): Nd4jArrayStructure {
+ check(arg)
+ return arg.ndArray.rsub(this).wrap()
+ }
+}
+
+/**
+ * Represents [NDRing] over [Nd4jArrayStructure] of [Long].
+ */
+public class LongNd4jArrayRing(public override val shape: IntArray) : Nd4jArrayRing {
+ public override val elementContext: LongRing
+ get() = LongRing
+
+ public override fun INDArray.wrap(): Nd4jArrayStructure = check(asLongStructure())
+
+ public override operator fun Nd4jArrayStructure.plus(arg: Long): Nd4jArrayStructure {
+ check(this)
+ return ndArray.add(arg).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.minus(arg: Long): Nd4jArrayStructure {
+ check(this)
+ return ndArray.sub(arg).wrap()
+ }
+
+ public override operator fun Nd4jArrayStructure.times(arg: Long): Nd4jArrayStructure {
+ check(this)
+ return ndArray.mul(arg).wrap()
+ }
+
+ public override operator fun Long.minus(arg: Nd4jArrayStructure): Nd4jArrayStructure {
+ check(arg)
+ return arg.ndArray.rsub(this).wrap()
+ }
+}
diff --git a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/INDArrayIterators.kt b/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayIterator.kt
similarity index 63%
rename from kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/INDArrayIterators.kt
rename to kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayIterator.kt
index 9e7ef9e16..1463a92fe 100644
--- a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/INDArrayIterators.kt
+++ b/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayIterator.kt
@@ -3,7 +3,7 @@ package kscience.kmath.nd4j
import org.nd4j.linalg.api.ndarray.INDArray
import org.nd4j.linalg.api.shape.Shape
-private class INDArrayIndicesIterator(private val iterateOver: INDArray) : Iterator {
+private class Nd4jArrayIndicesIterator(private val iterateOver: INDArray) : Iterator {
private var i: Int = 0
override fun hasNext(): Boolean = i < iterateOver.length()
@@ -18,9 +18,9 @@ private class INDArrayIndicesIterator(private val iterateOver: INDArray) : Itera
}
}
-internal fun INDArray.indicesIterator(): Iterator = INDArrayIndicesIterator(this)
+internal fun INDArray.indicesIterator(): Iterator = Nd4jArrayIndicesIterator(this)
-private sealed class INDArrayIteratorBase(protected val iterateOver: INDArray) : Iterator> {
+private sealed class Nd4jArrayIteratorBase(protected val iterateOver: INDArray) : Iterator> {
private var i: Int = 0
final override fun hasNext(): Boolean = i < iterateOver.length()
@@ -37,26 +37,26 @@ private sealed class INDArrayIteratorBase(protected val iterateOver: INDArray
}
}
-private class INDArrayRealIterator(iterateOver: INDArray) : INDArrayIteratorBase(iterateOver) {
+private class Nd4jArrayRealIterator(iterateOver: INDArray) : Nd4jArrayIteratorBase(iterateOver) {
override fun getSingle(indices: LongArray): Double = iterateOver.getDouble(*indices)
}
-internal fun INDArray.realIterator(): Iterator> = INDArrayRealIterator(this)
+internal fun INDArray.realIterator(): Iterator> = Nd4jArrayRealIterator(this)
-private class INDArrayLongIterator(iterateOver: INDArray) : INDArrayIteratorBase(iterateOver) {
+private class Nd4jArrayLongIterator(iterateOver: INDArray) : Nd4jArrayIteratorBase(iterateOver) {
override fun getSingle(indices: LongArray) = iterateOver.getLong(*indices)
}
-internal fun INDArray.longIterator(): Iterator> = INDArrayLongIterator(this)
+internal fun INDArray.longIterator(): Iterator> = Nd4jArrayLongIterator(this)
-private class INDArrayIntIterator(iterateOver: INDArray) : INDArrayIteratorBase(iterateOver) {
+private class Nd4jArrayIntIterator(iterateOver: INDArray) : Nd4jArrayIteratorBase(iterateOver) {
override fun getSingle(indices: LongArray) = iterateOver.getInt(*indices.toIntArray())
}
-internal fun INDArray.intIterator(): Iterator> = INDArrayIntIterator(this)
+internal fun INDArray.intIterator(): Iterator> = Nd4jArrayIntIterator(this)
-private class INDArrayFloatIterator(iterateOver: INDArray) : INDArrayIteratorBase(iterateOver) {
+private class Nd4jArrayFloatIterator(iterateOver: INDArray) : Nd4jArrayIteratorBase(iterateOver) {
override fun getSingle(indices: LongArray) = iterateOver.getFloat(*indices)
}
-internal fun INDArray.floatIterator(): Iterator> = INDArrayFloatIterator(this)
+internal fun INDArray.floatIterator(): Iterator> = Nd4jArrayFloatIterator(this)
diff --git a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/INDArrayStructures.kt b/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayStructure.kt
similarity index 63%
rename from kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/INDArrayStructures.kt
rename to kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayStructure.kt
index 5d4e1a979..d47a293c3 100644
--- a/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/INDArrayStructures.kt
+++ b/kmath-nd4j/src/main/kotlin/kscience.kmath.nd4j/Nd4jArrayStructure.kt
@@ -1,15 +1,15 @@
package kscience.kmath.nd4j
-import org.nd4j.linalg.api.ndarray.INDArray
import kscience.kmath.structures.MutableNDStructure
import kscience.kmath.structures.NDStructure
+import org.nd4j.linalg.api.ndarray.INDArray
/**
* Represents a [NDStructure] wrapping an [INDArray] object.
*
* @param T the type of items.
*/
-public sealed class INDArrayStructure