Add different ways to provide data for XY interpolator
This commit is contained in:
parent
73f40105c4
commit
068b90e7ab
@ -3,6 +3,8 @@ package scientifik.kmath.interpolation
|
|||||||
import scientifik.kmath.functions.PiecewisePolynomial
|
import scientifik.kmath.functions.PiecewisePolynomial
|
||||||
import scientifik.kmath.functions.value
|
import scientifik.kmath.functions.value
|
||||||
import scientifik.kmath.operations.Ring
|
import scientifik.kmath.operations.Ring
|
||||||
|
import scientifik.kmath.structures.Buffer
|
||||||
|
import scientifik.kmath.structures.asBuffer
|
||||||
|
|
||||||
interface Interpolator<X, Y> {
|
interface Interpolator<X, Y> {
|
||||||
fun interpolate(points: XYPointSet<X, Y>): (X) -> Y
|
fun interpolate(points: XYPointSet<X, Y>): (X) -> Y
|
||||||
@ -19,3 +21,25 @@ interface PolynomialInterpolator<T : Comparable<T>> : Interpolator<T, T> {
|
|||||||
interpolatePolynomials(points).value(algebra, x) ?: getDefaultValue()
|
interpolatePolynomials(points).value(algebra, x) ?: getDefaultValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T : Comparable<T>> PolynomialInterpolator<T>.interpolatePolynomials(
|
||||||
|
x: Buffer<T>,
|
||||||
|
y: Buffer<T>
|
||||||
|
): PiecewisePolynomial<T> {
|
||||||
|
val pointSet = BufferXYPointSet(x, y)
|
||||||
|
return interpolatePolynomials(pointSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : Comparable<T>> PolynomialInterpolator<T>.interpolatePolynomials(
|
||||||
|
data: Map<T, T>
|
||||||
|
): PiecewisePolynomial<T> {
|
||||||
|
val pointSet = BufferXYPointSet(data.keys.toList().asBuffer(), data.values.toList().asBuffer())
|
||||||
|
return interpolatePolynomials(pointSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : Comparable<T>> PolynomialInterpolator<T>.interpolatePolynomials(
|
||||||
|
data: List<Pair<T, T>>
|
||||||
|
): PiecewisePolynomial<T> {
|
||||||
|
val pointSet = BufferXYPointSet(data.map { it.first }.asBuffer(), data.map { it.second }.asBuffer())
|
||||||
|
return interpolatePolynomials(pointSet)
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
//package scientifik.kmath.interpolation
|
package scientifik.kmath.interpolation
|
||||||
//
|
//
|
||||||
//import scientifik.kmath.functions.PiecewisePolynomial
|
//import scientifik.kmath.functions.PiecewisePolynomial
|
||||||
//import scientifik.kmath.operations.Ring
|
//import scientifik.kmath.operations.Ring
|
||||||
|
Loading…
Reference in New Issue
Block a user