forked from kscience/kmath
Reverse types for buffers and typealiases for geometry.
This commit is contained in:
parent
dba001eff3
commit
fcb7e2fa7d
@ -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
|
||||
|
@ -14,7 +14,7 @@ allprojects {
|
||||
}
|
||||
|
||||
group = "space.kscience"
|
||||
version = "0.4.0-RC"
|
||||
version = "0.4.0-RC2"
|
||||
}
|
||||
|
||||
subprojects {
|
||||
|
@ -23,7 +23,7 @@ import space.kscience.kmath.structures.IntBuffer
|
||||
import space.kscience.kmath.structures.asBuffer
|
||||
|
||||
public class CMMatrix(public val origin: RealMatrix) : Matrix<Double> {
|
||||
override val type: SafeType<Double> 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<Double> {
|
||||
|
||||
@JvmInline
|
||||
public value class CMVector(public val origin: RealVector) : Point<Double> {
|
||||
override val type: SafeType<Double> get() = DoubleField.type
|
||||
override val size: Int get() = origin.dimension
|
||||
|
||||
override operator fun get(index: Int): Double = origin.getEntry(index)
|
||||
|
@ -36,8 +36,6 @@ public class Quaternion(
|
||||
require(!z.isNaN()) { "z-component of quaternion is not-a-number" }
|
||||
}
|
||||
|
||||
override val type: SafeType<Double> get() = safeTypeOf()
|
||||
|
||||
/**
|
||||
* Returns a string representation of this quaternion.
|
||||
*/
|
||||
|
@ -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 <init> (Lkotlin/reflect/KType;IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> (Lkotlin/reflect/KType;IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun <init> (IILspace/kscience/attributes/Attributes;Lkotlin/jvm/functions/Function2;)V
|
||||
public synthetic fun <init> (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 <init> (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 <init> (Lkotlin/reflect/KType;[ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> ([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 <init> (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 <init> (Lkotlin/reflect/KType;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun <init> (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 <init> (Lkotlin/reflect/KType;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer;
|
||||
public fun <init> (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 <init> (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 <init> (Lkotlin/reflect/KType;ILkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public fun <init> (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;
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ public abstract class DSAlgebra<T, A : Ring<T>>(
|
||||
vararg derivatives: T,
|
||||
): DS<T, A> {
|
||||
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)
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class DerivationResult<T : Any>(
|
||||
*/
|
||||
public fun <T : Any> DerivationResult<T>.grad(vararg variables: Symbol): Point<T> {
|
||||
check(variables.isNotEmpty()) { "Variable order is not provided for gradient construction" }
|
||||
return variables.map(::derivative).asBuffer(type)
|
||||
return variables.map(::derivative).asBuffer()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -227,4 +227,4 @@ public fun <T> Matrix<T>.asVector(): Point<T> =
|
||||
* @receiver a buffer.
|
||||
* @return the new matrix.
|
||||
*/
|
||||
public fun <T> Point<T>.asMatrix(): VirtualMatrix<T> = VirtualMatrix(type, size, 1) { i, _ -> get(i) }
|
||||
public fun <T> Point<T>.asMatrix(): VirtualMatrix<T> = VirtualMatrix(size, 1) { i, _ -> get(i) }
|
@ -27,7 +27,7 @@ public interface LupDecomposition<T> {
|
||||
* Create a pivot matrix from pivot vector using provided [LinearSpace]
|
||||
*/
|
||||
public fun <T> LupDecomposition<T>.pivotMatrix(linearSpace: LinearSpace<T, Ring<T>>): Matrix<T> =
|
||||
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<T>(
|
||||
|
||||
|
||||
override val l: Matrix<T>
|
||||
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<T>(
|
||||
}
|
||||
|
||||
override val u: Matrix<T>
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public fun <T> Matrix<T>.modifyAttributes(modifier: (Attributes) -> Attributes):
|
||||
public fun <T> LinearSpace<T, Ring<T>>.one(
|
||||
rows: Int,
|
||||
columns: Int,
|
||||
): MatrixWrapper<T> = VirtualMatrix(type, rows, columns) { i, j ->
|
||||
): MatrixWrapper<T> = VirtualMatrix(rows, columns) { i, j ->
|
||||
if (i == j) elementAlgebra.one else elementAlgebra.zero
|
||||
}.withAttribute(IsUnit)
|
||||
|
||||
@ -79,6 +79,6 @@ public fun <T> LinearSpace<T, Ring<T>>.one(
|
||||
public fun <T> LinearSpace<T, Ring<T>>.zero(
|
||||
rows: Int,
|
||||
columns: Int,
|
||||
): MatrixWrapper<T> = VirtualMatrix(type, rows, columns) { _, _ ->
|
||||
): MatrixWrapper<T> = VirtualMatrix(rows, columns) { _, _ ->
|
||||
elementAlgebra.zero
|
||||
}.withAttribute(IsZero)
|
||||
|
@ -6,11 +6,9 @@
|
||||
package space.kscience.kmath.linear
|
||||
|
||||
import space.kscience.attributes.Attributes
|
||||
import space.kscience.attributes.SafeType
|
||||
|
||||
|
||||
public class TransposedMatrix<T>(public val origin: Matrix<T>) : Matrix<T> {
|
||||
override val type: SafeType<T> get() = origin.type
|
||||
|
||||
override val rowNum: Int get() = origin.colNum
|
||||
|
||||
|
@ -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<out T>(
|
||||
override val type: SafeType<T>,
|
||||
override val rowNum: Int,
|
||||
override val colNum: Int,
|
||||
override val attributes: Attributes = Attributes.EMPTY,
|
||||
@ -31,4 +29,4 @@ public class VirtualMatrix<out T>(
|
||||
public fun <T : Any> MatrixBuilder<T, *>.virtual(
|
||||
attributes: Attributes = Attributes.EMPTY,
|
||||
generator: (i: Int, j: Int) -> T,
|
||||
): VirtualMatrix<T> = VirtualMatrix(type, rows, columns, attributes, generator)
|
||||
): VirtualMatrix<T> = VirtualMatrix(rows, columns, attributes, generator)
|
||||
|
@ -26,7 +26,7 @@ public fun <V : Comparable<V>> Buffer<V>.indicesSorted(): IntArray = permSortInd
|
||||
*/
|
||||
public fun <V : Comparable<V>> Buffer<V>.sorted(): Buffer<V> {
|
||||
val permutations = indicesSorted()
|
||||
return VirtualBuffer(type, size) { this[permutations[it]] }
|
||||
return VirtualBuffer(size) { this[permutations[it]] }
|
||||
}
|
||||
|
||||
@UnstableKMathAPI
|
||||
@ -38,7 +38,7 @@ public fun <V : Comparable<V>> Buffer<V>.indicesSortedDescending(): IntArray =
|
||||
*/
|
||||
public fun <V : Comparable<V>> Buffer<V>.sortedDescending(): Buffer<V> {
|
||||
val permutations = indicesSortedDescending()
|
||||
return VirtualBuffer(type, size) { this[permutations[it]] }
|
||||
return VirtualBuffer(size) { this[permutations[it]] }
|
||||
}
|
||||
|
||||
@UnstableKMathAPI
|
||||
@ -47,7 +47,7 @@ public fun <V, C : Comparable<C>> Buffer<V>.indicesSortedBy(selector: (V) -> C):
|
||||
|
||||
public fun <V, C : Comparable<C>> Buffer<V>.sortedBy(selector: (V) -> C): Buffer<V> {
|
||||
val permutations = indicesSortedBy(selector)
|
||||
return VirtualBuffer(type, size) { this[permutations[it]] }
|
||||
return VirtualBuffer(size) { this[permutations[it]] }
|
||||
}
|
||||
|
||||
@UnstableKMathAPI
|
||||
@ -56,7 +56,7 @@ public fun <V, C : Comparable<C>> Buffer<V>.indicesSortedByDescending(selector:
|
||||
|
||||
public fun <V, C : Comparable<C>> Buffer<V>.sortedByDescending(selector: (V) -> C): Buffer<V> {
|
||||
val permutations = indicesSortedByDescending(selector)
|
||||
return VirtualBuffer(type, size) { this[permutations[it]] }
|
||||
return VirtualBuffer(size) { this[permutations[it]] }
|
||||
}
|
||||
|
||||
@UnstableKMathAPI
|
||||
@ -68,7 +68,7 @@ public fun <V> Buffer<V>.indicesSortedWith(comparator: Comparator<V>): IntArray
|
||||
*/
|
||||
public fun <V> Buffer<V>.sortedWith(comparator: Comparator<V>): Buffer<V> {
|
||||
val permutations = indicesSortedWith(comparator)
|
||||
return VirtualBuffer(type,size) { this[permutations[it]] }
|
||||
return VirtualBuffer(size) { this[permutations[it]] }
|
||||
}
|
||||
|
||||
private fun <V> Buffer<V>.permSortIndicesWith(comparator: Comparator<Int>): IntArray {
|
||||
|
@ -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<out T>(
|
||||
public open val buffer: Buffer<T>,
|
||||
) : StructureND<T> {
|
||||
|
||||
override val type: SafeType<T> get() = buffer.type
|
||||
|
||||
@PerformancePitfall
|
||||
override operator fun get(index: IntArray): T = buffer[indices.offset(index)]
|
||||
|
||||
|
@ -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<Double>(indexes, buffer), MutableStructureNDOfDouble {
|
||||
|
||||
override val type: SafeType<Float64> get() = Float64Field.type
|
||||
|
||||
override fun getDouble(index: IntArray): Double = buffer[indices.offset(index)]
|
||||
|
||||
override fun setDouble(index: IntArray, value: Double) {
|
||||
|
@ -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<T>(
|
||||
public val permutation: (IntArray) -> IntArray,
|
||||
) : StructureND<T> {
|
||||
|
||||
override val type: SafeType<T> get() = origin.type
|
||||
|
||||
override val shape: ShapeND
|
||||
get() = origin.shape
|
||||
|
||||
@ -35,8 +32,6 @@ public class PermutedMutableStructureND<T>(
|
||||
public val permutation: (IntArray) -> IntArray,
|
||||
) : MutableStructureND<T> {
|
||||
|
||||
override val type: SafeType<T> get() = origin.type
|
||||
|
||||
@OptIn(PerformancePitfall::class)
|
||||
override fun set(index: IntArray, value: T) {
|
||||
origin[permutation(index)] = value
|
||||
|
@ -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<T> : Structure1D<T>, MutableStructureND<T>,
|
||||
@JvmInline
|
||||
private value class Structure1DWrapper<out T>(val structure: StructureND<T>) : Structure1D<T> {
|
||||
|
||||
override val type: SafeType<T> 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<out T>(val structure: StructureND<T>) : S
|
||||
*/
|
||||
private class MutableStructure1DWrapper<T>(val structure: MutableStructureND<T>) : MutableStructure1D<T> {
|
||||
|
||||
override val type: SafeType<T> 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<T>(val structure: MutableStructureND<T>)
|
||||
structure[intArrayOf(index)] = value
|
||||
}
|
||||
|
||||
@OptIn(PerformancePitfall::class)
|
||||
override fun copy(): MutableBuffer<T> = structure
|
||||
.elements()
|
||||
.map(Pair<IntArray, T>::second)
|
||||
.toMutableList()
|
||||
.asMutableBuffer(type)
|
||||
|
||||
override fun toString(): String = Buffer.toString(this)
|
||||
}
|
||||
|
||||
@ -98,8 +85,6 @@ private class MutableStructure1DWrapper<T>(val structure: MutableStructureND<T>)
|
||||
@JvmInline
|
||||
private value class Buffer1DWrapper<out T>(val buffer: Buffer<T>) : Structure1D<T> {
|
||||
|
||||
override val type: SafeType<T> 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<out T>(val buffer: Buffer<T>) : Structure1D<
|
||||
|
||||
internal class MutableBuffer1DWrapper<T>(val buffer: MutableBuffer<T>) : MutableStructure1D<T> {
|
||||
|
||||
override val type: SafeType<T> 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<T>(val buffer: MutableBuffer<T>) : Mutable
|
||||
buffer[index] = value
|
||||
}
|
||||
|
||||
override fun copy(): MutableBuffer<T> = buffer.copy()
|
||||
|
||||
override fun toString(): String = Buffer.toString(this)
|
||||
}
|
||||
|
||||
|
@ -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<out T> : StructureND<T> {
|
||||
*/
|
||||
@PerformancePitfall
|
||||
public val rows: List<Buffer<T>>
|
||||
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<Buffer<T>>
|
||||
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<T>(
|
||||
private val indexer: (Int) -> IntArray,
|
||||
) : MutableBuffer<T> {
|
||||
|
||||
override val type: SafeType<T> get() = structure.type
|
||||
|
||||
override fun set(index: Int, value: T) {
|
||||
structure[indexer(index)] = value
|
||||
}
|
||||
@ -88,8 +85,6 @@ public class MutableStructureNDAccessorBuffer<T>(
|
||||
override fun get(index: Int): T = structure[indexer(index)]
|
||||
|
||||
override fun toString(): String = "AccessorBuffer(structure=$structure, size=$size)"
|
||||
|
||||
override fun copy(): MutableBuffer<T> = MutableBuffer(type, size, ::get)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,8 +125,6 @@ public interface MutableStructure2D<T> : Structure2D<T>, MutableStructureND<T> {
|
||||
@JvmInline
|
||||
private value class Structure2DWrapper<out T>(val structure: StructureND<T>) : Structure2D<T> {
|
||||
|
||||
override val type: SafeType<T> 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<out T>(val structure: StructureND<T>) : S
|
||||
*/
|
||||
private class MutableStructure2DWrapper<T>(val structure: MutableStructureND<T>) : MutableStructure2D<T> {
|
||||
|
||||
override val type: SafeType<T> get() = structure.type
|
||||
|
||||
override val shape: ShapeND get() = structure.shape
|
||||
|
||||
override val rowNum: Int get() = shape[0]
|
||||
|
@ -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<T> : Attribute<T>
|
||||
*
|
||||
* @param T the type of items.
|
||||
*/
|
||||
public interface StructureND<out T> : AttributeContainer, WithShape, WithType<T> {
|
||||
public interface StructureND<out T> : AttributeContainer, WithShape {
|
||||
/**
|
||||
* The shape of structure i.e., non-empty sequence of non-negative integers that specify sizes of dimensions for
|
||||
* this structure.
|
||||
|
@ -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<T>(
|
||||
override val type: SafeType<T>,
|
||||
override val shape: ShapeND,
|
||||
public val producer: (IntArray) -> T,
|
||||
) : StructureND<T> {
|
||||
@ -27,10 +24,10 @@ public open class VirtualStructureND<T>(
|
||||
public class VirtualDoubleStructureND(
|
||||
shape: ShapeND,
|
||||
producer: (IntArray) -> Double,
|
||||
) : VirtualStructureND<Double>(safeTypeOf(), shape, producer)
|
||||
) : VirtualStructureND<Double>(shape, producer)
|
||||
|
||||
@UnstableKMathAPI
|
||||
public class VirtualIntStructureND(
|
||||
shape: ShapeND,
|
||||
producer: (IntArray) -> Int,
|
||||
) : VirtualStructureND<Int>(safeTypeOf(), shape, producer)
|
||||
) : VirtualStructureND<Int>(shape, producer)
|
@ -10,7 +10,7 @@ import space.kscience.kmath.PerformancePitfall
|
||||
@OptIn(PerformancePitfall::class)
|
||||
public fun <T> StructureND<T>.roll(axis: Int, step: Int = 1): StructureND<T> {
|
||||
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 <T> StructureND<T>.roll(axis: Int, step: Int = 1): StructureND<T> {
|
||||
public fun <T> StructureND<T>.roll(pair: Pair<Int, Int>, vararg others: Pair<Int, Int>): StructureND<T> {
|
||||
val axisMap: Map<Int, Int> = 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])
|
||||
|
@ -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<Double> {
|
||||
override val type: SafeType<Float64> get() = Float64Field.type
|
||||
|
||||
/**
|
||||
* Guaranteed non-blocking access to content
|
||||
@ -42,8 +37,6 @@ public fun MutableStructureND<Double>.getDouble(index: IntArray): Double =
|
||||
|
||||
public interface StructureNDOfInt : StructureND<Int> {
|
||||
|
||||
override val type: SafeType<Int> get() = Int32Field.type
|
||||
|
||||
/**
|
||||
* Guaranteed non-blocking access to content
|
||||
*/
|
||||
|
@ -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<T>(override val type: SafeType<T>, internal val array: Array<T>) : MutableBuffer<T> {
|
||||
@JvmInline
|
||||
public value class ArrayBuffer<T>(internal val array: Array<T>) : MutableBuffer<T> {
|
||||
// Can't inline because array is invariant
|
||||
override val size: Int get() = array.size
|
||||
|
||||
@ -25,7 +25,6 @@ public class ArrayBuffer<T>(override val type: SafeType<T>, internal val array:
|
||||
}
|
||||
|
||||
override operator fun iterator(): Iterator<T> = array.iterator()
|
||||
override fun copy(): MutableBuffer<T> = ArrayBuffer(type, array.copyOf())
|
||||
|
||||
override fun toString(): String = Buffer.toString(this)
|
||||
}
|
||||
@ -33,9 +32,4 @@ public class ArrayBuffer<T>(override val type: SafeType<T>, internal val array:
|
||||
/**
|
||||
* Returns an [ArrayBuffer] that wraps the original array.
|
||||
*/
|
||||
public fun <T> Array<T>.asBuffer(type: SafeType<T>): ArrayBuffer<T> = ArrayBuffer(type, this)
|
||||
|
||||
/**
|
||||
* Returns an [ArrayBuffer] that wraps the original array.
|
||||
*/
|
||||
public inline fun <reified T> Array<T>.asBuffer(): ArrayBuffer<T> = ArrayBuffer(safeTypeOf<T>(), this)
|
||||
public fun <T> Array<T>.asBuffer(): ArrayBuffer<T> = ArrayBuffer( this)
|
||||
|
@ -66,7 +66,7 @@ public inline fun <reified T> MutableBufferFactory(): MutableBufferFactory<T> =
|
||||
*
|
||||
* @param T the type of elements contained in the buffer.
|
||||
*/
|
||||
public interface Buffer<out T> : WithSize, WithType<T> {
|
||||
public interface Buffer<out T> : WithSize {
|
||||
/**
|
||||
* The size of this buffer.
|
||||
*/
|
||||
@ -120,7 +120,7 @@ public fun <T> Buffer(
|
||||
typeOf<Int>() -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer<T>
|
||||
typeOf<Long>() -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer<T>
|
||||
typeOf<Float>() -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer<T>
|
||||
else -> List(size, initializer).asBuffer(type)
|
||||
else -> List(size, initializer).asBuffer()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,7 +139,7 @@ public inline fun <reified T> Buffer(size: Int, initializer: (Int) -> T): Buffer
|
||||
typeOf<Int>() -> MutableBuffer.int(size) { initializer(it) as Int } as Buffer<T>
|
||||
typeOf<Long>() -> MutableBuffer.long(size) { initializer(it) as Long } as Buffer<T>
|
||||
typeOf<Float>() -> MutableBuffer.float(size) { initializer(it) as Float } as Buffer<T>
|
||||
else -> List(size, initializer).asBuffer(type)
|
||||
else -> List(size, initializer).asBuffer()
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,7 +172,6 @@ public fun <T> Buffer<T>.last(): T {
|
||||
* @param T the type of elements provided by the buffer.
|
||||
*/
|
||||
public class VirtualBuffer<out T>(
|
||||
override val type: SafeType<T>,
|
||||
override val size: Int,
|
||||
private val generator: (Int) -> T,
|
||||
) : Buffer<T> {
|
||||
@ -185,11 +184,3 @@ public class VirtualBuffer<out T>(
|
||||
|
||||
override fun toString(): String = Buffer.toString(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Inline builder for [VirtualBuffer]
|
||||
*/
|
||||
public inline fun <reified T> VirtualBuffer(
|
||||
size: Int,
|
||||
noinline generator: (Int) -> T,
|
||||
): VirtualBuffer<T> = VirtualBuffer(safeTypeOf(), size, generator)
|
||||
|
@ -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<T>(
|
||||
// ) { (i, j) -> get(i, j) }.as2D()
|
||||
|
||||
inner class Row(val buffer: MutableBuffer<T>, val rowIndex: Int) : MutableBuffer<T> {
|
||||
override val type: SafeType<T> get() = buffer.type
|
||||
|
||||
override val size: Int get() = colNum
|
||||
|
||||
@ -43,7 +41,6 @@ internal class BufferAccessor2D<T>(
|
||||
buffer[rowIndex, index] = value
|
||||
}
|
||||
|
||||
override fun copy(): MutableBuffer<T> = factory(colNum) { get(it) }
|
||||
override operator fun iterator(): Iterator<T> = (0 until colNum).map(::get).iterator()
|
||||
|
||||
override fun toString(): String = Buffer.toString(this)
|
||||
|
@ -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<T> : Buffer<T> {
|
||||
public val origin: Buffer<T>
|
||||
|
||||
override val type: SafeType<T> 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<T>(
|
||||
origin[permutations[index]] = value
|
||||
}
|
||||
|
||||
override fun copy(): MutableBuffer<T> = PermutedMutableBuffer(origin.copy(), permutations)
|
||||
//TODO Probably could be optimized
|
||||
|
||||
override fun iterator(): Iterator<T> = permutations.asSequence().map { origin[it] }.iterator()
|
||||
|
||||
@UnstableKMathAPI
|
||||
|
@ -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<Double?>, Buffer<Double?> {
|
||||
|
||||
override val type: SafeType<Double?> = safeTypeOf()
|
||||
|
||||
init {
|
||||
require(values.size == flags.size) { "Values and flags must have the same dimensions" }
|
||||
}
|
||||
|
@ -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<Float> {
|
||||
|
||||
override val type: SafeType<Float32> get() = safeTypeOf<Float32>()
|
||||
|
||||
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<Float> =
|
||||
Float32Buffer(array.copyOf())
|
||||
}
|
||||
|
||||
public typealias FloatBuffer = Float32Buffer
|
||||
|
@ -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<Double> {
|
||||
|
||||
override val type: SafeType<Double> 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 {
|
||||
|
@ -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<Short> {
|
||||
|
||||
override val type: SafeType<Short> 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<Sho
|
||||
}
|
||||
|
||||
override operator fun iterator(): ShortIterator = array.iterator()
|
||||
override fun copy(): MutableBuffer<Short> = Int16Buffer(array.copyOf())
|
||||
}
|
||||
|
||||
public typealias ShortBuffer = Int16Buffer
|
||||
|
@ -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<Int> {
|
||||
|
||||
override val type: SafeType<Int> get() = safeTypeOf()
|
||||
|
||||
override val size: Int get() = array.size
|
||||
|
||||
@ -29,7 +26,6 @@ public value class Int32Buffer(public val array: IntArray) : PrimitiveBuffer<Int
|
||||
|
||||
override operator fun iterator(): IntIterator = array.iterator()
|
||||
|
||||
override fun copy(): Int32Buffer = Int32Buffer(array.copyOf())
|
||||
}
|
||||
|
||||
public typealias IntBuffer = Int32Buffer
|
||||
|
@ -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 Int64Buffer(public val array: LongArray) : PrimitiveBuffer<Long> {
|
||||
|
||||
override val type: SafeType<Long> 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<Lo
|
||||
|
||||
override operator fun iterator(): LongIterator = array.iterator()
|
||||
|
||||
override fun copy(): MutableBuffer<Long> =
|
||||
Int64Buffer(array.copyOf())
|
||||
}
|
||||
|
||||
public typealias LongBuffer = Int64Buffer
|
||||
|
@ -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<Byte> {
|
||||
|
||||
override val type: SafeType<Byte> 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<Byte>
|
||||
}
|
||||
|
||||
override operator fun iterator(): ByteIterator = array.iterator()
|
||||
override fun copy(): MutableBuffer<Byte> = Int8Buffer(array.copyOf())
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<T>(override val type: SafeType<T>, public val list: List<T>) : Buffer<T> {
|
||||
public class ListBuffer<T>(public val list: List<T>) : Buffer<T> {
|
||||
|
||||
override val size: Int get() = list.size
|
||||
|
||||
@ -28,12 +25,7 @@ public class ListBuffer<T>(override val type: SafeType<T>, public val list: List
|
||||
/**
|
||||
* Returns an [ListBuffer] that wraps the original list.
|
||||
*/
|
||||
public fun <T> List<T>.asBuffer(type: SafeType<T>): ListBuffer<T> = ListBuffer(type, this)
|
||||
|
||||
/**
|
||||
* Returns an [ListBuffer] that wraps the original list.
|
||||
*/
|
||||
public inline fun <reified T> List<T>.asBuffer(): ListBuffer<T> = asBuffer(safeTypeOf())
|
||||
public fun <T> List<T>.asBuffer(): ListBuffer<T> = ListBuffer(this)
|
||||
|
||||
/**
|
||||
* [MutableBuffer] implementation over [MutableList].
|
||||
@ -41,7 +33,7 @@ public inline fun <reified T> List<T>.asBuffer(): ListBuffer<T> = asBuffer(safeT
|
||||
* @param T the type of elements contained in the buffer.
|
||||
* @property list The underlying list.
|
||||
*/
|
||||
public class MutableListBuffer<T>(override val type: SafeType<T>, public val list: MutableList<T>) : MutableBuffer<T> {
|
||||
public class MutableListBuffer<T>(public val list: MutableList<T>) : MutableBuffer<T> {
|
||||
|
||||
override val size: Int get() = list.size
|
||||
|
||||
@ -52,7 +44,6 @@ public class MutableListBuffer<T>(override val type: SafeType<T>, public val lis
|
||||
}
|
||||
|
||||
override operator fun iterator(): Iterator<T> = list.iterator()
|
||||
override fun copy(): MutableBuffer<T> = MutableListBuffer(type, ArrayList(list))
|
||||
|
||||
override fun toString(): String = Buffer.toString(this)
|
||||
}
|
||||
@ -61,15 +52,4 @@ public class MutableListBuffer<T>(override val type: SafeType<T>, public val lis
|
||||
/**
|
||||
* Returns an [MutableListBuffer] that wraps the original list.
|
||||
*/
|
||||
public fun <T> MutableList<T>.asMutableBuffer(type: SafeType<T>): MutableListBuffer<T> = MutableListBuffer(
|
||||
type,
|
||||
this
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns an [MutableListBuffer] that wraps the original list.
|
||||
*/
|
||||
public inline fun <reified T> MutableList<T>.asMutableBuffer(): MutableListBuffer<T> = MutableListBuffer(
|
||||
safeTypeOf(),
|
||||
this
|
||||
)
|
||||
public fun <T> MutableList<T>.asMutableBuffer(): MutableListBuffer<T> = MutableListBuffer(this)
|
@ -14,16 +14,13 @@ import kotlin.reflect.typeOf
|
||||
*
|
||||
* @param T the type of elements contained in the buffer.
|
||||
*/
|
||||
public interface MutableBuffer<T> : Buffer<T> {
|
||||
public interface MutableBuffer<T> : Buffer<T>{
|
||||
|
||||
/**
|
||||
* 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<T>
|
||||
|
||||
public companion object {
|
||||
/**
|
||||
@ -65,6 +62,25 @@ public interface MutableBuffer<T> : Buffer<T> {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a shallow copy of the buffer.
|
||||
*/
|
||||
public fun <T> Buffer<T>.copy(bufferFactory: BufferFactory<T>): Buffer<T> =if(this is ArrayBuffer){
|
||||
ArrayBuffer(array.copyOf())
|
||||
}else{
|
||||
bufferFactory(size,::get)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a mutable shallow copy of the buffer.
|
||||
*/
|
||||
public fun <T> Buffer<T>.mutableCopy(bufferFactory: MutableBufferFactory<T>): MutableBuffer<T> =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 <T> MutableBuffer(
|
||||
typeOf<Float>() -> MutableBuffer.float(size) { initializer(it) as Float } as MutableBuffer<T>
|
||||
typeOf<Double>() -> MutableBuffer.double(size) { initializer(it) as Double } as MutableBuffer<T>
|
||||
//TODO add unsigned types
|
||||
else -> MutableListBuffer(type, MutableList(size, initializer))
|
||||
else -> MutableListBuffer(MutableList(size, initializer))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,7 @@ class MatrixTest {
|
||||
|
||||
@Test
|
||||
fun testMatrixExtension() = Double.algebra.linearSpace.run {
|
||||
val transitionMatrix: Matrix<Double> = VirtualMatrix(type,6, 6) { row, col ->
|
||||
val transitionMatrix: Matrix<Double> = VirtualMatrix(6, 6) { row, col ->
|
||||
when {
|
||||
col == 0 -> .50
|
||||
row + 1 == col -> .50
|
||||
|
@ -33,7 +33,7 @@ public fun <T> MutableBuffer.Companion.parallel(
|
||||
typeOf<Double>() -> IntStream.range(0, size).parallel().mapToDouble { initializer(it) as Float64 }.toArray()
|
||||
.asBuffer() as MutableBuffer<T>
|
||||
//TODO add unsigned types
|
||||
else -> IntStream.range(0, size).parallel().mapToObj { initializer(it) }.collect(Collectors.toList<T>()).asMutableBuffer(type)
|
||||
else -> IntStream.range(0, size).parallel().mapToObj { initializer(it) }.collect(Collectors.toList<T>()).asMutableBuffer()
|
||||
}
|
||||
|
||||
public class ParallelBufferFactory<T>(override val type: SafeType<T>) : MutableBufferFactory<T> {
|
||||
|
@ -37,7 +37,7 @@ class ParallelMatrixTest {
|
||||
|
||||
@Test
|
||||
fun testMatrixExtension() = Float64Field.linearSpace.parallel{
|
||||
val transitionMatrix: Matrix<Double> = VirtualMatrix(type,6, 6) { row, col ->
|
||||
val transitionMatrix: Matrix<Double> = VirtualMatrix(6, 6) { row, col ->
|
||||
when {
|
||||
col == 0 -> .50
|
||||
row + 1 == col -> .50
|
||||
|
@ -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<T>(
|
||||
private val buffer: MutableBuffer<T>,
|
||||
private val bufferFactory: BufferFactory<T>,
|
||||
private var startIndex: Int = 0,
|
||||
size: Int = 0,
|
||||
) : Buffer<T> {
|
||||
|
||||
override val type: SafeType<T> get() = buffer.type
|
||||
|
||||
private val mutex: Mutex = Mutex()
|
||||
|
||||
@ -43,7 +40,7 @@ public class RingBuffer<T>(
|
||||
override operator fun iterator(): Iterator<T> = object : AbstractIterator<T>() {
|
||||
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<T>(
|
||||
* A safe snapshot operation
|
||||
*/
|
||||
public suspend fun snapshot(): Buffer<T> = 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<T>(
|
||||
|
||||
public inline fun <reified T : Any> RingBuffer(size: Int, empty: T): RingBuffer<T> {
|
||||
val buffer = MutableBuffer(size) { empty }
|
||||
return RingBuffer(buffer)
|
||||
return RingBuffer(buffer, BufferFactory())
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,5 +81,5 @@ public inline fun <reified T : Any> RingBuffer(size: Int, empty: T): RingBuffer<
|
||||
*/
|
||||
public fun <T> RingBuffer(size: Int, algebra: Group<T>): RingBuffer<T> {
|
||||
val buffer: MutableBuffer<T> = MutableBuffer(algebra.type, size) { algebra.zero }
|
||||
return RingBuffer(buffer)
|
||||
return RingBuffer(buffer, algebra.bufferFactory)
|
||||
}
|
||||
|
@ -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<out T>(
|
||||
public val scope: CoroutineScope,
|
||||
override val type: SafeType<T>,
|
||||
override val shape: ShapeND,
|
||||
public val function: suspend (IntArray) -> T,
|
||||
) : StructureND<T> {
|
||||
@ -54,10 +51,10 @@ public suspend fun <T> StructureND<T>.await(index: IntArray): T =
|
||||
public inline fun <T, reified R> StructureND<T>.mapAsyncIndexed(
|
||||
scope: CoroutineScope,
|
||||
crossinline function: suspend (T, index: IntArray) -> R,
|
||||
): LazyStructureND<R> = LazyStructureND(scope, safeTypeOf(), shape) { index -> function(get(index), index) }
|
||||
): LazyStructureND<R> = LazyStructureND(scope, shape) { index -> function(get(index), index) }
|
||||
|
||||
@OptIn(PerformancePitfall::class)
|
||||
public inline fun <T, reified R> StructureND<T>.mapAsync(
|
||||
scope: CoroutineScope,
|
||||
crossinline function: suspend (T) -> R,
|
||||
): LazyStructureND<R> = LazyStructureND(scope, safeTypeOf(), shape) { index -> function(get(index)) }
|
||||
): LazyStructureND<R> = LazyStructureND(scope, shape) { index -> function(get(index)) }
|
||||
|
@ -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<out T, R : Dimension, C : Dimension>(
|
||||
private val structure: Structure2D<T>,
|
||||
) : DMatrix<T, R, C> {
|
||||
|
||||
override val type: SafeType<T> 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<out T, D : Dimension> : Point<T> {
|
||||
@JvmInline
|
||||
public value class DPointWrapper<out T, D : Dimension>(public val point: Point<T>) : DPoint<T, D> {
|
||||
|
||||
override val type: SafeType<T> get() = point.type
|
||||
|
||||
override val size: Int get() = point.size
|
||||
|
||||
override operator fun get(index: Int): T = point[index]
|
||||
|
@ -38,7 +38,6 @@ public class EjmlDoubleVector<out M : DMatrix>(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<Double> get() = safeTypeOf()
|
||||
|
||||
override operator fun get(index: Int): Double = origin[0, index]
|
||||
}
|
||||
@ -51,8 +50,6 @@ public class EjmlFloatVector<out M : FMatrix>(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<Float> get() = safeTypeOf()
|
||||
|
||||
override operator fun get(index: Int): Float = origin[0, index]
|
||||
}
|
||||
|
||||
@ -60,8 +57,6 @@ public class EjmlFloatVector<out M : FMatrix>(override val origin: M) : EjmlVect
|
||||
* [EjmlMatrix] specialization for [Double].
|
||||
*/
|
||||
public class EjmlDoubleMatrix<out M : DMatrix>(override val origin: M) : EjmlMatrix<Double, M>(origin) {
|
||||
override val type: SafeType<Double> get() = safeTypeOf()
|
||||
|
||||
override operator fun get(i: Int, j: Int): Double = origin[i, j]
|
||||
}
|
||||
|
||||
@ -69,7 +64,6 @@ public class EjmlDoubleMatrix<out M : DMatrix>(override val origin: M) : EjmlMat
|
||||
* [EjmlMatrix] specialization for [Float].
|
||||
*/
|
||||
public class EjmlFloatMatrix<out M : FMatrix>(override val origin: M) : EjmlMatrix<Float, M>(origin) {
|
||||
override val type: SafeType<Float> get() = safeTypeOf()
|
||||
|
||||
override operator fun get(i: Int, j: Int): Float = origin[i, j]
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public fun Sequence<DoubleArray>.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)
|
||||
}
|
||||
|
||||
|
@ -54,14 +54,14 @@ public fun <T : Comparable<T>> PolynomialInterpolator<T>.interpolatePolynomials(
|
||||
public fun <T : Comparable<T>> PolynomialInterpolator<T>.interpolatePolynomials(
|
||||
data: Map<T, T>,
|
||||
): PiecewisePolynomial<T> {
|
||||
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 <T : Comparable<T>> PolynomialInterpolator<T>.interpolatePolynomials(
|
||||
data: List<Pair<T, T>>,
|
||||
): PiecewisePolynomial<T> {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ kscience{
|
||||
jvm()
|
||||
js()
|
||||
native()
|
||||
wasm()
|
||||
|
||||
useContextReceivers()
|
||||
useSerialization()
|
||||
|
@ -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 <T> Buffer<T>.asVector3D(): Vector3D<T> = object : Vector3D<T> {
|
||||
require(this@asVector3D.size == 3) { "Buffer of size 3 is required for Vector3D" }
|
||||
}
|
||||
|
||||
override val type: SafeType<T> = 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]
|
||||
|
@ -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<Float32>{
|
||||
override val type: SafeType<Float32> get() = Float32Field.type
|
||||
}
|
||||
|
||||
public typealias Float32Vector2D = Vector2D<Float32>
|
||||
|
||||
|
||||
public object Float32Space2D : GeometrySpace<Vector2D<Float32>, Float32> {
|
||||
|
@ -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<Float64> {
|
||||
override val type: SafeType<Float64> get() = Float64Field.type
|
||||
}
|
||||
public typealias Float64Vector2D = Vector2D<Float64>
|
||||
|
||||
@Deprecated("Use Float64Vector2D", ReplaceWith("Float64Vector2D"))
|
||||
public typealias DoubleVector2D = Float64Vector2D
|
||||
|
@ -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<Float>{
|
||||
override val type: SafeType<Float32> get() = Float32Field.type
|
||||
}
|
||||
|
||||
public typealias Float32Vector3D = Vector3D<Float>
|
||||
|
||||
|
||||
public object Float32Space3D : GeometrySpace<Vector3D<Float32>, Float32> {
|
||||
|
@ -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<Float64> {
|
||||
override val type: SafeType<Float64> get() = Float64Field.type
|
||||
}
|
||||
public typealias Float64Vector3D = Vector3D<Float64>
|
||||
|
||||
@Deprecated("Use Float64Vector3D", ReplaceWith("Float64Vector3D"))
|
||||
public typealias DoubleVector3D = Float64Vector3D
|
||||
|
@ -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<Angle> {
|
||||
override val type: SafeType<Angle> get() = Angle.type
|
||||
|
||||
public companion object
|
||||
}
|
||||
|
||||
|
@ -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 <init> (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
|
||||
}
|
||||
|
||||
|
@ -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<T : Any>(protected val memory: Memory, protected val spec: MemorySpec<T>) : Buffer<T> {
|
||||
|
||||
override val type: SafeType<T> 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<T : Any>(
|
||||
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<T> = MutableMemoryBuffer(memory.copy(), spec)
|
||||
|
||||
public companion object {
|
||||
public fun <T : Any> create(spec: MemorySpec<T>, size: Int): MutableMemoryBuffer<T> =
|
||||
|
@ -30,8 +30,6 @@ public val DataType.type: SafeType<*>
|
||||
|
||||
@JvmInline
|
||||
public value class MultikTensor<T>(public val array: MutableMultiArray<T, DN>) : Tensor<T> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override val type: SafeType<T> get() = array.dtype.type as SafeType<T>
|
||||
|
||||
override val shape: ShapeND get() = ShapeND(array.shape)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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<Double> = Nd4jArrayD
|
||||
|
||||
public data class Nd4jArrayFloatStructure(override val ndArray: INDArray) : Nd4jArrayStructure<Float>() {
|
||||
|
||||
override val type: SafeType<Float> get() = Float32Field.type
|
||||
|
||||
override fun elementsIterator(): Iterator<Pair<IntArray, Float>> = ndArray.floatIterator()
|
||||
|
||||
@PerformancePitfall
|
||||
|
@ -64,7 +64,6 @@ public object ValueAndErrorField : Field<ValueAndError> {
|
||||
require(values.size == ds.size)
|
||||
}
|
||||
|
||||
override val type: SafeType<ValueAndError> get() = safeTypeOf()
|
||||
override val size: Int
|
||||
get() = values.size
|
||||
|
||||
@ -77,7 +76,6 @@ public object ValueAndErrorField : Field<ValueAndError> {
|
||||
values[index] = value.dispersion
|
||||
}
|
||||
|
||||
override fun copy(): MutableBuffer<ValueAndError> = ValueAndErrorBuffer(values.copy(), ds.copy())
|
||||
}
|
||||
|
||||
override val bufferFactory: MutableBufferFactory<ValueAndError> = object : MutableBufferFactory<ValueAndError> {
|
||||
|
@ -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<TFloat64>,
|
||||
) : TensorFlowOutput<Double, TFloat64>(graph, output) {
|
||||
override val type: SafeType<Double> get() = Float64Field.type
|
||||
|
||||
override fun org.tensorflow.Tensor.actualizeTensor(): NdArray<Double> = this as TFloat64
|
||||
}
|
||||
|
@ -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<TInt32>,
|
||||
) : TensorFlowOutput<Int, TInt32>(graph, output) {
|
||||
|
||||
override val type: SafeType<Int32> get() = Int32Ring.type
|
||||
|
||||
override fun org.tensorflow.Tensor.actualizeTensor(): NdArray<Int> = this as TInt32
|
||||
}
|
||||
|
||||
@ -31,6 +24,5 @@ public class LongTensorFlowOutput(
|
||||
output: Output<TInt64>,
|
||||
) : TensorFlowOutput<Long, TInt64>(graph, output) {
|
||||
|
||||
override val type: SafeType<Int64> get() = Int64Ring.type
|
||||
override fun org.tensorflow.Tensor.actualizeTensor(): NdArray<Long> = this as TInt64
|
||||
}
|
@ -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<T> : Tensor<T>
|
||||
/**
|
||||
* Static (eager) in-memory TensorFlow tensor
|
||||
*/
|
||||
public class TensorFlowArray<T>(override val type: SafeType<T>, public val tensor: NdArray<T>) : Tensor<T> {
|
||||
@JvmInline
|
||||
public value class TensorFlowArray<T>(public val tensor: NdArray<T>) : Tensor<T> {
|
||||
|
||||
override val shape: ShapeND get() = ShapeND(tensor.shape().asArray().toIntArray())
|
||||
|
||||
@ -74,7 +74,7 @@ public abstract class TensorFlowOutput<T, TT : TType>(
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Double> = iterator {
|
||||
for (i in indices) {
|
||||
@ -90,8 +88,6 @@ public open class DoubleTensor(
|
||||
final override val source: OffsetDoubleBuffer,
|
||||
) : BufferedTensor<Double>(shape), MutableStructureNDOfDouble {
|
||||
|
||||
override val type: SafeType<Double> get() = DoubleField.type
|
||||
|
||||
init {
|
||||
require(linearSize == source.size) { "Source buffer size must be equal tensor size" }
|
||||
}
|
||||
|
@ -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<Double> = source.copy()
|
||||
|
||||
@PerformancePitfall
|
||||
override fun elements(): Sequence<Pair<IntArray, Double>> = super<MutableStructure1D>.elements()
|
||||
}
|
||||
|
@ -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<Int> 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<Int> = 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<Int> get() = IntRing.type
|
||||
|
||||
public constructor(shape: ShapeND, buffer: Int32Buffer) : this(shape, OffsetIntBuffer(buffer, 0, buffer.size))
|
||||
|
||||
|
@ -17,7 +17,7 @@ import space.kscience.kmath.tensors.api.Tensor
|
||||
public fun StructureND<Double>.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,
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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<Double> {
|
||||
override val type: SafeType<Double> 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<Double> = ViktorBuffer(flatArray.copy().flatten())
|
||||
override operator fun iterator(): Iterator<Double> = flatArray.data.iterator()
|
||||
|
||||
override fun toString(): String = Buffer.toString(this)
|
||||
|
@ -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<Double> {
|
||||
override val type: SafeType<Double> get() = Float64Field.type
|
||||
|
||||
override val shape: ShapeND get() = ShapeND(f64Buffer.shape)
|
||||
|
||||
@OptIn(PerformancePitfall::class)
|
||||
|
Loading…
Reference in New Issue
Block a user