0.1.4-dev-4 #86

Merged
altavir merged 38 commits from dev into master 2020-04-30 11:36:59 +03:00
2 changed files with 25 additions and 1 deletions
Showing only changes of commit 068b90e7ab - Show all commits

View File

@ -3,6 +3,8 @@ package scientifik.kmath.interpolation
import scientifik.kmath.functions.PiecewisePolynomial
import scientifik.kmath.functions.value
import scientifik.kmath.operations.Ring
import scientifik.kmath.structures.Buffer
import scientifik.kmath.structures.asBuffer
interface Interpolator<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()
}
}
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)
}

View File

@ -1,4 +1,4 @@
//package scientifik.kmath.interpolation
package scientifik.kmath.interpolation
//
//import scientifik.kmath.functions.PiecewisePolynomial
//import scientifik.kmath.operations.Ring