Remove asPolynomial

This commit is contained in:
Alexander Nozik 2023-10-25 10:28:39 +03:00
parent bfb556b013
commit 1765f8cf8c
8 changed files with 38 additions and 15 deletions

View File

@ -15,6 +15,7 @@
### Deprecated
### Removed
- `asPolynomial` function due to scope pollution
### Fixed
- Median statistics

View File

@ -69,4 +69,4 @@ ksciencePublish {
apiValidation.nonPublicMarkers.add("space.kscience.kmath.UnstableKMathAPI")
val multikVersion by extra("0.2.0")
val multikVersion by extra("0.2.2")

View File

@ -5,6 +5,10 @@
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
}
dependencyResolutionManagement {
val projectProperties = java.util.Properties()
file("../gradle.properties").inputStream().use {

View File

@ -12,6 +12,6 @@ org.gradle.jvmargs=-Xmx4096m
org.gradle.parallel=true
org.gradle.workers.max=4
toolsVersion=0.15.0-kotlin-1.9.20-Beta2
toolsVersion=0.15.0-kotlin-1.9.20-RC2
#kotlin.experimental.tryK2=true
#kscience.wasm.disabled=true

View File

@ -52,7 +52,7 @@ internal external fun createType(types: Array<Type>): Type
internal external fun expandType(type: Type): Array<Type>
internal external enum class ExpressionIds {
internal external enum class ExpressionIds {
Invalid,
Block,
If,

View File

@ -10,6 +10,7 @@ import space.kscience.kmath.UnstableKMathAPI
import space.kscience.kmath.expressions.Symbol
import space.kscience.kmath.nd.Structure2D
import space.kscience.kmath.structures.Buffer
import space.kscience.kmath.structures.VirtualBuffer
import kotlin.math.max
/**
@ -33,7 +34,10 @@ public interface XYColumnarData<out T, out X : T, out Y : T> : ColumnarData<T> {
else -> null
}
public companion object{
public companion object {
/**
* Create data form two buffers (zero-copy)
*/
@UnstableKMathAPI
public fun <T, X : T, Y : T> of(x: Buffer<X>, y: Buffer<Y>): XYColumnarData<T, X, Y> {
require(x.size == y.size) { "Buffer size mismatch. x buffer size is ${x.size}, y buffer size is ${y.size}" }
@ -43,6 +47,26 @@ public interface XYColumnarData<out T, out X : T, out Y : T> : ColumnarData<T> {
override val y: Buffer<Y> = y
}
}
/**
* Create two-column data from a list of row-objects (zero-copy)
*/
@UnstableKMathAPI
public fun <I, T, X : T, Y : T> ofList(
list: List<I>,
xConverter: (I) -> X,
yConverter: (I) -> Y,
): XYColumnarData<T, X, Y> = object : XYColumnarData<T, X, Y> {
override val size: Int get() = list.size
override val x: Buffer<X> = VirtualBuffer(list.size) {
xConverter(list[it])
}
override val y: Buffer<Y> = VirtualBuffer(list.size) {
yConverter(list[it])
}
}
}
}
@ -56,9 +80,10 @@ public fun <T> ColumnarData<T>.asXYData(
ySymbol: Symbol,
): XYColumnarData<T, T, T> = object : XYColumnarData<T, T, T> {
init {
requireNotNull(this@asXYData[xSymbol]){"The column with name $xSymbol is not present in $this"}
requireNotNull(this@asXYData[ySymbol]){"The column with name $ySymbol is not present in $this"}
requireNotNull(this@asXYData[xSymbol]) { "The column with name $xSymbol is not present in $this" }
requireNotNull(this@asXYData[ySymbol]) { "The column with name $ySymbol is not present in $this" }
}
override val size: Int get() = this@asXYData.size
override val x: Buffer<T> get() = this@asXYData[xSymbol]!!
override val y: Buffer<T> get() = this@asXYData[ySymbol]!!

View File

@ -65,9 +65,7 @@ public class RingBuffer<T>(
}
}
@Suppress("NOTHING_TO_INLINE")
private inline fun Int.forward(n: Int): Int = (this + n) % (buffer.size)
private fun Int.forward(n: Int): Int = (this + n) % (buffer.size)
override fun toString(): String = Buffer.toString(this)

View File

@ -21,8 +21,3 @@ public fun <C> Polynomial(coefficients: List<C>, reverse: Boolean = false): Poly
@Suppress("FunctionName")
public fun <C> Polynomial(vararg coefficients: C, reverse: Boolean = false): Polynomial<C> =
Polynomial(with(coefficients) { if (reverse) reversed() else toList() })
/**
* Represents [this] constant as a [Polynomial].
*/
public fun <C> C.asPolynomial() : Polynomial<C> = Polynomial(listOf(this))