diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 05c1c603e..cbf13d03d 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -44,11 +44,9 @@ jobs:
run: >
./gradlew release --no-daemon -Ppublishing.enabled=true -Ppublishing.space.user=${{ secrets.SPACE_APP_ID }}
-Ppublishing.space.token=${{ secrets.SPACE_APP_SECRET }}
- -Ppublishing.sonatype=false
- name: Publish Mac Artifacts
if: matrix.os == 'macOS-latest'
run: >
./gradlew release --no-daemon -Ppublishing.enabled=true -Ppublishing.platform=macosX64
-Ppublishing.space.user=${{ secrets.SPACE_APP_ID }}
-Ppublishing.space.token=${{ secrets.SPACE_APP_SECRET }}
- -Ppublishing.sonatype=false
diff --git a/README.md b/README.md
index 7645256d9..a15c4384f 100644
--- a/README.md
+++ b/README.md
@@ -132,7 +132,7 @@ KMath is a modular library. Different modules provide different features with di
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.
> - [domains](kmath-core/src/commonMain/kotlin/space/kscience/kmath/domains) : Domains
-> - [autodif](kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt) : Automatic differentiation
+> - [autodiff](kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt) : Automatic differentiation
@@ -222,8 +222,8 @@ One can still use generic algebras though.
> **Maturity**: EXPERIMENTAL
>
> **Features:**
-> - [differentiable-mst-expression](kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt) : MST based DifferentiableExpression.
-> - [differentiable-mst-expression](kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt) : Conversions between Kotlin∇'s SFun and MST
+> - [differentiable-mst-expression](kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/KotlingradExpression.kt) : MST based DifferentiableExpression.
+> - [scalars-adapters](kmath-kotlingrad/src/main/kotlin/space/kscience/kmath/kotlingrad/scalarsAdapters.kt) : Conversions between Kotlin∇'s SFun and MST
@@ -264,7 +264,7 @@ One can still use generic algebras though.
>
> **Features:**
> - [tensor algebra](kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/TensorAlgebra.kt) : Basic linear algebra operations on tensors (plus, dot, etc.)
-> - [tensor algebra with broadcasting](kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/algebras/BroadcastDoubleTensorAlgebra.kt) : Basic linear algebra operations implemented with broadcasting.
+> - [tensor algebra with broadcasting](kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/BroadcastDoubleTensorAlgebra.kt) : Basic linear algebra operations implemented with broadcasting.
> - [linear algebra operations](kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/LinearOpsTensorAlgebra.kt) : Advanced linear algebra operations like LU decomposition, SVD, etc.
diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt
index c28b566b9..955f86fa9 100644
--- a/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt
+++ b/examples/src/main/kotlin/space/kscience/kmath/structures/typeSafeDimensions.kt
@@ -19,7 +19,7 @@ private fun DMatrixContext.simple() {
}
private object D5 : Dimension {
- override val dim: Int = 5
+ override val dim: UInt = 5u
}
private fun DMatrixContext.custom() {
diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt
index 6aeebb68c..afbfd9a24 100644
--- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt
+++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt
@@ -8,7 +8,6 @@ package space.kscience.kmath.commons.random
import kotlinx.coroutines.runBlocking
import space.kscience.kmath.misc.PerformancePitfall
import space.kscience.kmath.samplers.GaussianSampler
-import space.kscience.kmath.misc.toIntExact
import space.kscience.kmath.stat.RandomGenerator
import space.kscience.kmath.stat.next
@@ -29,7 +28,7 @@ public class CMRandomGeneratorWrapper(
}
override fun setSeed(seed: Long) {
- setSeed(seed.toIntExact())
+ setSeed(seed.toInt())
}
override fun nextBytes(bytes: ByteArray) {
diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/numbers.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/numbers.kt
deleted file mode 100644
index f879a06d5..000000000
--- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/numbers.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
- */
-
-package space.kscience.kmath.misc
-
-public expect fun Long.toIntExact(): Int
diff --git a/kmath-core/src/jsMain/kotlin/space/kscience/kmath/misc/numbers.kt b/kmath-core/src/jsMain/kotlin/space/kscience/kmath/misc/numbers.kt
deleted file mode 100644
index 68a3c995b..000000000
--- a/kmath-core/src/jsMain/kotlin/space/kscience/kmath/misc/numbers.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
- */
-
-package space.kscience.kmath.misc
-
-public actual fun Long.toIntExact(): Int {
- val i = toInt()
- if (i.toLong() == this) throw ArithmeticException("integer overflow")
- return i
-}
diff --git a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/misc/numbersJVM.kt b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/misc/numbersJVM.kt
deleted file mode 100644
index 5ba0dbc9b..000000000
--- a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/misc/numbersJVM.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
- */
-
-package space.kscience.kmath.misc
-
-public actual fun Long.toIntExact(): Int = Math.toIntExact(this)
diff --git a/kmath-core/src/nativeMain/kotlin/space/kscience/kmath/misc/numbers.kt b/kmath-core/src/nativeMain/kotlin/space/kscience/kmath/misc/numbers.kt
deleted file mode 100644
index 68a3c995b..000000000
--- a/kmath-core/src/nativeMain/kotlin/space/kscience/kmath/misc/numbers.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * Copyright 2018-2021 KMath contributors.
- * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
- */
-
-package space.kscience.kmath.misc
-
-public actual fun Long.toIntExact(): Int {
- val i = toInt()
- if (i.toLong() == this) throw ArithmeticException("integer overflow")
- return i
-}
diff --git a/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt b/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimensions.kt
similarity index 67%
rename from kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt
rename to kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimensions.kt
index e57c22834..8b17d252f 100644
--- a/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt
+++ b/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Dimensions.kt
@@ -8,47 +8,47 @@ package space.kscience.kmath.dimensions
import kotlin.reflect.KClass
/**
- * Represents a quantity of dimensions in certain structure. **This interface must be implemented only by objects.**
+ * Represents a quantity of dimensions in certain structure.
*
* @property dim The number of dimensions.
*/
public interface Dimension {
- public val dim: Int
+ public val dim: UInt
public companion object
}
-public fun KClass.dim(): Int = Dimension.resolve(this).dim
+public fun KClass.dim(): UInt = Dimension.resolve(this).dim
public expect fun Dimension.Companion.resolve(type: KClass): D
/**
* Finds or creates [Dimension] with [Dimension.dim] equal to [dim].
*/
-public expect fun Dimension.Companion.of(dim: Int): Dimension
+public expect fun Dimension.Companion.of(dim: UInt): Dimension
/**
* Finds [Dimension.dim] of given type [D].
*/
-public inline fun Dimension.Companion.dim(): Int = D::class.dim()
+public inline fun Dimension.Companion.dim(): UInt = D::class.dim()
/**
* Type representing 1 dimension.
*/
public object D1 : Dimension {
- override val dim: Int get() = 1
+ override val dim: UInt get() = 1U
}
/**
* Type representing 2 dimensions.
*/
public object D2 : Dimension {
- override val dim: Int get() = 2
+ override val dim: UInt get() = 2U
}
/**
* Type representing 3 dimensions.
*/
public object D3 : Dimension {
- override val dim: Int get() = 3
+ override val dim: UInt get() = 3U
}
diff --git a/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Wrappers.kt b/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Wrappers.kt
index deb297913..a2ee14301 100644
--- a/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Wrappers.kt
+++ b/kmath-dimensions/src/commonMain/kotlin/space/kscience/kmath/dimensions/Wrappers.kt
@@ -23,11 +23,11 @@ public interface DMatrix : Structure2D {
* Coerces a regular matrix to a matrix with type-safe dimensions and throws a error if coercion failed
*/
public inline fun coerce(structure: Structure2D): DMatrix {
- require(structure.rowNum == Dimension.dim()) {
+ require(structure.rowNum == Dimension.dim().toInt()) {
"Row number mismatch: expected ${Dimension.dim()} but found ${structure.rowNum}"
}
- require(structure.colNum == Dimension.dim()) {
+ require(structure.colNum == Dimension.dim().toInt()) {
"Column number mismatch: expected ${Dimension.dim()} but found ${structure.colNum}"
}
@@ -61,7 +61,7 @@ public value class DMatrixWrapper(
public interface DPoint : Point {
public companion object {
public inline fun coerce(point: Point): DPoint {
- require(point.size == Dimension.dim()) {
+ require(point.size == Dimension.dim().toInt()) {
"Vector dimension mismatch: expected ${Dimension.dim()}, but found ${point.size}"
}
@@ -92,11 +92,11 @@ public value class DPointWrapper(public val point: Point>(public val context: LinearSpace) {
public inline fun Matrix.coerce(): DMatrix {
- require(rowNum == Dimension.dim()) {
+ require(rowNum == Dimension.dim().toInt()) {
"Row number mismatch: expected ${Dimension.dim()} but found $rowNum"
}
- require(colNum == Dimension.dim()) {
+ require(colNum == Dimension.dim().toInt()) {
"Column number mismatch: expected ${Dimension.dim()} but found $colNum"
}
@@ -111,7 +111,7 @@ public value class DMatrixContext>(public val context:
): DMatrix {
val rows = Dimension.dim()
val cols = Dimension.dim()
- return context.buildMatrix(rows, cols, initializer).coerce()
+ return context.buildMatrix(rows.toInt(), cols.toInt(), initializer).coerce()
}
public inline fun point(noinline initializer: A.(Int) -> T): DPoint {
@@ -119,7 +119,7 @@ public value class DMatrixContext>(public val context:
return DPoint.coerceUnsafe(
context.buildVector(
- size,
+ size.toInt(),
initializer
)
)
@@ -167,4 +167,4 @@ public inline fun DMatrixContext.on
public inline fun DMatrixContext.zero(): DMatrix =
produce { _, _ ->
0.0
- }
+ }
\ No newline at end of file
diff --git a/kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt b/kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/dimJs.kt
similarity index 62%
rename from kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt
rename to kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/dimJs.kt
index 610e8b4c0..27912f5bc 100644
--- a/kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt
+++ b/kmath-dimensions/src/jsMain/kotlin/space/kscience/kmath/dimensions/dimJs.kt
@@ -7,17 +7,17 @@ package space.kscience.kmath.dimensions
import kotlin.reflect.KClass
-private val dimensionMap: MutableMap = hashMapOf(1 to D1, 2 to D2, 3 to D3)
+private val dimensionMap: MutableMap = hashMapOf(1u to D1, 2u to D2, 3u to D3)
@Suppress("UNCHECKED_CAST")
public actual fun Dimension.Companion.resolve(type: KClass): D = dimensionMap
.entries
- .map(MutableMap.MutableEntry::value)
+ .map(MutableMap.MutableEntry::value)
.find { it::class == type } as? D
?: error("Can't resolve dimension $type")
-public actual fun Dimension.Companion.of(dim: Int): Dimension = dimensionMap.getOrPut(dim) {
+public actual fun Dimension.Companion.of(dim: UInt): Dimension = dimensionMap.getOrPut(dim) {
object : Dimension {
- override val dim: Int get() = dim
+ override val dim: UInt get() = dim
}
}
diff --git a/kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt b/kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/dimJvm.kt
similarity index 69%
rename from kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt
rename to kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/dimJvm.kt
index e6d8b3b35..f21a3e18f 100644
--- a/kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt
+++ b/kmath-dimensions/src/jvmMain/kotlin/space/kscience/kmath/dimensions/dimJvm.kt
@@ -3,8 +3,6 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
-@file:JvmName("DimensionJVM")
-
package space.kscience.kmath.dimensions
import kotlin.reflect.KClass
@@ -12,12 +10,12 @@ import kotlin.reflect.KClass
public actual fun Dimension.Companion.resolve(type: KClass): D =
type.objectInstance ?: error("No object instance for dimension class")
-public actual fun Dimension.Companion.of(dim: Int): Dimension = when (dim) {
- 1 -> D1
- 2 -> D2
- 3 -> D3
+public actual fun Dimension.Companion.of(dim: UInt): Dimension = when (dim) {
+ 1u -> D1
+ 2u -> D2
+ 3u -> D3
else -> object : Dimension {
- override val dim: Int get() = dim
+ override val dim: UInt get() = dim
}
-}
+}
\ No newline at end of file
diff --git a/kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt b/kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/dimNative.kt
similarity index 65%
rename from kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt
rename to kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/dimNative.kt
index 64edbe935..9aa58e64a 100644
--- a/kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/Dimension.kt
+++ b/kmath-dimensions/src/nativeMain/kotlin/space/kscience/kmath/dimensions/dimNative.kt
@@ -9,17 +9,17 @@ import kotlin.native.concurrent.ThreadLocal
import kotlin.reflect.KClass
@ThreadLocal
-private val dimensionMap: MutableMap = hashMapOf(1 to D1, 2 to D2, 3 to D3)
+private val dimensionMap: MutableMap = hashMapOf(1u to D1, 2u to D2, 3u to D3)
@Suppress("UNCHECKED_CAST")
public actual fun Dimension.Companion.resolve(type: KClass): D = dimensionMap
.entries
- .map(MutableMap.MutableEntry::value)
+ .map(MutableMap.MutableEntry::value)
.find { it::class == type } as? D
?: error("Can't resolve dimension $type")
-public actual fun Dimension.Companion.of(dim: Int): Dimension = dimensionMap.getOrPut(dim) {
+public actual fun Dimension.Companion.of(dim: UInt): Dimension = dimensionMap.getOrPut(dim) {
object : Dimension {
- override val dim: Int get() = dim
+ override val dim: UInt get() = dim
}
}
diff --git a/kmath-kotlingrad/README.md b/kmath-kotlingrad/README.md
index 304a0639b..3b337460f 100644
--- a/kmath-kotlingrad/README.md
+++ b/kmath-kotlingrad/README.md
@@ -2,8 +2,8 @@
[Kotlin∇](https://www.htmlsymbols.xyz/unicode/U+2207) integration module.
- - [differentiable-mst-expression](src/main/kotlin/space/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt) : MST based DifferentiableExpression.
- - [differentiable-mst-expression](src/main/kotlin/space/kscience/kmath/kotlingrad/DifferentiableMstExpression.kt) : Conversions between Kotlin∇'s SFun and MST
+ - [differentiable-mst-expression](src/main/kotlin/space/kscience/kmath/kotlingrad/KotlingradExpression.kt) : MST based DifferentiableExpression.
+ - [scalars-adapters](src/main/kotlin/space/kscience/kmath/kotlingrad/scalarsAdapters.kt) : Conversions between Kotlin∇'s SFun and MST
## Artifact:
diff --git a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/arrays.kt b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/arrays.kt
index 3ca756600..75a334ca7 100644
--- a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/arrays.kt
+++ b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/arrays.kt
@@ -5,6 +5,4 @@
package space.kscience.kmath.nd4j
-import space.kscience.kmath.misc.toIntExact
-
-internal fun LongArray.toIntArray(): IntArray = IntArray(size) { this[it].toIntExact() }
+internal fun LongArray.toIntArray(): IntArray = IntArray(size) { this[it].toInt() }
diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/PoissonSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/PoissonSampler.kt
index 96131aa4b..2177e41ab 100644
--- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/PoissonSampler.kt
+++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/PoissonSampler.kt
@@ -7,7 +7,6 @@ package space.kscience.kmath.samplers
import space.kscience.kmath.chains.BlockingIntChain
import space.kscience.kmath.internal.InternalUtils
-import space.kscience.kmath.misc.toIntExact
import space.kscience.kmath.stat.RandomGenerator
import space.kscience.kmath.stat.Sampler
import space.kscience.kmath.structures.IntBuffer
@@ -120,7 +119,7 @@ public class LargeMeanPoissonSampler(public val mean: Double) : Sampler {
val gaussian = ZigguratNormalizedGaussianSampler.sample(generator)
val smallMeanPoissonSampler = if (mean - lambda < Double.MIN_VALUE) {
- null
+ null
} else {
KempSmallMeanPoissonSampler(mean - lambda).sample(generator)
}
@@ -189,7 +188,7 @@ public class LargeMeanPoissonSampler(public val mean: Double) : Sampler {
}
}
- return min(y2 + y.toLong(), Int.MAX_VALUE.toLong()).toIntExact()
+ return min(y2 + y.toLong(), Int.MAX_VALUE.toLong()).toInt()
}
override fun nextBufferBlocking(size: Int): IntBuffer = IntBuffer(size) { nextBlocking() }
diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/ZigguratNormalizedGaussianSampler.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/ZigguratNormalizedGaussianSampler.kt
index 81b8c3d4b..24148271d 100644
--- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/ZigguratNormalizedGaussianSampler.kt
+++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/samplers/ZigguratNormalizedGaussianSampler.kt
@@ -6,7 +6,6 @@
package space.kscience.kmath.samplers
import space.kscience.kmath.chains.BlockingDoubleChain
-import space.kscience.kmath.misc.toIntExact
import space.kscience.kmath.stat.RandomGenerator
import space.kscience.kmath.structures.DoubleBuffer
import kotlin.math.*
@@ -59,7 +58,7 @@ public object ZigguratNormalizedGaussianSampler : NormalizedGaussianSampler {
private fun sampleOne(generator: RandomGenerator): Double {
val j = generator.nextLong()
- val i = (j and LAST.toLong()).toIntExact()
+ val i = (j and LAST.toLong()).toInt()
return if (abs(j) < K[i]) j * W[i] else fix(generator, j, i)
}
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 445f75c09..18f867df3 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -5,7 +5,7 @@ pluginManagement {
gradlePluginPortal()
}
- val toolsVersion = "0.10.1"
+ val toolsVersion = "0.10.2"
val kotlinVersion = "1.5.21"
plugins {