From 646207e14031927dba9be5cd874d8ba67cc2de37 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 6 May 2020 10:50:08 +0300 Subject: [PATCH] Equlity half-fix for NDStructure --- build.gradle.kts | 4 +- examples/build.gradle.kts | 2 +- .../kmath/commons/linear/CMMatrix.kt | 11 ++++ .../scientifik/kmath/operations/BigInt.kt | 16 +++++ .../kmath/structures/BufferedNDElement.kt | 12 ++-- .../scientifik/kmath/structures/Buffers.kt | 2 +- .../kmath/structures/NDStructure.kt | 62 +++++++++---------- .../kmath/structures/Structure2D.kt | 19 ------ .../{BigNumbers.kt => bigNumbers.kt} | 23 ++----- .../kotlin/scientifik/kmath/chains/Chain.kt | 4 ++ .../kmath/structures/LazyNDStructure.kt | 14 +++++ .../scientifik/kmath/linear/RealVector.kt | 48 -------------- .../scientifik/kmath/real/RealVector.kt | 59 ++++++++++++++++++ .../scientifik/kmath/linear/VectorTest.kt | 1 + .../kmath/histogram/RealHistogram.kt | 2 +- .../histogram/MultivariateHistogramTest.kt | 2 +- .../kmath/histogram/UnivariateHistogram.kt | 4 +- .../scientifik.kmath.linear/KomaMatrix.kt | 13 ++++ settings.gradle.kts | 12 ++-- 19 files changed, 172 insertions(+), 138 deletions(-) rename kmath-core/src/jvmMain/kotlin/scientifik/kmath/operations/{BigNumbers.kt => bigNumbers.kt} (56%) delete mode 100644 kmath-for-real/src/commonMain/kotlin/scientifik/kmath/linear/RealVector.kt create mode 100644 kmath-for-real/src/commonMain/kotlin/scientifik/kmath/real/RealVector.kt diff --git a/build.gradle.kts b/build.gradle.kts index 6ab33d31c..34e87fa2a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,8 @@ plugins { - id("scientifik.publish") version "0.4.2" apply false + id("scientifik.publish") apply false } -val kmathVersion by extra("0.1.4-dev-4") +val kmathVersion by extra("0.1.4-dev-5") val bintrayRepo by extra("scientifik") val githubProject by extra("kmath") diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 8853b78a5..8ab0dd1eb 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -57,6 +57,6 @@ benchmark { tasks.withType { kotlinOptions { - jvmTarget = Scientifik.JVM_VERSION + jvmTarget = Scientifik.JVM_TARGET.toString() } } \ No newline at end of file diff --git a/kmath-commons/src/main/kotlin/scientifik/kmath/commons/linear/CMMatrix.kt b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/linear/CMMatrix.kt index 72e5fb95a..a17effccc 100644 --- a/kmath-commons/src/main/kotlin/scientifik/kmath/commons/linear/CMMatrix.kt +++ b/kmath-commons/src/main/kotlin/scientifik/kmath/commons/linear/CMMatrix.kt @@ -5,6 +5,7 @@ import org.apache.commons.math3.linear.RealMatrix import org.apache.commons.math3.linear.RealVector import scientifik.kmath.linear.* import scientifik.kmath.structures.Matrix +import scientifik.kmath.structures.NDStructure class CMMatrix(val origin: RealMatrix, features: Set? = null) : FeaturedMatrix { @@ -19,6 +20,16 @@ class CMMatrix(val origin: RealMatrix, features: Set? = null) : CMMatrix(origin, this.features + features) override fun get(i: Int, j: Int): Double = origin.getEntry(i, j) + + override fun equals(other: Any?): Boolean { + return NDStructure.equals(this, other as? NDStructure<*> ?: return false) + } + + override fun hashCode(): Int { + var result = origin.hashCode() + result = 31 * result + features.hashCode() + return result + } } fun Matrix.toCM(): CMMatrix = if (this is CMMatrix) { diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/BigInt.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/BigInt.kt index 1661170d3..5e7d49b1c 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/BigInt.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/BigInt.kt @@ -2,6 +2,7 @@ package scientifik.kmath.operations import scientifik.kmath.operations.BigInt.Companion.BASE import scientifik.kmath.operations.BigInt.Companion.BASE_SIZE +import scientifik.kmath.structures.* import kotlin.math.log2 import kotlin.math.max import kotlin.math.min @@ -482,3 +483,18 @@ fun String.parseBigInteger(): BigInt? { } return res * sign } + +inline fun Buffer.Companion.bigInt(size: Int, initializer: (Int) -> BigInt): Buffer = + boxing(size, initializer) + +inline fun MutableBuffer.Companion.bigInt(size: Int, initializer: (Int) -> BigInt): MutableBuffer = + boxing(size, initializer) + +fun NDAlgebra.Companion.bigInt(vararg shape: Int): BoxingNDRing = + BoxingNDRing(shape, BigIntField, Buffer.Companion::bigInt) + +fun NDElement.Companion.bigInt( + vararg shape: Int, + initializer: BigIntField.(IntArray) -> BigInt +): BufferedNDRingElement = + NDAlgebra.bigInt(*shape).produce(initializer) \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/BufferedNDElement.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/BufferedNDElement.kt index 04049368a..be80f66bf 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/BufferedNDElement.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/BufferedNDElement.kt @@ -3,10 +3,10 @@ package scientifik.kmath.structures import scientifik.kmath.operations.* /** - * Base interface for an element with context, containing strides + * Base class for an element with context, containing strides */ -interface BufferedNDElement : NDBuffer, NDElement> { - override val context: BufferedNDAlgebra +abstract class BufferedNDElement : NDBuffer(), NDElement> { + abstract override val context: BufferedNDAlgebra override val strides get() = context.strides @@ -16,7 +16,7 @@ interface BufferedNDElement : NDBuffer, NDElement> { class BufferedNDSpaceElement>( override val context: BufferedNDSpace, override val buffer: Buffer -) : BufferedNDElement, SpaceElement, BufferedNDSpaceElement, BufferedNDSpace> { +) : BufferedNDElement(), SpaceElement, BufferedNDSpaceElement, BufferedNDSpace> { override fun unwrap(): NDBuffer = this @@ -29,7 +29,7 @@ class BufferedNDSpaceElement>( class BufferedNDRingElement>( override val context: BufferedNDRing, override val buffer: Buffer -) : BufferedNDElement, RingElement, BufferedNDRingElement, BufferedNDRing> { +) : BufferedNDElement(), RingElement, BufferedNDRingElement, BufferedNDRing> { override fun unwrap(): NDBuffer = this @@ -42,7 +42,7 @@ class BufferedNDRingElement>( class BufferedNDFieldElement>( override val context: BufferedNDField, override val buffer: Buffer -) : BufferedNDElement, FieldElement, BufferedNDFieldElement, BufferedNDField> { +) : BufferedNDElement(), FieldElement, BufferedNDFieldElement, BufferedNDField> { override fun unwrap(): NDBuffer = this diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/Buffers.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/Buffers.kt index f02fd8dd0..ab8891ab9 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/Buffers.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/Buffers.kt @@ -71,7 +71,7 @@ interface Buffer { fun Buffer.asSequence(): Sequence = Sequence(::iterator) -fun Buffer.asIterable(): Iterable = asSequence().asIterable() +fun Buffer.asIterable(): Iterable = Iterable(::iterator) val Buffer<*>.indices: IntRange get() = IntRange(0, size - 1) diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/NDStructure.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/NDStructure.kt index 808f970c5..25d736b92 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/NDStructure.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/NDStructure.kt @@ -14,15 +14,21 @@ interface NDStructure { fun elements(): Sequence> + override fun equals(other: Any?): Boolean + + override fun hashCode(): Int + companion object { fun equals(st1: NDStructure<*>, st2: NDStructure<*>): Boolean { - return when { - st1 === st2 -> true - st1 is BufferNDStructure<*> && st2 is BufferNDStructure<*> && st1.strides == st2.strides -> st1.buffer.contentEquals( - st2.buffer - ) - else -> st1.elements().all { (index, value) -> value == st2[index] } + if(st1===st2) return true + + // fast comparison of buffers if possible + if(st1 is NDBuffer && st2 is NDBuffer && st1.strides == st2.strides){ + return st1.buffer.contentEquals(st2.buffer) } + + //element by element comparison if it could not be avoided + return st1.elements().all { (index, value) -> value == st2[index] } } /** @@ -177,15 +183,25 @@ class DefaultStrides private constructor(override val shape: IntArray) : Strides } } -interface NDBuffer : NDStructure { - val buffer: Buffer - val strides: Strides +abstract class NDBuffer : NDStructure { + abstract val buffer: Buffer + abstract val strides: Strides override fun get(index: IntArray): T = buffer[strides.offset(index)] override val shape: IntArray get() = strides.shape - override fun elements() = strides.indices().map { it to this[it] } + override fun elements(): Sequence> = strides.indices().map { it to this[it] } + + override fun equals(other: Any?): Boolean { + return NDStructure.equals(this, other as? NDStructure<*> ?: return false) + } + + override fun hashCode(): Int { + var result = strides.hashCode() + result = 31 * result + buffer.hashCode() + return result + } } /** @@ -194,34 +210,12 @@ interface NDBuffer : NDStructure { class BufferNDStructure( override val strides: Strides, override val buffer: Buffer -) : NDBuffer { - +) : NDBuffer(){ init { if (strides.linearSize != buffer.size) { error("Expected buffer side of ${strides.linearSize}, but found ${buffer.size}") } } - - override fun get(index: IntArray): T = buffer[strides.offset(index)] - - override val shape: IntArray get() = strides.shape - - override fun elements() = strides.indices().map { it to this[it] } - - override fun equals(other: Any?): Boolean { - return when { - this === other -> true - other is BufferNDStructure<*> && this.strides == other.strides -> this.buffer.contentEquals(other.buffer) - other is NDStructure<*> -> elements().all { (index, value) -> value == other[index] } - else -> false - } - } - - override fun hashCode(): Int { - var result = strides.hashCode() - result = 31 * result + buffer.hashCode() - return result - } } /** @@ -245,7 +239,7 @@ inline fun NDStructure.mapToBuffer( class MutableBufferNDStructure( override val strides: Strides, override val buffer: MutableBuffer -) : NDBuffer, MutableNDStructure { +) : NDBuffer(), MutableNDStructure { init { if (strides.linearSize != buffer.size) { diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/Structure2D.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/Structure2D.kt index e736f84a0..bfaf8338d 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/Structure2D.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/Structure2D.kt @@ -14,7 +14,6 @@ interface Structure2D : NDStructure { return get(index[0], index[1]) } - val rows: Buffer> get() = VirtualBuffer(rowNum) { i -> VirtualBuffer(colNum) { j -> get(i, j) } @@ -58,22 +57,4 @@ fun NDStructure.as2D(): Structure2D = if (shape.size == 2) { error("Can't create 2d-structure from ${shape.size}d-structure") } -/** - * Represent this 2D structure as 1D if it has exactly one column. Throw error otherwise. - */ -fun Structure2D.as1D() = if (colNum == 1) { - object : Structure1D { - override fun get(index: Int): T = get(index, 0) - - override val shape: IntArray get() = intArrayOf(rowNum) - - override fun elements(): Sequence> = elements() - - override val size: Int get() = rowNum - } -} else { - error("Can't convert matrix with more than one column to vector") -} - - typealias Matrix = Structure2D \ No newline at end of file diff --git a/kmath-core/src/jvmMain/kotlin/scientifik/kmath/operations/BigNumbers.kt b/kmath-core/src/jvmMain/kotlin/scientifik/kmath/operations/bigNumbers.kt similarity index 56% rename from kmath-core/src/jvmMain/kotlin/scientifik/kmath/operations/BigNumbers.kt rename to kmath-core/src/jvmMain/kotlin/scientifik/kmath/operations/bigNumbers.kt index f44d15042..76ca199c5 100644 --- a/kmath-core/src/jvmMain/kotlin/scientifik/kmath/operations/BigNumbers.kt +++ b/kmath-core/src/jvmMain/kotlin/scientifik/kmath/operations/bigNumbers.kt @@ -5,7 +5,7 @@ import java.math.BigDecimal import java.math.BigInteger import java.math.MathContext -object BigIntegerRing : Ring { +object JBigIntegerField : Field { override val zero: BigInteger = BigInteger.ZERO override val one: BigInteger = BigInteger.ONE @@ -14,9 +14,11 @@ object BigIntegerRing : Ring { override fun multiply(a: BigInteger, k: Number): BigInteger = a.multiply(k.toInt().toBigInteger()) override fun multiply(a: BigInteger, b: BigInteger): BigInteger = a.multiply(b) + + override fun divide(a: BigInteger, b: BigInteger): BigInteger = a.div(b) } -class BigDecimalField(val mathContext: MathContext = MathContext.DECIMAL64) : Field { +class JBigDecimalField(val mathContext: MathContext = MathContext.DECIMAL64) : Field { override val zero: BigDecimal = BigDecimal.ZERO override val one: BigDecimal = BigDecimal.ONE @@ -27,19 +29,4 @@ class BigDecimalField(val mathContext: MathContext = MathContext.DECIMAL64) : Fi override fun multiply(a: BigDecimal, b: BigDecimal): BigDecimal = a.multiply(b, mathContext) override fun divide(a: BigDecimal, b: BigDecimal): BigDecimal = a.divide(b, mathContext) -} - -inline fun Buffer.Companion.bigInt(size: Int, initializer: (Int) -> BigInteger): Buffer = - boxing(size, initializer) - -inline fun MutableBuffer.Companion.bigInt(size: Int, initializer: (Int) -> BigInteger): MutableBuffer = - boxing(size, initializer) - -fun NDAlgebra.Companion.bigInt(vararg shape: Int): BoxingNDRing = - BoxingNDRing(shape, BigIntegerRing, Buffer.Companion::bigInt) - -fun NDElement.Companion.bigInt( - vararg shape: Int, - initializer: BigIntegerRing.(IntArray) -> BigInteger -): BufferedNDRingElement = - NDAlgebra.bigInt(*shape).produce(initializer) \ No newline at end of file +} \ No newline at end of file diff --git a/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/chains/Chain.kt b/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/chains/Chain.kt index 1c2872d17..fd68636f9 100644 --- a/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/chains/Chain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/chains/Chain.kt @@ -68,6 +68,8 @@ class MarkovChain(private val seed: suspend () -> R, private val ge private var value: R? = null + fun value() = value + override suspend fun next(): R { mutex.withLock { val newValue = gen(value ?: seed()) @@ -97,6 +99,8 @@ class StatefulChain( private var value: R? = null + fun value() = value + override suspend fun next(): R { mutex.withLock { val newValue = state.gen(value ?: state.seed()) diff --git a/kmath-coroutines/src/jvmMain/kotlin/scientifik/kmath/structures/LazyNDStructure.kt b/kmath-coroutines/src/jvmMain/kotlin/scientifik/kmath/structures/LazyNDStructure.kt index 784b7cd10..e65940739 100644 --- a/kmath-coroutines/src/jvmMain/kotlin/scientifik/kmath/structures/LazyNDStructure.kt +++ b/kmath-coroutines/src/jvmMain/kotlin/scientifik/kmath/structures/LazyNDStructure.kt @@ -30,6 +30,20 @@ class LazyNDStructure( } return res.asSequence() } + + override fun equals(other: Any?): Boolean { + return NDStructure.equals(this, other as? NDStructure<*> ?: return false) + } + + override fun hashCode(): Int { + var result = scope.hashCode() + result = 31 * result + shape.contentHashCode() + result = 31 * result + function.hashCode() + result = 31 * result + cache.hashCode() + return result + } + + } fun NDStructure.deferred(index: IntArray) = diff --git a/kmath-for-real/src/commonMain/kotlin/scientifik/kmath/linear/RealVector.kt b/kmath-for-real/src/commonMain/kotlin/scientifik/kmath/linear/RealVector.kt deleted file mode 100644 index d3cf07e79..000000000 --- a/kmath-for-real/src/commonMain/kotlin/scientifik/kmath/linear/RealVector.kt +++ /dev/null @@ -1,48 +0,0 @@ -package scientifik.kmath.linear - -import scientifik.kmath.operations.Field -import scientifik.kmath.operations.Norm -import scientifik.kmath.operations.RealField -import scientifik.kmath.operations.SpaceElement -import scientifik.kmath.structures.Buffer -import scientifik.kmath.structures.DoubleBuffer -import scientifik.kmath.structures.asBuffer -import scientifik.kmath.structures.asSequence - -fun DoubleArray.asVector() = RealVector(this.asBuffer()) -fun List.asVector() = RealVector(this.asBuffer()) - - -object VectorL2Norm : Norm, Double> { - override fun norm(arg: Point): Double = - kotlin.math.sqrt(arg.asSequence().sumByDouble { it.toDouble() }) -} - -inline class RealVector(val point: Point) : - SpaceElement, RealVector, VectorSpace>, Point { - override val context: VectorSpace get() = space(point.size) - - override fun unwrap(): Point = point - - override fun Point.wrap(): RealVector = RealVector(this) - - override val size: Int get() = point.size - - override fun get(index: Int): Double = point[index] - - override fun iterator(): Iterator = point.iterator() - - companion object { - - private val spaceCache = HashMap>() - - inline operator fun invoke(dim:Int, initalizer: (Int)-> Double) = RealVector(DoubleBuffer(dim, initalizer)) - - operator fun invoke(vararg values: Double) = values.asVector() - - fun space(dim: Int) = - spaceCache.getOrPut(dim) { - BufferVectorSpace(dim, RealField) { size, init -> Buffer.real(size, init) } - } - } -} \ No newline at end of file diff --git a/kmath-for-real/src/commonMain/kotlin/scientifik/kmath/real/RealVector.kt b/kmath-for-real/src/commonMain/kotlin/scientifik/kmath/real/RealVector.kt new file mode 100644 index 000000000..ff4c835ed --- /dev/null +++ b/kmath-for-real/src/commonMain/kotlin/scientifik/kmath/real/RealVector.kt @@ -0,0 +1,59 @@ +package scientifik.kmath.real + +import scientifik.kmath.linear.BufferVectorSpace +import scientifik.kmath.linear.Point +import scientifik.kmath.linear.VectorSpace +import scientifik.kmath.operations.Norm +import scientifik.kmath.operations.RealField +import scientifik.kmath.operations.SpaceElement +import scientifik.kmath.structures.Buffer +import scientifik.kmath.structures.DoubleBuffer +import scientifik.kmath.structures.asBuffer +import scientifik.kmath.structures.asIterable +import kotlin.math.sqrt + +fun DoubleArray.asVector() = RealVector(this.asBuffer()) +fun List.asVector() = RealVector(this.asBuffer()) + + +object VectorL2Norm : Norm, Double> { + override fun norm(arg: Point): Double = sqrt(arg.asIterable().sumByDouble { it.toDouble() }) +} + +inline class RealVector(private val point: Point) : + SpaceElement, RealVector, VectorSpace>, Point { + + override val context: VectorSpace + get() = space( + point.size + ) + + override fun unwrap(): Point = point + + override fun Point.wrap(): RealVector = + RealVector(this) + + override val size: Int get() = point.size + + override fun get(index: Int): Double = point[index] + + override fun iterator(): Iterator = point.iterator() + + companion object { + + private val spaceCache = HashMap>() + + inline operator fun invoke(dim: Int, initializer: (Int) -> Double) = + RealVector(DoubleBuffer(dim, initializer)) + + operator fun invoke(vararg values: Double): RealVector = values.asVector() + + fun space(dim: Int): BufferVectorSpace = + spaceCache.getOrPut(dim) { + BufferVectorSpace( + dim, + RealField + ) { size, init -> Buffer.real(size, init) } + } + } +} \ No newline at end of file diff --git a/kmath-for-real/src/commonTest/kotlin/scientifik/kmath/linear/VectorTest.kt b/kmath-for-real/src/commonTest/kotlin/scientifik/kmath/linear/VectorTest.kt index 0e73ee4a5..28e62b066 100644 --- a/kmath-for-real/src/commonTest/kotlin/scientifik/kmath/linear/VectorTest.kt +++ b/kmath-for-real/src/commonTest/kotlin/scientifik/kmath/linear/VectorTest.kt @@ -1,5 +1,6 @@ package scientifik.kmath.linear +import scientifik.kmath.real.RealVector import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/RealHistogram.kt b/kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/RealHistogram.kt index 85f078fda..4438f5d60 100644 --- a/kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/RealHistogram.kt +++ b/kmath-histograms/src/commonMain/kotlin/scientifik/kmath/histogram/RealHistogram.kt @@ -1,7 +1,7 @@ package scientifik.kmath.histogram import scientifik.kmath.linear.Point -import scientifik.kmath.linear.asVector +import scientifik.kmath.real.asVector import scientifik.kmath.operations.SpaceOperations import scientifik.kmath.structures.* import kotlin.math.floor diff --git a/kmath-histograms/src/commonTest/kotlin/scietifik/kmath/histogram/MultivariateHistogramTest.kt b/kmath-histograms/src/commonTest/kotlin/scietifik/kmath/histogram/MultivariateHistogramTest.kt index 4dc4dfc74..5edecb5a5 100644 --- a/kmath-histograms/src/commonTest/kotlin/scietifik/kmath/histogram/MultivariateHistogramTest.kt +++ b/kmath-histograms/src/commonTest/kotlin/scietifik/kmath/histogram/MultivariateHistogramTest.kt @@ -3,7 +3,7 @@ package scietifik.kmath.histogram import scientifik.kmath.histogram.RealHistogram import scientifik.kmath.histogram.fill import scientifik.kmath.histogram.put -import scientifik.kmath.linear.RealVector +import scientifik.kmath.real.RealVector import kotlin.random.Random import kotlin.test.Test import kotlin.test.assertEquals diff --git a/kmath-histograms/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt b/kmath-histograms/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt index 90b9aff5e..dcc5ac0eb 100644 --- a/kmath-histograms/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt +++ b/kmath-histograms/src/jvmMain/kotlin/scientifik/kmath/histogram/UnivariateHistogram.kt @@ -1,7 +1,7 @@ package scientifik.kmath.histogram -import scientifik.kmath.linear.RealVector -import scientifik.kmath.linear.asVector +import scientifik.kmath.real.RealVector +import scientifik.kmath.real.asVector import scientifik.kmath.structures.Buffer import java.util.* import kotlin.math.floor diff --git a/kmath-koma/src/commonMain/kotlin/scientifik.kmath.linear/KomaMatrix.kt b/kmath-koma/src/commonMain/kotlin/scientifik.kmath.linear/KomaMatrix.kt index 74681ac48..10deabd73 100644 --- a/kmath-koma/src/commonMain/kotlin/scientifik.kmath.linear/KomaMatrix.kt +++ b/kmath-koma/src/commonMain/kotlin/scientifik.kmath.linear/KomaMatrix.kt @@ -4,6 +4,7 @@ import koma.extensions.fill import koma.matrix.MatrixFactory import scientifik.kmath.operations.Space import scientifik.kmath.structures.Matrix +import scientifik.kmath.structures.NDStructure class KomaMatrixContext( private val factory: MatrixFactory>, @@ -85,6 +86,18 @@ class KomaMatrix(val origin: koma.matrix.Matrix, features: Set ?: return false) + } + + override fun hashCode(): Int { + var result = origin.hashCode() + result = 31 * result + features.hashCode() + return result + } + + } class KomaVector internal constructor(val origin: koma.matrix.Matrix) : Point { diff --git a/settings.gradle.kts b/settings.gradle.kts index a08d5f7ee..57173250b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,10 +1,12 @@ pluginManagement { + val toolsVersion = "0.5.0" + plugins { - id("scientifik.mpp") version "0.4.1" - id("scientifik.jvm") version "0.4.1" - id("scientifik.atomic") version "0.4.1" - id("scientifik.publish") version "0.4.1" + id("scientifik.mpp") version toolsVersion + id("scientifik.jvm") version toolsVersion + id("scientifik.atomic") version toolsVersion + id("scientifik.publish") version toolsVersion } repositories { @@ -20,7 +22,7 @@ pluginManagement { resolutionStrategy { eachPlugin { when (requested.id.id) { - "scientifik.mpp", "scientifik.jvm", "scientifik.publish" -> useModule("scientifik:gradle-tools:${requested.version}") + "scientifik.mpp", "scientifik.jvm", "scientifik.publish" -> useModule("scientifik:gradle-tools:$toolsVersion") } } }