forked from kscience/kmath
Merge pull request #148 from mipt-npm/gsl-experiment
Changes for upcoming GSL extension project
This commit is contained in:
commit
84adce13c9
@ -1,7 +1,6 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
java
|
||||
kotlin("jvm")
|
||||
kotlin("plugin.allopen")
|
||||
id("kotlinx.benchmark")
|
||||
|
@ -526,6 +526,7 @@ public final class kscience/kmath/linear/BufferMatrixContext : kscience/kmath/li
|
||||
public synthetic fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D;
|
||||
public fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer;
|
||||
public fun getElementContext ()Lkscience/kmath/operations/Ring;
|
||||
public fun getFeature (Lkscience/kmath/nd/Structure2D;Lkotlin/reflect/KClass;)Ljava/lang/Object;
|
||||
public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
|
||||
public fun minus (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/linear/BufferMatrix;
|
||||
public synthetic fun minus (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D;
|
||||
@ -630,6 +631,7 @@ public final class kscience/kmath/linear/GenericMatrixContext$DefaultImpls {
|
||||
public static fun div (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D;
|
||||
public static fun dot (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D;
|
||||
public static fun dot (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer;
|
||||
public static fun getFeature (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Lkotlin/reflect/KClass;)Ljava/lang/Object;
|
||||
public static fun minus (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D;
|
||||
public static fun multiply (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D;
|
||||
public static fun plus (Lkscience/kmath/linear/GenericMatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D;
|
||||
@ -713,6 +715,7 @@ public abstract interface class kscience/kmath/linear/MatrixContext : kscience/k
|
||||
public abstract fun binaryOperationFunction (Ljava/lang/String;)Lkotlin/jvm/functions/Function2;
|
||||
public abstract fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D;
|
||||
public abstract fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer;
|
||||
public abstract fun getFeature (Lkscience/kmath/nd/Structure2D;Lkotlin/reflect/KClass;)Ljava/lang/Object;
|
||||
public abstract fun point (ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/Buffer;
|
||||
public abstract fun produce (IILkotlin/jvm/functions/Function2;)Lkscience/kmath/nd/Structure2D;
|
||||
public abstract fun times (Ljava/lang/Object;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D;
|
||||
@ -728,6 +731,7 @@ public final class kscience/kmath/linear/MatrixContext$DefaultImpls {
|
||||
public static fun binaryOperation (Lkscience/kmath/linear/MatrixContext;Ljava/lang/String;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D;
|
||||
public static fun binaryOperationFunction (Lkscience/kmath/linear/MatrixContext;Ljava/lang/String;)Lkotlin/jvm/functions/Function2;
|
||||
public static fun div (Lkscience/kmath/linear/MatrixContext;Lkscience/kmath/nd/Structure2D;Ljava/lang/Number;)Lkscience/kmath/nd/Structure2D;
|
||||
public static fun getFeature (Lkscience/kmath/linear/MatrixContext;Lkscience/kmath/nd/Structure2D;Lkotlin/reflect/KClass;)Ljava/lang/Object;
|
||||
public static fun minus (Lkscience/kmath/linear/MatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D;
|
||||
public static fun plus (Lkscience/kmath/linear/MatrixContext;Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D;
|
||||
public static fun point (Lkscience/kmath/linear/MatrixContext;ILkotlin/jvm/functions/Function1;)Lkscience/kmath/structures/Buffer;
|
||||
@ -797,6 +801,7 @@ public final class kscience/kmath/linear/RealMatrixContext : kscience/kmath/line
|
||||
public fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/linear/BufferMatrix;
|
||||
public synthetic fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D;
|
||||
public fun dot (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/structures/Buffer;)Lkscience/kmath/structures/Buffer;
|
||||
public fun getFeature (Lkscience/kmath/nd/Structure2D;Lkotlin/reflect/KClass;)Ljava/lang/Object;
|
||||
public synthetic fun minus (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
|
||||
public fun minus (Lkscience/kmath/nd/Structure2D;Lkscience/kmath/nd/Structure2D;)Lkscience/kmath/nd/Structure2D;
|
||||
public synthetic fun multiply (Ljava/lang/Object;Ljava/lang/Number;)Ljava/lang/Object;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package kscience.kmath.linear
|
||||
|
||||
import kscience.kmath.misc.UnstableKMathAPI
|
||||
import kscience.kmath.operations.Ring
|
||||
import kscience.kmath.operations.SpaceOperations
|
||||
import kscience.kmath.operations.invoke
|
||||
@ -7,6 +8,7 @@ import kscience.kmath.operations.sum
|
||||
import kscience.kmath.structures.Buffer
|
||||
import kscience.kmath.structures.BufferFactory
|
||||
import kscience.kmath.structures.asSequence
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
* Basic operations on matrices. Operates on [Matrix].
|
||||
@ -16,12 +18,12 @@ import kscience.kmath.structures.asSequence
|
||||
*/
|
||||
public interface MatrixContext<T : Any, out M : Matrix<T>> : SpaceOperations<Matrix<T>> {
|
||||
/**
|
||||
* Produce a matrix with this context and given dimensions
|
||||
* Produces a matrix with this context and given dimensions.
|
||||
*/
|
||||
public fun produce(rows: Int, columns: Int, initializer: (i: Int, j: Int) -> T): M
|
||||
|
||||
/**
|
||||
* Produce a point compatible with matrix space (and possibly optimized for it)
|
||||
* Produces a point compatible with matrix space (and possibly optimized for it).
|
||||
*/
|
||||
public fun point(size: Int, initializer: (Int) -> T): Point<T> = Buffer.boxing(size, initializer)
|
||||
|
||||
@ -63,11 +65,23 @@ public interface MatrixContext<T : Any, out M : Matrix<T>> : SpaceOperations<Mat
|
||||
* Multiplies an element by a matrix of it.
|
||||
*
|
||||
* @receiver the multiplicand.
|
||||
* @param value the multiplier.
|
||||
* @param m the multiplier.
|
||||
* @receiver the product.
|
||||
*/
|
||||
public operator fun T.times(m: Matrix<T>): M = m * this
|
||||
|
||||
/**
|
||||
* Gets a feature from the matrix. This function may return some additional features to
|
||||
* [kscience.kmath.nd.NDStructure.getFeature].
|
||||
*
|
||||
* @param F the type of feature.
|
||||
* @param m the matrix.
|
||||
* @param type the [KClass] instance of [F].
|
||||
* @return a feature object or `null` if it isn't present.
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public fun <F : Any> getFeature(m: Matrix<T>, type: KClass<F>): F? = m.getFeature(type)
|
||||
|
||||
public companion object {
|
||||
|
||||
/**
|
||||
@ -86,6 +100,21 @@ public interface MatrixContext<T : Any, out M : Matrix<T>> : SpaceOperations<Mat
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a feature from the matrix. This function may return some additional features to
|
||||
* [kscience.kmath.nd.NDStructure.getFeature].
|
||||
*
|
||||
* @param T the type of items in the matrices.
|
||||
* @param M the type of operated matrices.
|
||||
* @param F the type of feature.
|
||||
* @receiver the [MatrixContext] of [T].
|
||||
* @param m the matrix.
|
||||
* @return a feature object or `null` if it isn't present.
|
||||
*/
|
||||
@UnstableKMathAPI
|
||||
public inline fun <T : Any, reified F : Any> MatrixContext<T, *>.getFeature(m: Matrix<T>): F? =
|
||||
getFeature(m, F::class)
|
||||
|
||||
/**
|
||||
* Partial implementation of [MatrixContext] for matrices of [Ring].
|
||||
*
|
||||
|
@ -237,11 +237,22 @@ public class ArrayBuffer<T>(private val array: Array<T>) : MutableBuffer<T> {
|
||||
override fun copy(): MutableBuffer<T> = ArrayBuffer(array.copyOf())
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an [ArrayBuffer] that wraps the original array.
|
||||
*/
|
||||
public fun <T> Array<T>.asBuffer(): ArrayBuffer<T> = ArrayBuffer(this)
|
||||
|
||||
/**
|
||||
* Creates a new [ArrayBuffer] with the specified [size], where each element is calculated by calling the specified
|
||||
* [init] function.
|
||||
*
|
||||
* The function [init] is called for each array element sequentially starting from the first one.
|
||||
* It should return the value for an array element given its index.
|
||||
*/
|
||||
public inline fun <reified T> ArrayBuffer(size: Int, init: (Int) -> T): ArrayBuffer<T> =
|
||||
Array(size) { i -> init(i) }.asBuffer()
|
||||
|
||||
/**
|
||||
* Immutable wrapper for [MutableBuffer].
|
||||
*
|
||||
|
@ -31,8 +31,8 @@ public object EjmlMatrixContext : MatrixContext<Double, EjmlMatrix> {
|
||||
|
||||
override fun produce(rows: Int, columns: Int, initializer: (i: Int, j: Int) -> Double): EjmlMatrix =
|
||||
EjmlMatrix(SimpleMatrix(rows, columns).also {
|
||||
(0 until it.numRows()).forEach { row ->
|
||||
(0 until it.numCols()).forEach { col -> it[row, col] = initializer(row, col) }
|
||||
(0 until rows).forEach { row ->
|
||||
(0 until columns).forEach { col -> it[row, col] = initializer(row, col) }
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -7,6 +7,7 @@ kotlin.sourceSets {
|
||||
languageSettings.apply {
|
||||
useExperimentalAnnotation("kotlinx.coroutines.FlowPreview")
|
||||
useExperimentalAnnotation("kotlinx.coroutines.ExperimentalCoroutinesApi")
|
||||
useExperimentalAnnotation("kotlinx.coroutines.ObsoleteCoroutinesApi")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user