From fcb7e2fa7d91667522d681d78c92c7aff181e29c Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 22 Feb 2024 21:03:58 +0300 Subject: [PATCH] Reverse types for buffers and typealiases for geometry. --- CHANGELOG.md | 3 +- build.gradle.kts | 2 +- .../kscience/kmath/commons/linear/CMMatrix.kt | 3 +- .../kscience/kmath/complex/Quaternion.kt | 2 - kmath-core/api/kmath-core.api | 87 ++++++------------- .../kscience/kmath/expressions/DSAlgebra.kt | 2 +- .../kmath/expressions/SimpleAutoDiff.kt | 2 +- .../kscience/kmath/linear/LinearSpace.kt | 2 +- .../kscience/kmath/linear/LupDecomposition.kt | 6 +- .../kscience/kmath/linear/MatrixWrapper.kt | 4 +- .../space/kscience/kmath/linear/Transposed.kt | 2 - .../kscience/kmath/linear/VirtualMatrix.kt | 4 +- .../space/kscience/kmath/misc/sorting.kt | 10 +-- .../space/kscience/kmath/nd/BufferND.kt | 3 - .../space/kscience/kmath/nd/Float64FieldND.kt | 4 - .../kscience/kmath/nd/PermutedStructureND.kt | 5 -- .../space/kscience/kmath/nd/Structure1D.kt | 19 ---- .../space/kscience/kmath/nd/Structure2D.kt | 13 +-- .../space/kscience/kmath/nd/StructureND.kt | 7 +- .../kscience/kmath/nd/VirtualStructureND.kt | 7 +- .../space/kscience/kmath/nd/operationsND.kt | 4 +- .../kscience/kmath/nd/primitiveStructureND.kt | 7 -- .../kscience/kmath/structures/ArrayBuffer.kt | 14 +-- .../space/kscience/kmath/structures/Buffer.kt | 15 +--- .../kmath/structures/BufferAccessor2D.kt | 3 - .../kscience/kmath/structures/BufferView.kt | 5 -- .../kmath/structures/FlaggedBuffer.kt | 4 - .../kmath/structures/Float32Buffer.kt | 6 -- .../kmath/structures/Float64Buffer.kt | 6 -- .../kscience/kmath/structures/Int16Buffer.kt | 5 +- .../kscience/kmath/structures/Int32Buffer.kt | 4 - .../kscience/kmath/structures/Int64Buffer.kt | 6 -- .../kscience/kmath/structures/Int8Buffer.kt | 5 -- .../kscience/kmath/structures/ListBuffer.kt | 28 +----- .../kmath/structures/MutableBuffer.kt | 28 ++++-- .../space/kscience/kmath/linear/MatrixTest.kt | 2 +- .../kmath/structures/parallelMutableBuffer.kt | 2 +- .../kmath/linear/ParallelMatrixTest.kt | 2 +- .../kscience/kmath/streaming/RingBuffer.kt | 17 ++-- .../kmath/structures/LazyStructureND.kt | 7 +- .../kscience/kmath/dimensions/Wrappers.kt | 5 -- .../kscience/kmath/ejml/implementations.kt | 6 -- .../space/kscience/kmath/real/RealMatrix.kt | 2 +- .../kmath/interpolation/Interpolator.kt | 4 +- kmath-geometry/build.gradle.kts | 1 + .../space/kscience/kmath/geometry/Vector3D.kt | 4 - .../geometry/euclidean2d/Float32Space2D.kt | 7 +- .../geometry/euclidean2d/Float64Space2D.kt | 6 +- .../geometry/euclidean3d/Float32Space3D.kt | 7 +- .../geometry/euclidean3d/Float64Space3D.kt | 6 +- .../kmath/geometry/euclidean3d/rotations3D.kt | 3 - kmath-memory/api/kmath-memory.api | 2 - .../kscience/kmath/memory/MemoryBuffer.kt | 4 - .../kscience/kmath/multik/MultikTensor.kt | 2 - kmath-nd4j/api/kmath-nd4j.api | 1 - .../kscience/kmath/nd4j/Nd4jArrayStructure.kt | 4 - .../kscience/kmath/stat/ValueAndErrorField.kt | 2 - .../tensorflow/DoubleTensorFlowAlgebra.kt | 2 - .../kmath/tensorflow/IntTensorFlowAlgebra.kt | 8 -- .../kmath/tensorflow/TensorFlowAlgebra.kt | 6 +- .../kmath/tensors/core/DoubleTensor.kt | 6 +- .../kmath/tensors/core/DoubleTensor1D.kt | 3 - .../kscience/kmath/tensors/core/IntTensor.kt | 7 +- .../kmath/tensors/core/tensorTransform.kt | 2 +- kmath-viktor/api/kmath-viktor.api | 5 -- .../kscience/kmath/viktor/ViktorBuffer.kt | 4 - .../kmath/viktor/ViktorStructureND.kt | 4 - 67 files changed, 117 insertions(+), 353 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d2525a80..5c383fe95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ ### Added -- Reification. Explicit `SafeType` for algebras and buffers. +- Reification. Explicit `SafeType` for algebras. - Integer division algebras. - Float32 geometries. - New Attributes-kt module that could be used as stand-alone. It declares. type-safe attributes containers. @@ -30,6 +30,7 @@ ### Changed +- Buffer copy removed from API (added as an extension). - Default naming for algebra and buffers now uses IntXX/FloatXX notation instead of Java types. - Remove unnecessary inlines in basic algebras. - QuaternionField -> QuaternionAlgebra and does not implement `Field` anymore since it is non-commutative diff --git a/build.gradle.kts b/build.gradle.kts index ae4ab51cf..9231fc312 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ allprojects { } group = "space.kscience" - version = "0.4.0-RC" + version = "0.4.0-RC2" } subprojects { diff --git a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt index 589dc19e0..1fe923cbb 100644 --- a/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt +++ b/kmath-commons/src/jvmMain/kotlin/space/kscience/kmath/commons/linear/CMMatrix.kt @@ -23,7 +23,7 @@ import space.kscience.kmath.structures.IntBuffer import space.kscience.kmath.structures.asBuffer public class CMMatrix(public val origin: RealMatrix) : Matrix { - override val type: SafeType get() = DoubleField.type + override val rowNum: Int get() = origin.rowDimension override val colNum: Int get() = origin.columnDimension @@ -32,7 +32,6 @@ public class CMMatrix(public val origin: RealMatrix) : Matrix { @JvmInline public value class CMVector(public val origin: RealVector) : Point { - override val type: SafeType get() = DoubleField.type override val size: Int get() = origin.dimension override operator fun get(index: Int): Double = origin.getEntry(index) diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt index d5093f4b0..6a6171975 100644 --- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/Quaternion.kt @@ -36,8 +36,6 @@ public class Quaternion( require(!z.isNaN()) { "z-component of quaternion is not-a-number" } } - override val type: SafeType get() = safeTypeOf() - /** * Returns a string representation of this quaternion. */ diff --git a/kmath-core/api/kmath-core.api b/kmath-core/api/kmath-core.api index 0053dde28..460c2e3c4 100644 --- a/kmath-core/api/kmath-core.api +++ b/kmath-core/api/kmath-core.api @@ -428,7 +428,6 @@ public final class space/kscience/kmath/expressions/NamedMatrix : space/kscience public fun getRowNum ()I public fun getRows ()Ljava/util/List; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public final fun getValues ()Lspace/kscience/kmath/nd/Structure2D; } @@ -820,7 +819,6 @@ public final class space/kscience/kmath/linear/MatrixWrapper : space/kscience/km public fun getRowNum ()I public fun getRows ()Ljava/util/List; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun toString ()Ljava/lang/String; } @@ -871,7 +869,6 @@ public final class space/kscience/kmath/linear/TransposedMatrix : space/kscience public fun getColNum ()I public final fun getOrigin ()Lspace/kscience/kmath/nd/Structure2D; public fun getRowNum ()I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public final class space/kscience/kmath/linear/UpperTriangular : space/kscience/attributes/FlagAttribute, space/kscience/kmath/linear/MatrixAttribute { @@ -879,15 +876,14 @@ public final class space/kscience/kmath/linear/UpperTriangular : space/kscience/ } public final class space/kscience/kmath/linear/VirtualMatrix : space/kscience/kmath/nd/Structure2D { - public synthetic fun (Lkotlin/reflect/KType;IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun (Lkotlin/reflect/KType;IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;)V + public synthetic fun (IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun get (II)Ljava/lang/Object; public fun getAttributes ()Lspace/kscience/attributes/Attributes; public fun getColNum ()I public final fun getGenerator ()Lkotlin/jvm/functions/Function2; public fun getRowNum ()I public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public final class space/kscience/kmath/linear/VirtualMatrixKt { @@ -1009,7 +1005,6 @@ public class space/kscience/kmath/nd/BufferND : space/kscience/kmath/nd/Structur public fun getBuffer ()Lspace/kscience/kmath/structures/Buffer; public fun getIndices ()Lspace/kscience/kmath/nd/ShapeIndexer; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun toString ()Ljava/lang/String; } @@ -1160,7 +1155,6 @@ public final class space/kscience/kmath/nd/Float64BufferND : space/kscience/kmat public synthetic fun getBuffer ()Lspace/kscience/kmath/structures/MutableBuffer; public fun getBuffer-E20IKn8 ()[D public fun getDouble ([I)D - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun setDouble ([ID)V } @@ -1290,11 +1284,9 @@ public abstract interface class space/kscience/kmath/nd/MutableStructureND : spa public final class space/kscience/kmath/nd/MutableStructureNDAccessorBuffer : space/kscience/kmath/structures/MutableBuffer { public fun (Lspace/kscience/kmath/nd/MutableStructureND;ILkotlin/jvm/functions/Function1;)V - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; public fun get (I)Ljava/lang/Object; public fun getSize ()I public final fun getStructure ()Lspace/kscience/kmath/nd/MutableStructureND; - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun set (ILjava/lang/Object;)V public fun toString ()Ljava/lang/String; } @@ -1316,7 +1308,6 @@ public final class space/kscience/kmath/nd/PermutedMutableStructureND : space/ks public final fun getOrigin ()Lspace/kscience/kmath/nd/MutableStructureND; public final fun getPermutation ()Lkotlin/jvm/functions/Function1; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun set ([ILjava/lang/Object;)V } @@ -1326,7 +1317,6 @@ public final class space/kscience/kmath/nd/PermutedStructureND : space/kscience/ public final fun getOrigin ()Lspace/kscience/kmath/nd/StructureND; public final fun getPermutation ()Lkotlin/jvm/functions/Function1; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public final class space/kscience/kmath/nd/PermutedStructureNDKt { @@ -1477,7 +1467,7 @@ public final class space/kscience/kmath/nd/Structure2DKt { public abstract interface class space/kscience/kmath/nd/StructureAttribute : space/kscience/attributes/Attribute { } -public abstract interface class space/kscience/kmath/nd/StructureND : space/kscience/attributes/AttributeContainer, space/kscience/attributes/WithType, space/kscience/kmath/nd/WithShape { +public abstract interface class space/kscience/kmath/nd/StructureND : space/kscience/attributes/AttributeContainer, space/kscience/kmath/nd/WithShape { public static final field Companion Lspace/kscience/kmath/nd/StructureND$Companion; public fun elements ()Lkotlin/sequences/Sequence; public abstract fun get ([I)Ljava/lang/Object; @@ -1509,20 +1499,17 @@ public final class space/kscience/kmath/nd/StructureNDKt { public abstract interface class space/kscience/kmath/nd/StructureNDOfDouble : space/kscience/kmath/nd/StructureND { public abstract fun getDouble ([I)D - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public abstract interface class space/kscience/kmath/nd/StructureNDOfInt : space/kscience/kmath/nd/StructureND { public abstract fun getInt ([I)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public class space/kscience/kmath/nd/VirtualStructureND : space/kscience/kmath/nd/StructureND { - public synthetic fun (Lkotlin/reflect/KType;[ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun ([ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public fun get ([I)Ljava/lang/Object; public final fun getProducer ()Lkotlin/jvm/functions/Function1; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public abstract interface class space/kscience/kmath/nd/WithShape { @@ -2376,21 +2363,31 @@ public abstract interface class space/kscience/kmath/operations/WithSize { } public final class space/kscience/kmath/structures/ArrayBuffer : space/kscience/kmath/structures/MutableBuffer { - public synthetic fun (Lkotlin/reflect/KType;[Ljava/lang/Object;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public static final synthetic fun box-impl ([Ljava/lang/Object;)Lspace/kscience/kmath/structures/ArrayBuffer; + public static fun constructor-impl ([Ljava/lang/Object;)[Ljava/lang/Object; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl ([Ljava/lang/Object;Ljava/lang/Object;)Z + public static final fun equals-impl0 ([Ljava/lang/Object;[Ljava/lang/Object;)Z public fun get (I)Ljava/lang/Object; + public static fun get-impl ([Ljava/lang/Object;I)Ljava/lang/Object; public fun getSize ()I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; + public static fun getSize-impl ([Ljava/lang/Object;)I + public fun hashCode ()I + public static fun hashCode-impl ([Ljava/lang/Object;)I public fun iterator ()Ljava/util/Iterator; + public static fun iterator-impl ([Ljava/lang/Object;)Ljava/util/Iterator; public fun set (ILjava/lang/Object;)V + public static fun set-impl ([Ljava/lang/Object;ILjava/lang/Object;)V public fun toString ()Ljava/lang/String; + public static fun toString-impl ([Ljava/lang/Object;)Ljava/lang/String; + public final synthetic fun unbox-impl ()[Ljava/lang/Object; } public final class space/kscience/kmath/structures/ArrayBufferKt { - public static final fun asBuffer-Fnn_obI ([Ljava/lang/Object;Lkotlin/reflect/KType;)Lspace/kscience/kmath/structures/ArrayBuffer; + public static final fun asBuffer ([Ljava/lang/Object;)[Ljava/lang/Object; } -public abstract interface class space/kscience/kmath/structures/Buffer : space/kscience/attributes/WithType, space/kscience/kmath/operations/WithSize { +public abstract interface class space/kscience/kmath/structures/Buffer : space/kscience/kmath/operations/WithSize { public static final field Companion Lspace/kscience/kmath/structures/Buffer$Companion; public abstract fun get (I)Ljava/lang/Object; public abstract fun getSize ()I @@ -2449,7 +2446,6 @@ public final class space/kscience/kmath/structures/BufferSlice : space/kscience/ public abstract interface class space/kscience/kmath/structures/BufferView : space/kscience/kmath/structures/Buffer { public fun get (I)Ljava/lang/Object; public abstract fun getOrigin ()Lspace/kscience/kmath/structures/Buffer; - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; } public final class space/kscience/kmath/structures/BufferViewKt { @@ -2477,7 +2473,6 @@ public final class space/kscience/kmath/structures/FlaggedDoubleBuffer : space/k public fun getFlag (I)B public final fun getFlags ()[B public fun getSize ()I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public final fun getValues ()[D public fun iterator ()Ljava/util/Iterator; public fun toString ()Ljava/lang/String; @@ -2486,8 +2481,6 @@ public final class space/kscience/kmath/structures/FlaggedDoubleBuffer : space/k public final class space/kscience/kmath/structures/Float32Buffer : space/kscience/kmath/structures/PrimitiveBuffer { public static final synthetic fun box-impl ([F)Lspace/kscience/kmath/structures/Float32Buffer; public static fun constructor-impl ([F)[F - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([F)Lspace/kscience/kmath/structures/MutableBuffer; public fun equals (Ljava/lang/Object;)Z public static fun equals-impl ([FLjava/lang/Object;)Z public static final fun equals-impl0 ([F[F)Z @@ -2497,8 +2490,6 @@ public final class space/kscience/kmath/structures/Float32Buffer : space/kscienc public final fun getArray ()[F public fun getSize ()I public static fun getSize-impl ([F)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY ([F)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([F)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2523,9 +2514,6 @@ public final class space/kscience/kmath/structures/Float64Buffer : space/kscienc public static final field Companion Lspace/kscience/kmath/structures/Float64Buffer$Companion; public static final synthetic fun box-impl ([D)Lspace/kscience/kmath/structures/Float64Buffer; public static fun constructor-impl ([D)[D - public synthetic fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public fun copy-E20IKn8 ()[D - public static fun copy-E20IKn8 ([D)[D public fun equals (Ljava/lang/Object;)Z public static fun equals-impl ([DLjava/lang/Object;)Z public static final fun equals-impl0 ([D[D)Z @@ -2535,8 +2523,6 @@ public final class space/kscience/kmath/structures/Float64Buffer : space/kscienc public final fun getArray ()[D public fun getSize ()I public static fun getSize-impl ([D)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY ([D)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([D)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2571,8 +2557,6 @@ public abstract interface class space/kscience/kmath/structures/Float64BufferTra public final class space/kscience/kmath/structures/Int16Buffer : space/kscience/kmath/structures/MutableBuffer { public static final synthetic fun box-impl ([S)Lspace/kscience/kmath/structures/Int16Buffer; public static fun constructor-impl ([S)[S - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([S)Lspace/kscience/kmath/structures/MutableBuffer; public fun equals (Ljava/lang/Object;)Z public static fun equals-impl ([SLjava/lang/Object;)Z public static final fun equals-impl0 ([S[S)Z @@ -2582,8 +2566,6 @@ public final class space/kscience/kmath/structures/Int16Buffer : space/kscience/ public final fun getArray ()[S public fun getSize ()I public static fun getSize-impl ([S)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY ([S)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([S)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2607,9 +2589,6 @@ public final class space/kscience/kmath/structures/Int16BufferKt { public final class space/kscience/kmath/structures/Int32Buffer : space/kscience/kmath/structures/PrimitiveBuffer { public static final synthetic fun box-impl ([I)Lspace/kscience/kmath/structures/Int32Buffer; public static fun constructor-impl ([I)[I - public synthetic fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public fun copy-M_oXE9g ()[I - public static fun copy-M_oXE9g ([I)[I public fun equals (Ljava/lang/Object;)Z public static fun equals-impl ([ILjava/lang/Object;)Z public static final fun equals-impl0 ([I[I)Z @@ -2619,8 +2598,6 @@ public final class space/kscience/kmath/structures/Int32Buffer : space/kscience/ public final fun getArray ()[I public fun getSize ()I public static fun getSize-impl ([I)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY ([I)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([I)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2644,8 +2621,6 @@ public final class space/kscience/kmath/structures/Int32BufferKt { public final class space/kscience/kmath/structures/Int64Buffer : space/kscience/kmath/structures/PrimitiveBuffer { public static final synthetic fun box-impl ([J)Lspace/kscience/kmath/structures/Int64Buffer; public static fun constructor-impl ([J)[J - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([J)Lspace/kscience/kmath/structures/MutableBuffer; public fun equals (Ljava/lang/Object;)Z public static fun equals-impl ([JLjava/lang/Object;)Z public static final fun equals-impl0 ([J[J)Z @@ -2655,8 +2630,6 @@ public final class space/kscience/kmath/structures/Int64Buffer : space/kscience/ public final fun getArray ()[J public fun getSize ()I public static fun getSize-impl ([J)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY ([J)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([J)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2680,8 +2653,6 @@ public final class space/kscience/kmath/structures/Int64BufferKt { public final class space/kscience/kmath/structures/Int8Buffer : space/kscience/kmath/structures/MutableBuffer { public static final synthetic fun box-impl ([B)Lspace/kscience/kmath/structures/Int8Buffer; public static fun constructor-impl ([B)[B - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl ([B)Lspace/kscience/kmath/structures/MutableBuffer; public fun equals (Ljava/lang/Object;)Z public static fun equals-impl ([BLjava/lang/Object;)Z public static final fun equals-impl0 ([B[B)Z @@ -2691,8 +2662,6 @@ public final class space/kscience/kmath/structures/Int8Buffer : space/kscience/k public final fun getArray ()[B public fun getSize ()I public static fun getSize-impl ([B)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY ([B)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl ([B)I public synthetic fun iterator ()Ljava/util/Iterator; @@ -2714,23 +2683,21 @@ public final class space/kscience/kmath/structures/Int8BufferKt { } public final class space/kscience/kmath/structures/ListBuffer : space/kscience/kmath/structures/Buffer { - public synthetic fun (Lkotlin/reflect/KType;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Ljava/util/List;)V public fun get (I)Ljava/lang/Object; public final fun getList ()Ljava/util/List; public fun getSize ()I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun iterator ()Ljava/util/Iterator; public fun toString ()Ljava/lang/String; } public final class space/kscience/kmath/structures/ListBufferKt { - public static final fun asBuffer-Fnn_obI (Ljava/util/List;Lkotlin/reflect/KType;)Lspace/kscience/kmath/structures/ListBuffer; - public static final fun asMutableBuffer-Fnn_obI (Ljava/util/List;Lkotlin/reflect/KType;)Lspace/kscience/kmath/structures/MutableListBuffer; + public static final fun asBuffer (Ljava/util/List;)Lspace/kscience/kmath/structures/ListBuffer; + public static final fun asMutableBuffer (Ljava/util/List;)Lspace/kscience/kmath/structures/MutableListBuffer; } public abstract interface class space/kscience/kmath/structures/MutableBuffer : space/kscience/kmath/structures/Buffer { public static final field Companion Lspace/kscience/kmath/structures/MutableBuffer$Companion; - public abstract fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; public abstract fun set (ILjava/lang/Object;)V } @@ -2752,15 +2719,15 @@ public final class space/kscience/kmath/structures/MutableBufferFactory$Companio public final class space/kscience/kmath/structures/MutableBufferKt { public static final fun MutableBuffer--rwW0uw (Lkotlin/reflect/KType;ILkotlin/jvm/functions/Function1;)Lspace/kscience/kmath/structures/MutableBuffer; + public static final fun copy (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/BufferFactory;)Lspace/kscience/kmath/structures/Buffer; + public static final fun mutableCopy (Lspace/kscience/kmath/structures/Buffer;Lspace/kscience/kmath/structures/MutableBufferFactory;)Lspace/kscience/kmath/structures/MutableBuffer; } public final class space/kscience/kmath/structures/MutableListBuffer : space/kscience/kmath/structures/MutableBuffer { - public synthetic fun (Lkotlin/reflect/KType;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; + public fun (Ljava/util/List;)V public fun get (I)Ljava/lang/Object; public final fun getList ()Ljava/util/List; public fun getSize ()I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun iterator ()Ljava/util/Iterator; public fun set (ILjava/lang/Object;)V public fun toString ()Ljava/lang/String; @@ -2789,7 +2756,6 @@ public final class space/kscience/kmath/structures/PermutedBuffer : space/kscien public final class space/kscience/kmath/structures/PermutedMutableBuffer : space/kscience/kmath/structures/BufferView, space/kscience/kmath/structures/MutableBuffer { public fun (Lspace/kscience/kmath/structures/MutableBuffer;[I)V - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; public fun get (I)Ljava/lang/Object; public synthetic fun getOrigin ()Lspace/kscience/kmath/structures/Buffer; public fun getOrigin ()Lspace/kscience/kmath/structures/MutableBuffer; @@ -2814,10 +2780,9 @@ public final class space/kscience/kmath/structures/ValueFlag : java/lang/Enum { } public final class space/kscience/kmath/structures/VirtualBuffer : space/kscience/kmath/structures/Buffer { - public synthetic fun (Lkotlin/reflect/KType;ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (ILkotlin/jvm/functions/Function1;)V public fun get (I)Ljava/lang/Object; public fun getSize ()I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun iterator ()Ljava/util/Iterator; public fun toString ()Ljava/lang/String; } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt index 3d2683167..a6e721d13 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/DSAlgebra.kt @@ -189,7 +189,7 @@ public abstract class DSAlgebra>( vararg derivatives: T, ): DS { require(derivatives.size == compiler.size) { "dimension mismatch: ${derivatives.size} and ${compiler.size}" } - val data = derivatives.asList().asBuffer(algebra.type) + val data = derivatives.asList().asBuffer() return DS(data) } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt index 1134fbb9b..1209372b4 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/SimpleAutoDiff.kt @@ -53,7 +53,7 @@ public class DerivationResult( */ public fun DerivationResult.grad(vararg variables: Symbol): Point { check(variables.isNotEmpty()) { "Variable order is not provided for gradient construction" } - return variables.map(::derivative).asBuffer(type) + return variables.map(::derivative).asBuffer() } /** diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpace.kt index 4ed36fbbc..fb4661b96 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpace.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LinearSpace.kt @@ -227,4 +227,4 @@ public fun Matrix.asVector(): Point = * @receiver a buffer. * @return the new matrix. */ -public fun Point.asMatrix(): VirtualMatrix = VirtualMatrix(type, size, 1) { i, _ -> get(i) } \ No newline at end of file +public fun Point.asMatrix(): VirtualMatrix = VirtualMatrix(size, 1) { i, _ -> get(i) } \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LupDecomposition.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LupDecomposition.kt index cff72b2f5..58831f38d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LupDecomposition.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/LupDecomposition.kt @@ -27,7 +27,7 @@ public interface LupDecomposition { * Create a pivot matrix from pivot vector using provided [LinearSpace] */ public fun LupDecomposition.pivotMatrix(linearSpace: LinearSpace>): Matrix = - VirtualMatrix(linearSpace.type, l.rowNum, l.colNum) { row, column -> + VirtualMatrix(l.rowNum, l.colNum) { row, column -> if (column == pivot[row]) linearSpace.elementAlgebra.one else linearSpace.elementAlgebra.zero } @@ -47,7 +47,7 @@ public class GenericLupDecomposition( override val l: Matrix - get() = VirtualMatrix(lu.type, lu.rowNum, lu.colNum, attributes = Attributes(LowerTriangular)) { i, j -> + get() = VirtualMatrix(lu.rowNum, lu.colNum, attributes = Attributes(LowerTriangular)) { i, j -> when { j < i -> lu[i, j] j == i -> elementAlgebra.one @@ -56,7 +56,7 @@ public class GenericLupDecomposition( } override val u: Matrix - get() = VirtualMatrix(lu.type, lu.rowNum, lu.colNum, attributes = Attributes(UpperTriangular)) { i, j -> + get() = VirtualMatrix(lu.rowNum, lu.colNum, attributes = Attributes(UpperTriangular)) { i, j -> if (j >= i) lu[i, j] else elementAlgebra.zero } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt index bea86d3ec..a5987bb18 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/MatrixWrapper.kt @@ -68,7 +68,7 @@ public fun Matrix.modifyAttributes(modifier: (Attributes) -> Attributes): public fun LinearSpace>.one( rows: Int, columns: Int, -): MatrixWrapper = VirtualMatrix(type, rows, columns) { i, j -> +): MatrixWrapper = VirtualMatrix(rows, columns) { i, j -> if (i == j) elementAlgebra.one else elementAlgebra.zero }.withAttribute(IsUnit) @@ -79,6 +79,6 @@ public fun LinearSpace>.one( public fun LinearSpace>.zero( rows: Int, columns: Int, -): MatrixWrapper = VirtualMatrix(type, rows, columns) { _, _ -> +): MatrixWrapper = VirtualMatrix(rows, columns) { _, _ -> elementAlgebra.zero }.withAttribute(IsZero) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt index 28821a52a..36be711e7 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/Transposed.kt @@ -6,11 +6,9 @@ package space.kscience.kmath.linear import space.kscience.attributes.Attributes -import space.kscience.attributes.SafeType public class TransposedMatrix(public val origin: Matrix) : Matrix { - override val type: SafeType get() = origin.type override val rowNum: Int get() = origin.colNum diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt index ab6808891..2b031de06 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/VirtualMatrix.kt @@ -6,7 +6,6 @@ package space.kscience.kmath.linear import space.kscience.attributes.Attributes -import space.kscience.attributes.SafeType import space.kscience.kmath.nd.ShapeND @@ -16,7 +15,6 @@ import space.kscience.kmath.nd.ShapeND * @property generator the function that provides elements. */ public class VirtualMatrix( - override val type: SafeType, override val rowNum: Int, override val colNum: Int, override val attributes: Attributes = Attributes.EMPTY, @@ -31,4 +29,4 @@ public class VirtualMatrix( public fun MatrixBuilder.virtual( attributes: Attributes = Attributes.EMPTY, generator: (i: Int, j: Int) -> T, -): VirtualMatrix = VirtualMatrix(type, rows, columns, attributes, generator) +): VirtualMatrix = VirtualMatrix(rows, columns, attributes, generator) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt index 9ff306355..e1b24dd68 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/sorting.kt @@ -26,7 +26,7 @@ public fun > Buffer.indicesSorted(): IntArray = permSortInd */ public fun > Buffer.sorted(): Buffer { val permutations = indicesSorted() - return VirtualBuffer(type, size) { this[permutations[it]] } + return VirtualBuffer(size) { this[permutations[it]] } } @UnstableKMathAPI @@ -38,7 +38,7 @@ public fun > Buffer.indicesSortedDescending(): IntArray = */ public fun > Buffer.sortedDescending(): Buffer { val permutations = indicesSortedDescending() - return VirtualBuffer(type, size) { this[permutations[it]] } + return VirtualBuffer(size) { this[permutations[it]] } } @UnstableKMathAPI @@ -47,7 +47,7 @@ public fun > Buffer.indicesSortedBy(selector: (V) -> C): public fun > Buffer.sortedBy(selector: (V) -> C): Buffer { val permutations = indicesSortedBy(selector) - return VirtualBuffer(type, size) { this[permutations[it]] } + return VirtualBuffer(size) { this[permutations[it]] } } @UnstableKMathAPI @@ -56,7 +56,7 @@ public fun > Buffer.indicesSortedByDescending(selector: public fun > Buffer.sortedByDescending(selector: (V) -> C): Buffer { val permutations = indicesSortedByDescending(selector) - return VirtualBuffer(type, size) { this[permutations[it]] } + return VirtualBuffer(size) { this[permutations[it]] } } @UnstableKMathAPI @@ -68,7 +68,7 @@ public fun Buffer.indicesSortedWith(comparator: Comparator): IntArray */ public fun Buffer.sortedWith(comparator: Comparator): Buffer { val permutations = indicesSortedWith(comparator) - return VirtualBuffer(type,size) { this[permutations[it]] } + return VirtualBuffer(size) { this[permutations[it]] } } private fun Buffer.permSortIndicesWith(comparator: Comparator): IntArray { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt index 24d69602f..5746ff881 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferND.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.nd -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.BufferFactory @@ -24,8 +23,6 @@ public open class BufferND( public open val buffer: Buffer, ) : StructureND { - override val type: SafeType get() = buffer.type - @PerformancePitfall override operator fun get(index: IntArray): T = buffer[indices.offset(index)] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt index ab9b25663..4bb853af8 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Float64FieldND.kt @@ -5,11 +5,9 @@ package space.kscience.kmath.nd -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.operations.* -import space.kscience.kmath.structures.Float64 import space.kscience.kmath.structures.Float64Buffer import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -24,8 +22,6 @@ public class Float64BufferND( override val buffer: Float64Buffer, ) : MutableBufferND(indexes, buffer), MutableStructureNDOfDouble { - override val type: SafeType get() = Float64Field.type - override fun getDouble(index: IntArray): Double = buffer[indices.offset(index)] override fun setDouble(index: IntArray, value: Double) { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt index 8c835afee..28130c037 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/PermutedStructureND.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.nd -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall @@ -14,8 +13,6 @@ public class PermutedStructureND( public val permutation: (IntArray) -> IntArray, ) : StructureND { - override val type: SafeType get() = origin.type - override val shape: ShapeND get() = origin.shape @@ -35,8 +32,6 @@ public class PermutedMutableStructureND( public val permutation: (IntArray) -> IntArray, ) : MutableStructureND { - override val type: SafeType get() = origin.type - @OptIn(PerformancePitfall::class) override fun set(index: IntArray, value: T) { origin[permutation(index)] = value diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt index 5bc5ba744..14f2aa7c2 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure1D.kt @@ -5,12 +5,10 @@ package space.kscience.kmath.nd -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.operations.asSequence import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer -import space.kscience.kmath.structures.asMutableBuffer import kotlin.jvm.JvmInline /** @@ -48,8 +46,6 @@ public interface MutableStructure1D : Structure1D, MutableStructureND, @JvmInline private value class Structure1DWrapper(val structure: StructureND) : Structure1D { - override val type: SafeType get() = structure.type - override val shape: ShapeND get() = structure.shape override val size: Int get() = structure.shape[0] @@ -65,8 +61,6 @@ private value class Structure1DWrapper(val structure: StructureND) : S */ private class MutableStructure1DWrapper(val structure: MutableStructureND) : MutableStructure1D { - override val type: SafeType get() = structure.type - override val shape: ShapeND get() = structure.shape override val size: Int get() = structure.shape[0] @@ -81,13 +75,6 @@ private class MutableStructure1DWrapper(val structure: MutableStructureND) structure[intArrayOf(index)] = value } - @OptIn(PerformancePitfall::class) - override fun copy(): MutableBuffer = structure - .elements() - .map(Pair::second) - .toMutableList() - .asMutableBuffer(type) - override fun toString(): String = Buffer.toString(this) } @@ -98,8 +85,6 @@ private class MutableStructure1DWrapper(val structure: MutableStructureND) @JvmInline private value class Buffer1DWrapper(val buffer: Buffer) : Structure1D { - override val type: SafeType get() = buffer.type - override val shape: ShapeND get() = ShapeND(buffer.size) override val size: Int get() = buffer.size @@ -113,8 +98,6 @@ private value class Buffer1DWrapper(val buffer: Buffer) : Structure1D< internal class MutableBuffer1DWrapper(val buffer: MutableBuffer) : MutableStructure1D { - override val type: SafeType get() = buffer.type - override val shape: ShapeND get() = ShapeND(buffer.size) override val size: Int get() = buffer.size @@ -128,8 +111,6 @@ internal class MutableBuffer1DWrapper(val buffer: MutableBuffer) : Mutable buffer[index] = value } - override fun copy(): MutableBuffer = buffer.copy() - override fun toString(): String = Buffer.toString(this) } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt index a16f1082d..0a3209970 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/Structure2D.kt @@ -6,7 +6,6 @@ package space.kscience.kmath.nd import space.kscience.attributes.Attributes -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer @@ -36,14 +35,14 @@ public interface Structure2D : StructureND { */ @PerformancePitfall public val rows: List> - get() = List(rowNum) { i -> VirtualBuffer(type, colNum) { j -> get(i, j) } } + get() = List(rowNum) { i -> VirtualBuffer(colNum) { j -> get(i, j) } } /** * The buffer of columns for this structure. It gets elements from the structure dynamically. */ @PerformancePitfall public val columns: List> - get() = List(colNum) { j -> VirtualBuffer(type, rowNum) { i -> get(i, j) } } + get() = List(colNum) { j -> VirtualBuffer(rowNum) { i -> get(i, j) } } /** * Retrieves an element from the structure by two indices. @@ -79,8 +78,6 @@ public class MutableStructureNDAccessorBuffer( private val indexer: (Int) -> IntArray, ) : MutableBuffer { - override val type: SafeType get() = structure.type - override fun set(index: Int, value: T) { structure[indexer(index)] = value } @@ -88,8 +85,6 @@ public class MutableStructureNDAccessorBuffer( override fun get(index: Int): T = structure[indexer(index)] override fun toString(): String = "AccessorBuffer(structure=$structure, size=$size)" - - override fun copy(): MutableBuffer = MutableBuffer(type, size, ::get) } /** @@ -130,8 +125,6 @@ public interface MutableStructure2D : Structure2D, MutableStructureND { @JvmInline private value class Structure2DWrapper(val structure: StructureND) : Structure2D { - override val type: SafeType get() = structure.type - override val shape: ShapeND get() = structure.shape override val rowNum: Int get() = shape[0] @@ -152,8 +145,6 @@ private value class Structure2DWrapper(val structure: StructureND) : S */ private class MutableStructure2DWrapper(val structure: MutableStructureND) : MutableStructure2D { - override val type: SafeType get() = structure.type - override val shape: ShapeND get() = structure.shape override val rowNum: Int get() = shape[0] diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt index 12034df64..5c1021147 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/StructureND.kt @@ -5,7 +5,10 @@ package space.kscience.kmath.nd -import space.kscience.attributes.* +import space.kscience.attributes.Attribute +import space.kscience.attributes.AttributeContainer +import space.kscience.attributes.Attributes +import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.linear.LinearSpace import space.kscience.kmath.operations.Ring @@ -24,7 +27,7 @@ public interface StructureAttribute : Attribute * * @param T the type of items. */ -public interface StructureND : AttributeContainer, WithShape, WithType { +public interface StructureND : AttributeContainer, WithShape { /** * The shape of structure i.e., non-empty sequence of non-negative integers that specify sizes of dimensions for * this structure. diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt index 82c04e640..a7e0b0053 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/VirtualStructureND.kt @@ -5,13 +5,10 @@ package space.kscience.kmath.nd -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI public open class VirtualStructureND( - override val type: SafeType, override val shape: ShapeND, public val producer: (IntArray) -> T, ) : StructureND { @@ -27,10 +24,10 @@ public open class VirtualStructureND( public class VirtualDoubleStructureND( shape: ShapeND, producer: (IntArray) -> Double, -) : VirtualStructureND(safeTypeOf(), shape, producer) +) : VirtualStructureND(shape, producer) @UnstableKMathAPI public class VirtualIntStructureND( shape: ShapeND, producer: (IntArray) -> Int, -) : VirtualStructureND(safeTypeOf(), shape, producer) \ No newline at end of file +) : VirtualStructureND(shape, producer) \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt index 9e9361bca..b91f2bde5 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/operationsND.kt @@ -10,7 +10,7 @@ import space.kscience.kmath.PerformancePitfall @OptIn(PerformancePitfall::class) public fun StructureND.roll(axis: Int, step: Int = 1): StructureND { require(axis in shape.indices) { "Axis $axis is outside of shape dimensions: [0, ${shape.size})" } - return VirtualStructureND(type, shape) { index -> + return VirtualStructureND(shape) { index -> val newIndex: IntArray = IntArray(index.size) { indexAxis -> if (indexAxis == axis) { (index[indexAxis] + step).mod(shape[indexAxis]) @@ -26,7 +26,7 @@ public fun StructureND.roll(axis: Int, step: Int = 1): StructureND { public fun StructureND.roll(pair: Pair, vararg others: Pair): StructureND { val axisMap: Map = mapOf(pair, *others) require(axisMap.keys.all { it in shape.indices }) { "Some of axes ${axisMap.keys} is outside of shape dimensions: [0, ${shape.size})" } - return VirtualStructureND(type, shape) { index -> + return VirtualStructureND(shape) { index -> val newIndex: IntArray = IntArray(index.size) { indexAxis -> val offset = axisMap[indexAxis] ?: 0 (index[indexAxis] + offset).mod(shape[indexAxis]) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt index ca299f12f..4831b4138 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/primitiveStructureND.kt @@ -5,14 +5,9 @@ package space.kscience.kmath.nd -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall -import space.kscience.kmath.operations.Float64Field -import space.kscience.kmath.operations.Int32Field -import space.kscience.kmath.structures.Float64 public interface StructureNDOfDouble : StructureND { - override val type: SafeType get() = Float64Field.type /** * Guaranteed non-blocking access to content @@ -42,8 +37,6 @@ public fun MutableStructureND.getDouble(index: IntArray): Double = public interface StructureNDOfInt : StructureND { - override val type: SafeType get() = Int32Field.type - /** * Guaranteed non-blocking access to content */ diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt index 54d0b40b9..892f6a7c5 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ArrayBuffer.kt @@ -5,8 +5,7 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf +import kotlin.jvm.JvmInline /** * [MutableBuffer] implementation over [Array]. @@ -14,7 +13,8 @@ import space.kscience.attributes.safeTypeOf * @param T the type of elements contained in the buffer. * @property array The underlying array. */ -public class ArrayBuffer(override val type: SafeType, internal val array: Array) : MutableBuffer { +@JvmInline +public value class ArrayBuffer(internal val array: Array) : MutableBuffer { // Can't inline because array is invariant override val size: Int get() = array.size @@ -25,7 +25,6 @@ public class ArrayBuffer(override val type: SafeType, internal val array: } override operator fun iterator(): Iterator = array.iterator() - override fun copy(): MutableBuffer = ArrayBuffer(type, array.copyOf()) override fun toString(): String = Buffer.toString(this) } @@ -33,9 +32,4 @@ public class ArrayBuffer(override val type: SafeType, internal val array: /** * Returns an [ArrayBuffer] that wraps the original array. */ -public fun Array.asBuffer(type: SafeType): ArrayBuffer = ArrayBuffer(type, this) - -/** - * Returns an [ArrayBuffer] that wraps the original array. - */ -public inline fun Array.asBuffer(): ArrayBuffer = ArrayBuffer(safeTypeOf(), this) \ No newline at end of file +public fun Array.asBuffer(): ArrayBuffer = ArrayBuffer( this) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt index 4a0ac9416..7fc06c43e 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Buffer.kt @@ -66,7 +66,7 @@ public inline fun MutableBufferFactory(): MutableBufferFactory = * * @param T the type of elements contained in the buffer. */ -public interface Buffer : WithSize, WithType { +public interface Buffer : WithSize { /** * The size of this buffer. */ @@ -120,7 +120,7 @@ public fun Buffer( typeOf() -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer typeOf() -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer - else -> List(size, initializer).asBuffer(type) + else -> List(size, initializer).asBuffer() } /** @@ -139,7 +139,7 @@ public inline fun Buffer(size: Int, initializer: (Int) -> T): Buffer typeOf() -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer typeOf() -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer - else -> List(size, initializer).asBuffer(type) + else -> List(size, initializer).asBuffer() } } @@ -172,7 +172,6 @@ public fun Buffer.last(): T { * @param T the type of elements provided by the buffer. */ public class VirtualBuffer( - override val type: SafeType, override val size: Int, private val generator: (Int) -> T, ) : Buffer { @@ -185,11 +184,3 @@ public class VirtualBuffer( override fun toString(): String = Buffer.toString(this) } - -/** - * Inline builder for [VirtualBuffer] - */ -public inline fun VirtualBuffer( - size: Int, - noinline generator: (Int) -> T, -): VirtualBuffer = VirtualBuffer(safeTypeOf(), size, generator) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt index 5c8541f22..32990c707 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferAccessor2D.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType import space.kscience.kmath.nd.Structure2D /** @@ -33,7 +32,6 @@ internal class BufferAccessor2D( // ) { (i, j) -> get(i, j) }.as2D() inner class Row(val buffer: MutableBuffer, val rowIndex: Int) : MutableBuffer { - override val type: SafeType get() = buffer.type override val size: Int get() = colNum @@ -43,7 +41,6 @@ internal class BufferAccessor2D( buffer[rowIndex, index] = value } - override fun copy(): MutableBuffer = factory(colNum) { get(it) } override operator fun iterator(): Iterator = (0 until colNum).map(::get).iterator() override fun toString(): String = Buffer.toString(this) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt index ac8a9af14..180098f51 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/BufferView.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI /** @@ -14,8 +13,6 @@ import space.kscience.kmath.UnstableKMathAPI public interface BufferView : Buffer { public val origin: Buffer - override val type: SafeType get() = origin.type - /** * Get the index in [origin] buffer from index in this buffer. * Return -1 if element not present in the original buffer @@ -190,9 +187,7 @@ public class PermutedMutableBuffer( origin[permutations[index]] = value } - override fun copy(): MutableBuffer = PermutedMutableBuffer(origin.copy(), permutations) //TODO Probably could be optimized - override fun iterator(): Iterator = permutations.asSequence().map { origin[it] }.iterator() @UnstableKMathAPI diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FlaggedBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FlaggedBuffer.kt index 55729a9c2..ce31163a9 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FlaggedBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/FlaggedBuffer.kt @@ -5,8 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import kotlin.experimental.and /** @@ -60,8 +58,6 @@ public class FlaggedDoubleBuffer( public val flags: ByteArray ) : FlaggedBuffer, Buffer { - override val type: SafeType = safeTypeOf() - init { require(values.size == flags.size) { "Values and flags must have the same dimensions" } } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt index 9f564f450..7ad6c2a0d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float32Buffer.kt @@ -5,8 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -18,8 +16,6 @@ import kotlin.jvm.JvmInline @JvmInline public value class Float32Buffer(public val array: FloatArray) : PrimitiveBuffer { - override val type: SafeType get() = safeTypeOf() - override val size: Int get() = array.size override operator fun get(index: Int): Float = array[index] @@ -30,8 +26,6 @@ public value class Float32Buffer(public val array: FloatArray) : PrimitiveBuffer override operator fun iterator(): FloatIterator = array.iterator() - override fun copy(): MutableBuffer = - Float32Buffer(array.copyOf()) } public typealias FloatBuffer = Float32Buffer diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt index ca9e8ef9f..38b737fd5 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Float64Buffer.kt @@ -5,8 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import space.kscience.kmath.operations.BufferTransform import kotlin.jvm.JvmInline @@ -18,8 +16,6 @@ import kotlin.jvm.JvmInline @JvmInline public value class Float64Buffer(public val array: DoubleArray) : PrimitiveBuffer { - override val type: SafeType get() = safeTypeOf() - override val size: Int get() = array.size override operator fun get(index: Int): Double = array[index] @@ -30,8 +26,6 @@ public value class Float64Buffer(public val array: DoubleArray) : PrimitiveBuffe override operator fun iterator(): DoubleIterator = array.iterator() - override fun copy(): Float64Buffer = Float64Buffer(array.copyOf()) - override fun toString(): String = Buffer.toString(this) public companion object { diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt index 17d4cd36b..9ceeeec05 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int16Buffer.kt @@ -5,8 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -17,7 +15,7 @@ import kotlin.jvm.JvmInline @JvmInline public value class Int16Buffer(public val array: ShortArray) : MutableBuffer { - override val type: SafeType get() = safeTypeOf() + override val size: Int get() = array.size override operator fun get(index: Int): Short = array[index] @@ -27,7 +25,6 @@ public value class Int16Buffer(public val array: ShortArray) : MutableBuffer = Int16Buffer(array.copyOf()) } public typealias ShortBuffer = Int16Buffer diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt index 5cdebb7d7..bb41c2b9b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int32Buffer.kt @@ -5,8 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -17,7 +15,6 @@ import kotlin.jvm.JvmInline @JvmInline public value class Int32Buffer(public val array: IntArray) : PrimitiveBuffer { - override val type: SafeType get() = safeTypeOf() override val size: Int get() = array.size @@ -29,7 +26,6 @@ public value class Int32Buffer(public val array: IntArray) : PrimitiveBuffer { - override val type: SafeType get() = safeTypeOf() - override val size: Int get() = array.size override operator fun get(index: Int): Long = array[index] @@ -29,8 +25,6 @@ public value class Int64Buffer(public val array: LongArray) : PrimitiveBuffer = - Int64Buffer(array.copyOf()) } public typealias LongBuffer = Int64Buffer diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt index 1a7ca98b0..c7b1d43c5 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/Int8Buffer.kt @@ -5,8 +5,6 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import kotlin.jvm.JvmInline /** @@ -17,8 +15,6 @@ import kotlin.jvm.JvmInline @JvmInline public value class Int8Buffer(public val array: ByteArray) : MutableBuffer { - override val type: SafeType get() = safeTypeOf() - override val size: Int get() = array.size override operator fun get(index: Int): Byte = array[index] @@ -28,7 +24,6 @@ public value class Int8Buffer(public val array: ByteArray) : MutableBuffer } override operator fun iterator(): ByteIterator = array.iterator() - override fun copy(): MutableBuffer = Int8Buffer(array.copyOf()) } /** diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt index fc9ba4933..501bd1c64 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/ListBuffer.kt @@ -5,16 +5,13 @@ package space.kscience.kmath.structures -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf - /** * [Buffer] implementation over [List]. * * @param T the type of elements contained in the buffer. * @property list The underlying list. */ -public class ListBuffer(override val type: SafeType, public val list: List) : Buffer { +public class ListBuffer(public val list: List) : Buffer { override val size: Int get() = list.size @@ -28,12 +25,7 @@ public class ListBuffer(override val type: SafeType, public val list: List /** * Returns an [ListBuffer] that wraps the original list. */ -public fun List.asBuffer(type: SafeType): ListBuffer = ListBuffer(type, this) - -/** - * Returns an [ListBuffer] that wraps the original list. - */ -public inline fun List.asBuffer(): ListBuffer = asBuffer(safeTypeOf()) +public fun List.asBuffer(): ListBuffer = ListBuffer(this) /** * [MutableBuffer] implementation over [MutableList]. @@ -41,7 +33,7 @@ public inline fun List.asBuffer(): ListBuffer = asBuffer(safeT * @param T the type of elements contained in the buffer. * @property list The underlying list. */ -public class MutableListBuffer(override val type: SafeType, public val list: MutableList) : MutableBuffer { +public class MutableListBuffer(public val list: MutableList) : MutableBuffer { override val size: Int get() = list.size @@ -52,7 +44,6 @@ public class MutableListBuffer(override val type: SafeType, public val lis } override operator fun iterator(): Iterator = list.iterator() - override fun copy(): MutableBuffer = MutableListBuffer(type, ArrayList(list)) override fun toString(): String = Buffer.toString(this) } @@ -61,15 +52,4 @@ public class MutableListBuffer(override val type: SafeType, public val lis /** * Returns an [MutableListBuffer] that wraps the original list. */ -public fun MutableList.asMutableBuffer(type: SafeType): MutableListBuffer = MutableListBuffer( - type, - this -) - -/** - * Returns an [MutableListBuffer] that wraps the original list. - */ -public inline fun MutableList.asMutableBuffer(): MutableListBuffer = MutableListBuffer( - safeTypeOf(), - this -) +public fun MutableList.asMutableBuffer(): MutableListBuffer = MutableListBuffer(this) \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt index 0acfd13a1..be0c76618 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/MutableBuffer.kt @@ -14,16 +14,13 @@ import kotlin.reflect.typeOf * * @param T the type of elements contained in the buffer. */ -public interface MutableBuffer : Buffer { +public interface MutableBuffer : Buffer{ + /** * Sets the array element at the specified [index] to the specified [value]. */ public operator fun set(index: Int, value: T) - /** - * Returns a shallow copy of the buffer. - */ - public fun copy(): MutableBuffer public companion object { /** @@ -65,6 +62,25 @@ public interface MutableBuffer : Buffer { } +/** + * Returns a shallow copy of the buffer. + */ +public fun Buffer.copy(bufferFactory: BufferFactory): Buffer =if(this is ArrayBuffer){ + ArrayBuffer(array.copyOf()) +}else{ + bufferFactory(size,::get) +} + +/** + * Returns a mutable shallow copy of the buffer. + */ +public fun Buffer.mutableCopy(bufferFactory: MutableBufferFactory): MutableBuffer =if(this is ArrayBuffer){ + ArrayBuffer(array.copyOf()) +}else{ + bufferFactory(size,::get) +} + + /** * Creates a [MutableBuffer] of given [type]. If the type is primitive, specialized buffers are used * ([Int32Buffer], [Float64Buffer], etc.), [ListBuffer] is returned otherwise. @@ -84,7 +100,7 @@ public inline fun MutableBuffer( typeOf() -> MutableBuffer.float(size) { initializer(it) as Float } as MutableBuffer typeOf() -> MutableBuffer.double(size) { initializer(it) as Double } as MutableBuffer //TODO add unsigned types - else -> MutableListBuffer(type, MutableList(size, initializer)) + else -> MutableListBuffer(MutableList(size, initializer)) } /** diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt index f7863a68c..eb76d59dc 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/linear/MatrixTest.kt @@ -38,7 +38,7 @@ class MatrixTest { @Test fun testMatrixExtension() = Double.algebra.linearSpace.run { - val transitionMatrix: Matrix = VirtualMatrix(type,6, 6) { row, col -> + val transitionMatrix: Matrix = VirtualMatrix(6, 6) { row, col -> when { col == 0 -> .50 row + 1 == col -> .50 diff --git a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/structures/parallelMutableBuffer.kt b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/structures/parallelMutableBuffer.kt index c57dba41e..7eeb0dbbd 100644 --- a/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/structures/parallelMutableBuffer.kt +++ b/kmath-core/src/jvmMain/kotlin/space/kscience/kmath/structures/parallelMutableBuffer.kt @@ -33,7 +33,7 @@ public fun MutableBuffer.Companion.parallel( typeOf() -> IntStream.range(0, size).parallel().mapToDouble { initializer(it) as Float64 }.toArray() .asBuffer() as MutableBuffer //TODO add unsigned types - else -> IntStream.range(0, size).parallel().mapToObj { initializer(it) }.collect(Collectors.toList()).asMutableBuffer(type) + else -> IntStream.range(0, size).parallel().mapToObj { initializer(it) }.collect(Collectors.toList()).asMutableBuffer() } public class ParallelBufferFactory(override val type: SafeType) : MutableBufferFactory { diff --git a/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/linear/ParallelMatrixTest.kt b/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/linear/ParallelMatrixTest.kt index 493948361..915ec3c5e 100644 --- a/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/linear/ParallelMatrixTest.kt +++ b/kmath-core/src/jvmTest/kotlin/space/kscience/kmath/linear/ParallelMatrixTest.kt @@ -37,7 +37,7 @@ class ParallelMatrixTest { @Test fun testMatrixExtension() = Float64Field.linearSpace.parallel{ - val transitionMatrix: Matrix = VirtualMatrix(type,6, 6) { row, col -> + val transitionMatrix: Matrix = VirtualMatrix(6, 6) { row, col -> when { col == 0 -> .50 row + 1 == col -> .50 diff --git a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt index d40f145f6..3ee6b203a 100644 --- a/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt +++ b/kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/streaming/RingBuffer.kt @@ -7,22 +7,19 @@ package space.kscience.kmath.streaming import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock -import space.kscience.attributes.SafeType import space.kscience.kmath.operations.Group -import space.kscience.kmath.structures.Buffer -import space.kscience.kmath.structures.MutableBuffer -import space.kscience.kmath.structures.VirtualBuffer +import space.kscience.kmath.structures.* /** * Thread-safe ring buffer */ public class RingBuffer( private val buffer: MutableBuffer, + private val bufferFactory: BufferFactory, private var startIndex: Int = 0, size: Int = 0, ) : Buffer { - override val type: SafeType get() = buffer.type private val mutex: Mutex = Mutex() @@ -43,7 +40,7 @@ public class RingBuffer( override operator fun iterator(): Iterator = object : AbstractIterator() { private var count = size private var index = startIndex - val copy = buffer.copy() + val copy = buffer.copy(bufferFactory) override fun computeNext() { if (count == 0) done() else { @@ -58,8 +55,8 @@ public class RingBuffer( * A safe snapshot operation */ public suspend fun snapshot(): Buffer = mutex.withLock { - val copy = buffer.copy() - VirtualBuffer(type, size) { i -> copy[startIndex.forward(i)] } + val copy = buffer.copy(bufferFactory) + VirtualBuffer(size) { i -> copy[startIndex.forward(i)] } } public suspend fun push(element: T) { @@ -76,7 +73,7 @@ public class RingBuffer( public inline fun RingBuffer(size: Int, empty: T): RingBuffer { val buffer = MutableBuffer(size) { empty } - return RingBuffer(buffer) + return RingBuffer(buffer, BufferFactory()) } /** @@ -84,5 +81,5 @@ public inline fun RingBuffer(size: Int, empty: T): RingBuffer< */ public fun RingBuffer(size: Int, algebra: Group): RingBuffer { val buffer: MutableBuffer = MutableBuffer(algebra.type, size) { algebra.zero } - return RingBuffer(buffer) + return RingBuffer(buffer, algebra.bufferFactory) } diff --git a/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyStructureND.kt b/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyStructureND.kt index cb90c9b02..1d23162f5 100644 --- a/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyStructureND.kt +++ b/kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyStructureND.kt @@ -6,8 +6,6 @@ package space.kscience.kmath.structures import kotlinx.coroutines.* -import space.kscience.attributes.SafeType -import space.kscience.attributes.safeTypeOf import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.coroutines.Math import space.kscience.kmath.nd.ColumnStrides @@ -16,7 +14,6 @@ import space.kscience.kmath.nd.StructureND public class LazyStructureND( public val scope: CoroutineScope, - override val type: SafeType, override val shape: ShapeND, public val function: suspend (IntArray) -> T, ) : StructureND { @@ -54,10 +51,10 @@ public suspend fun StructureND.await(index: IntArray): T = public inline fun StructureND.mapAsyncIndexed( scope: CoroutineScope, crossinline function: suspend (T, index: IntArray) -> R, -): LazyStructureND = LazyStructureND(scope, safeTypeOf(), shape) { index -> function(get(index), index) } +): LazyStructureND = LazyStructureND(scope, shape) { index -> function(get(index), index) } @OptIn(PerformancePitfall::class) public inline fun StructureND.mapAsync( scope: CoroutineScope, crossinline function: suspend (T) -> R, -): LazyStructureND = LazyStructureND(scope, safeTypeOf(), shape) { index -> function(get(index)) } +): LazyStructureND = LazyStructureND(scope, shape) { index -> function(get(index)) } 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 d1de77d54..7ddc143ad 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 @@ -5,7 +5,6 @@ package space.kscience.kmath.dimensions -import space.kscience.attributes.SafeType import space.kscience.kmath.linear.* import space.kscience.kmath.nd.ShapeND import space.kscience.kmath.nd.Structure2D @@ -50,8 +49,6 @@ public value class DMatrixWrapper( private val structure: Structure2D, ) : DMatrix { - override val type: SafeType get() = structure.type - override val shape: ShapeND get() = structure.shape override val rowNum: Int get() = shape[0] override val colNum: Int get() = shape[1] @@ -81,8 +78,6 @@ public interface DPoint : Point { @JvmInline public value class DPointWrapper(public val point: Point) : DPoint { - override val type: SafeType get() = point.type - override val size: Int get() = point.size override operator fun get(index: Int): T = point[index] diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/implementations.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/implementations.kt index d33a74199..d196f5f1a 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/implementations.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/implementations.kt @@ -38,7 +38,6 @@ public class EjmlDoubleVector(override val origin: M) : EjmlVec require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } } - override val type: SafeType get() = safeTypeOf() override operator fun get(index: Int): Double = origin[0, index] } @@ -51,8 +50,6 @@ public class EjmlFloatVector(override val origin: M) : EjmlVect require(origin.numRows == 1) { "The origin matrix must have only one row to form a vector" } } - override val type: SafeType get() = safeTypeOf() - override operator fun get(index: Int): Float = origin[0, index] } @@ -60,8 +57,6 @@ public class EjmlFloatVector(override val origin: M) : EjmlVect * [EjmlMatrix] specialization for [Double]. */ public class EjmlDoubleMatrix(override val origin: M) : EjmlMatrix(origin) { - override val type: SafeType get() = safeTypeOf() - override operator fun get(i: Int, j: Int): Double = origin[i, j] } @@ -69,7 +64,6 @@ public class EjmlDoubleMatrix(override val origin: M) : EjmlMat * [EjmlMatrix] specialization for [Float]. */ public class EjmlFloatMatrix(override val origin: M) : EjmlMatrix(origin) { - override val type: SafeType get() = safeTypeOf() override operator fun get(i: Int, j: Int): Float = origin[i, j] } diff --git a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealMatrix.kt b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealMatrix.kt index cafae06d7..d36537d71 100644 --- a/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealMatrix.kt +++ b/kmath-for-real/src/commonMain/kotlin/space/kscience/kmath/real/RealMatrix.kt @@ -48,7 +48,7 @@ public fun Sequence.toMatrix(): RealMatrix = toList().let { } public fun RealMatrix.repeatStackVertical(n: Int): RealMatrix = - VirtualMatrix(type, rowNum * n, colNum) { row, col -> + VirtualMatrix( rowNum * n, colNum) { row, col -> get(if (row == 0) 0 else row % rowNum, col) } diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt index 11131515a..3b9808028 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt @@ -54,14 +54,14 @@ public fun > PolynomialInterpolator.interpolatePolynomials( public fun > PolynomialInterpolator.interpolatePolynomials( data: Map, ): PiecewisePolynomial { - val pointSet = XYColumnarData.of(data.keys.toList().asBuffer(type), data.values.toList().asBuffer(type)) + val pointSet = XYColumnarData.of(data.keys.toList().asBuffer(), data.values.toList().asBuffer()) return interpolatePolynomials(pointSet) } public fun > PolynomialInterpolator.interpolatePolynomials( data: List>, ): PiecewisePolynomial { - val pointSet = XYColumnarData.of(data.map { it.first }.asBuffer(type), data.map { it.second }.asBuffer(type)) + val pointSet = XYColumnarData.of(data.map { it.first }.asBuffer(), data.map { it.second }.asBuffer()) return interpolatePolynomials(pointSet) } diff --git a/kmath-geometry/build.gradle.kts b/kmath-geometry/build.gradle.kts index 32926db7e..4bf768f4b 100644 --- a/kmath-geometry/build.gradle.kts +++ b/kmath-geometry/build.gradle.kts @@ -6,6 +6,7 @@ kscience{ jvm() js() native() + wasm() useContextReceivers() useSerialization() diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt index 64396baff..71442cf63 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Vector3D.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.geometry -import space.kscience.attributes.SafeType import space.kscience.kmath.linear.Point import space.kscience.kmath.structures.Buffer @@ -34,9 +33,6 @@ public fun Buffer.asVector3D(): Vector3D = object : Vector3D { require(this@asVector3D.size == 3) { "Buffer of size 3 is required for Vector3D" } } - override val type: SafeType = this@asVector3D.type - - override val x: T get() = this@asVector3D[0] override val y: T get() = this@asVector3D[1] override val z: T get() = this@asVector3D[2] diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt index ed3caede8..ae140ff06 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float32Space2D.kt @@ -11,7 +11,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import space.kscience.attributes.SafeType import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector2D import space.kscience.kmath.operations.Float32Field @@ -20,10 +19,8 @@ import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.pow import kotlin.math.sqrt -@Serializable(Float32Space2D.VectorSerializer::class) -public interface Float32Vector2D : Vector2D{ - override val type: SafeType get() = Float32Field.type -} + +public typealias Float32Vector2D = Vector2D public object Float32Space2D : GeometrySpace, Float32> { diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt index 6a4f5ef34..37e11ba87 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean2d/Float64Space2D.kt @@ -11,7 +11,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import space.kscience.attributes.SafeType import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector2D import space.kscience.kmath.operations.Float64Field @@ -22,10 +21,7 @@ import kotlin.math.pow import kotlin.math.sqrt -@Serializable(Float64Space2D.VectorSerializer::class) -public interface Float64Vector2D : Vector2D { - override val type: SafeType get() = Float64Field.type -} +public typealias Float64Vector2D = Vector2D @Deprecated("Use Float64Vector2D", ReplaceWith("Float64Vector2D")) public typealias DoubleVector2D = Float64Vector2D diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt index 56ff49533..ad61a7b77 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float32Space3D.kt @@ -11,7 +11,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import space.kscience.attributes.SafeType import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector3D import space.kscience.kmath.operations.Float32Field @@ -20,10 +19,8 @@ import space.kscience.kmath.structures.MutableBufferFactory import kotlin.math.pow import kotlin.math.sqrt -@Serializable(Float32Space3D.VectorSerializer::class) -public interface Float32Vector3D : Vector3D{ - override val type: SafeType get() = Float32Field.type -} + +public typealias Float32Vector3D = Vector3D public object Float32Space3D : GeometrySpace, Float32> { diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt index 86ddf554b..fa07190bb 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/Float64Space3D.kt @@ -11,7 +11,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import space.kscience.attributes.SafeType import space.kscience.kmath.geometry.GeometrySpace import space.kscience.kmath.geometry.Vector3D import space.kscience.kmath.linear.Float64LinearSpace @@ -34,10 +33,7 @@ internal fun leviCivita(i: Int, j: Int, k: Int): Int = when { else -> 0 } -@Serializable(Float64Space3D.VectorSerializer::class) -public interface Float64Vector3D : Vector3D { - override val type: SafeType get() = Float64Field.type -} +public typealias Float64Vector3D = Vector3D @Deprecated("Use Float64Vector3D", ReplaceWith("Float64Vector3D")) public typealias DoubleVector3D = Float64Vector3D diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt index e65bd8e22..1275ad630 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/euclidean3d/rotations3D.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.geometry.euclidean3d -import space.kscience.attributes.SafeType import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.complex.* import space.kscience.kmath.geometry.* @@ -245,8 +244,6 @@ public fun Quaternion.Companion.fromEuler( * A vector consisting of angles */ public data class AngleVector(override val x: Angle, override val y: Angle, override val z: Angle) : Vector3D { - override val type: SafeType get() = Angle.type - public companion object } diff --git a/kmath-memory/api/kmath-memory.api b/kmath-memory/api/kmath-memory.api index 67303dd97..d8bfe6625 100644 --- a/kmath-memory/api/kmath-memory.api +++ b/kmath-memory/api/kmath-memory.api @@ -38,7 +38,6 @@ public class space/kscience/kmath/memory/MemoryBuffer : space/kscience/kmath/str protected final fun getMemory ()Lspace/kscience/kmath/memory/Memory; public fun getSize ()I protected final fun getSpec ()Lspace/kscience/kmath/memory/MemorySpec; - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun iterator ()Ljava/util/Iterator; public fun toString ()Ljava/lang/String; } @@ -90,7 +89,6 @@ public abstract interface class space/kscience/kmath/memory/MemoryWriter : java/ public final class space/kscience/kmath/memory/MutableMemoryBuffer : space/kscience/kmath/memory/MemoryBuffer, space/kscience/kmath/structures/MutableBuffer { public static final field Companion Lspace/kscience/kmath/memory/MutableMemoryBuffer$Companion; public fun (Lspace/kscience/kmath/memory/Memory;Lspace/kscience/kmath/memory/MemorySpec;)V - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; public fun set (ILjava/lang/Object;)V } diff --git a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemoryBuffer.kt b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemoryBuffer.kt index ea6e705b6..27deea126 100644 --- a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemoryBuffer.kt +++ b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/MemoryBuffer.kt @@ -5,7 +5,6 @@ package space.kscience.kmath.memory -import space.kscience.attributes.SafeType import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer @@ -18,8 +17,6 @@ import space.kscience.kmath.structures.MutableBuffer */ public open class MemoryBuffer(protected val memory: Memory, protected val spec: MemorySpec) : Buffer { - override val type: SafeType get() = spec.type - override val size: Int get() = memory.size / spec.objectSize override operator fun get(index: Int): T = memory.read { read(spec, spec.objectSize * index) } @@ -56,7 +53,6 @@ public class MutableMemoryBuffer( private val writer: MemoryWriter = memory.writer() override operator fun set(index: Int, value: T): Unit = writer.write(spec, spec.objectSize * index, value) - override fun copy(): MutableBuffer = MutableMemoryBuffer(memory.copy(), spec) public companion object { public fun create(spec: MemorySpec, size: Int): MutableMemoryBuffer = diff --git a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt index 7ce9825d3..1c6dfe806 100644 --- a/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt +++ b/kmath-multik/src/commonMain/kotlin/space/kscience/kmath/multik/MultikTensor.kt @@ -30,8 +30,6 @@ public val DataType.type: SafeType<*> @JvmInline public value class MultikTensor(public val array: MutableMultiArray) : Tensor { - @Suppress("UNCHECKED_CAST") - override val type: SafeType get() = array.dtype.type as SafeType override val shape: ShapeND get() = ShapeND(array.shape) diff --git a/kmath-nd4j/api/kmath-nd4j.api b/kmath-nd4j/api/kmath-nd4j.api index 74c6b8805..5a9a7985d 100644 --- a/kmath-nd4j/api/kmath-nd4j.api +++ b/kmath-nd4j/api/kmath-nd4j.api @@ -202,7 +202,6 @@ public final class space/kscience/kmath/nd4j/Nd4jArrayFloatStructure : space/ksc public fun get ([I)Ljava/lang/Float; public synthetic fun get ([I)Ljava/lang/Object; public fun getNdArray ()Lorg/nd4j/linalg/api/ndarray/INDArray; - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun hashCode ()I public fun set ([IF)V public synthetic fun set ([ILjava/lang/Object;)V diff --git a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructure.kt b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructure.kt index 9bfc2f8f5..ac4ef68d2 100644 --- a/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructure.kt +++ b/kmath-nd4j/src/main/kotlin/space/kscience/kmath/nd4j/Nd4jArrayStructure.kt @@ -6,10 +6,8 @@ package space.kscience.kmath.nd4j import org.nd4j.linalg.api.ndarray.INDArray -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.* -import space.kscience.kmath.operations.Float32Field /** * Represents a [StructureND] wrapping an [INDArray] object. @@ -70,8 +68,6 @@ public fun INDArray.asDoubleStructure(): Nd4jArrayStructure = Nd4jArrayD public data class Nd4jArrayFloatStructure(override val ndArray: INDArray) : Nd4jArrayStructure() { - override val type: SafeType get() = Float32Field.type - override fun elementsIterator(): Iterator> = ndArray.floatIterator() @PerformancePitfall diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt index 96acf559a..8f0aa1729 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/ValueAndErrorField.kt @@ -64,7 +64,6 @@ public object ValueAndErrorField : Field { require(values.size == ds.size) } - override val type: SafeType get() = safeTypeOf() override val size: Int get() = values.size @@ -77,7 +76,6 @@ public object ValueAndErrorField : Field { values[index] = value.dispersion } - override fun copy(): MutableBuffer = ValueAndErrorBuffer(values.copy(), ds.copy()) } override val bufferFactory: MutableBufferFactory = object : MutableBufferFactory { diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt index 9a559bc28..516a3a2ce 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/DoubleTensorFlowAlgebra.kt @@ -10,7 +10,6 @@ import org.tensorflow.Output import org.tensorflow.ndarray.NdArray import org.tensorflow.op.core.Constant import org.tensorflow.types.TFloat64 -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.expressions.Symbol @@ -26,7 +25,6 @@ public class DoubleTensorFlowOutput( graph: Graph, output: Output, ) : TensorFlowOutput(graph, output) { - override val type: SafeType get() = Float64Field.type override fun org.tensorflow.Tensor.actualizeTensor(): NdArray = this as TFloat64 } diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt index 3695a2640..95ed52638 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/IntTensorFlowAlgebra.kt @@ -10,19 +10,12 @@ import org.tensorflow.Output import org.tensorflow.ndarray.NdArray import org.tensorflow.types.TInt32 import org.tensorflow.types.TInt64 -import space.kscience.attributes.SafeType -import space.kscience.kmath.operations.Int32Ring -import space.kscience.kmath.operations.Int64Ring -import space.kscience.kmath.structures.Int32 -import space.kscience.kmath.structures.Int64 public class IntTensorFlowOutput( graph: Graph, output: Output, ) : TensorFlowOutput(graph, output) { - override val type: SafeType get() = Int32Ring.type - override fun org.tensorflow.Tensor.actualizeTensor(): NdArray = this as TInt32 } @@ -31,6 +24,5 @@ public class LongTensorFlowOutput( output: Output, ) : TensorFlowOutput(graph, output) { - override val type: SafeType get() = Int64Ring.type override fun org.tensorflow.Tensor.actualizeTensor(): NdArray = this as TInt64 } \ No newline at end of file diff --git a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt index 7e413c29c..2a8720275 100644 --- a/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt +++ b/kmath-tensorflow/src/main/kotlin/space/kscience/kmath/tensorflow/TensorFlowAlgebra.kt @@ -17,7 +17,6 @@ import org.tensorflow.op.core.* import org.tensorflow.types.TInt32 import org.tensorflow.types.family.TNumber import org.tensorflow.types.family.TType -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnsafeKMathAPI import space.kscience.kmath.UnstableKMathAPI @@ -40,7 +39,8 @@ public sealed interface TensorFlowTensor : Tensor /** * Static (eager) in-memory TensorFlow tensor */ -public class TensorFlowArray(override val type: SafeType, public val tensor: NdArray) : Tensor { +@JvmInline +public value class TensorFlowArray(public val tensor: NdArray) : Tensor { override val shape: ShapeND get() = ShapeND(tensor.shape().asArray().toIntArray()) @@ -74,7 +74,7 @@ public abstract class TensorFlowOutput( internal val actualTensor by lazy { Session(graph).use { session -> - TensorFlowArray(type, session.runner().fetch(output).run().first().actualizeTensor()) + TensorFlowArray(session.runner().fetch(output).run().first().actualizeTensor()) } } diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt index b150c9839..b3c2eb1b4 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor.kt @@ -5,12 +5,10 @@ package space.kscience.kmath.tensors.core -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.MutableStructureNDOfDouble import space.kscience.kmath.nd.ShapeND -import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.structures.* import space.kscience.kmath.tensors.core.internal.toPrettyString @@ -36,7 +34,7 @@ public class OffsetDoubleBuffer( /** * Copy only a part of buffer that belongs to this [OffsetDoubleBuffer] */ - override fun copy(): Float64Buffer = origin.array.copyOfRange(offset, offset + size).asBuffer() + public fun copy(): Float64Buffer = origin.array.copyOfRange(offset, offset + size).asBuffer() override fun iterator(): Iterator = iterator { for (i in indices) { @@ -90,8 +88,6 @@ public open class DoubleTensor( final override val source: OffsetDoubleBuffer, ) : BufferedTensor(shape), MutableStructureNDOfDouble { - override val type: SafeType get() = DoubleField.type - init { require(linearSize == source.size) { "Source buffer size must be equal tensor size" } } diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor1D.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor1D.kt index 74a4f65c4..05f1b2f20 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor1D.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensor1D.kt @@ -8,7 +8,6 @@ package space.kscience.kmath.tensors.core import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.MutableStructure1D import space.kscience.kmath.nd.ShapeND -import space.kscience.kmath.structures.MutableBuffer public class DoubleTensor1D( source: OffsetDoubleBuffer, @@ -30,8 +29,6 @@ public class DoubleTensor1D( source[index] = value } - override fun copy(): MutableBuffer = source.copy() - @PerformancePitfall override fun elements(): Sequence> = super.elements() } diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt index 4c00933db..eb95d5e70 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/IntTensor.kt @@ -5,10 +5,8 @@ package space.kscience.kmath.tensors.core -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.ShapeND -import space.kscience.kmath.operations.IntRing import space.kscience.kmath.structures.* /** @@ -26,8 +24,6 @@ public class OffsetIntBuffer( require(offset + size <= source.size) { "Maximum index must be inside source dimension" } } - override val type: SafeType get() = IntRing.type - override fun set(index: Int, value: Int) { require(index in 0 until size) { "Index must be in [0, size)" } source[index + offset] = value @@ -38,7 +34,7 @@ public class OffsetIntBuffer( /** * Copy only a part of buffer that belongs to this tensor */ - override fun copy(): Int32Buffer = source.array.copyOfRange(offset, offset + size).asBuffer() + public fun copy(): Int32Buffer = source.array.copyOfRange(offset, offset + size).asBuffer() override fun iterator(): Iterator = iterator { for (i in indices) { @@ -87,7 +83,6 @@ public class IntTensor( require(linearSize == source.size) { "Source buffer size must be equal tensor size" } } - override val type: SafeType get() = IntRing.type public constructor(shape: ShapeND, buffer: Int32Buffer) : this(shape, OffsetIntBuffer(buffer, 0, buffer.size)) diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorTransform.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorTransform.kt index bafd3fadd..6490ecdb9 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorTransform.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/tensorTransform.kt @@ -17,7 +17,7 @@ import space.kscience.kmath.tensors.api.Tensor public fun StructureND.copyToTensor(): DoubleTensor = if (this is DoubleTensor) { DoubleTensor(shape, source.copy()) } else if (this is Float64BufferND && indices is RowStrides) { - DoubleTensor(shape, buffer.copy()) + DoubleTensor(shape, buffer.array.copyOf().asBuffer()) } else { DoubleTensor( shape, diff --git a/kmath-viktor/api/kmath-viktor.api b/kmath-viktor/api/kmath-viktor.api index 11e312e12..0ad7368a9 100644 --- a/kmath-viktor/api/kmath-viktor.api +++ b/kmath-viktor/api/kmath-viktor.api @@ -1,8 +1,6 @@ public final class space/kscience/kmath/viktor/ViktorBuffer : space/kscience/kmath/structures/MutableBuffer { public static final synthetic fun box-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lspace/kscience/kmath/viktor/ViktorBuffer; public static fun constructor-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lorg/jetbrains/bio/viktor/F64FlatArray; - public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer; - public static fun copy-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lspace/kscience/kmath/structures/MutableBuffer; public fun equals (Ljava/lang/Object;)Z public static fun equals-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;Ljava/lang/Object;)Z public static final fun equals-impl0 (Lorg/jetbrains/bio/viktor/F64FlatArray;Lorg/jetbrains/bio/viktor/F64FlatArray;)Z @@ -12,8 +10,6 @@ public final class space/kscience/kmath/viktor/ViktorBuffer : space/kscience/kma public final fun getFlatArray ()Lorg/jetbrains/bio/viktor/F64FlatArray; public fun getSize ()I public static fun getSize-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; - public static fun getType-V0oMfBY (Lorg/jetbrains/bio/viktor/F64FlatArray;)Lkotlin/reflect/KType; public fun hashCode ()I public static fun hashCode-impl (Lorg/jetbrains/bio/viktor/F64FlatArray;)I public fun iterator ()Ljava/util/Iterator; @@ -115,7 +111,6 @@ public final class space/kscience/kmath/viktor/ViktorStructureND : space/kscienc public synthetic fun get ([I)Ljava/lang/Object; public final fun getF64Buffer ()Lorg/jetbrains/bio/viktor/F64Array; public fun getShape-IIYLAfE ()[I - public fun getType-V0oMfBY ()Lkotlin/reflect/KType; public fun set ([ID)V public synthetic fun set ([ILjava/lang/Object;)V } diff --git a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt index 88112af2a..89b51f269 100644 --- a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt +++ b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorBuffer.kt @@ -6,15 +6,12 @@ package space.kscience.kmath.viktor import org.jetbrains.bio.viktor.F64FlatArray -import space.kscience.attributes.SafeType -import space.kscience.kmath.operations.Float64Field import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.MutableBuffer @Suppress("NOTHING_TO_INLINE", "OVERRIDE_BY_INLINE") @JvmInline public value class ViktorBuffer(public val flatArray: F64FlatArray) : MutableBuffer { - override val type: SafeType get() = Float64Field.type override val size: Int get() = flatArray.length @@ -25,7 +22,6 @@ public value class ViktorBuffer(public val flatArray: F64FlatArray) : MutableBuf flatArray[index] = value } - override fun copy(): MutableBuffer = ViktorBuffer(flatArray.copy().flatten()) override operator fun iterator(): Iterator = flatArray.data.iterator() override fun toString(): String = Buffer.toString(this) diff --git a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorStructureND.kt b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorStructureND.kt index 9e01fd88a..328a0ab01 100644 --- a/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorStructureND.kt +++ b/kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorStructureND.kt @@ -6,17 +6,13 @@ package space.kscience.kmath.viktor import org.jetbrains.bio.viktor.F64Array -import space.kscience.attributes.SafeType import space.kscience.kmath.PerformancePitfall import space.kscience.kmath.nd.ColumnStrides import space.kscience.kmath.nd.MutableStructureND import space.kscience.kmath.nd.ShapeND -import space.kscience.kmath.operations.Float64Field @Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") public class ViktorStructureND(public val f64Buffer: F64Array) : MutableStructureND { - override val type: SafeType get() = Float64Field.type - override val shape: ShapeND get() = ShapeND(f64Buffer.shape) @OptIn(PerformancePitfall::class)