Fix broken APIs in kmath-for-real

This commit is contained in:
Iaroslav Postovalov 2020-11-30 01:19:27 +07:00
parent 4433da9acf
commit 6fb3c03e87
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7
2 changed files with 11 additions and 0 deletions

View File

@ -3,16 +3,26 @@ package kscience.kmath.real
import kscience.kmath.linear.Point
import kscience.kmath.operations.Norm
import kscience.kmath.structures.Buffer
import kscience.kmath.structures.RealBuffer
import kscience.kmath.structures.asBuffer
import kscience.kmath.structures.asIterable
import kotlin.math.pow
import kotlin.math.sqrt
public typealias RealVector = Point<Double>
public inline fun RealVector(size: Int, init: (Int) -> Double): RealVector = RealBuffer(size, init)
public fun RealVector(vararg doubles: Double): RealVector = RealBuffer(doubles)
public fun DoubleArray.asVector(): RealVector = asBuffer()
public fun List<Double>.asVector(): RealVector = asBuffer()
public object VectorL2Norm : Norm<Point<out Number>, Double> {
override fun norm(arg: Point<out Number>): Double = sqrt(arg.asIterable().sumByDouble(Number::toDouble))
}
/**
* Fill the vector of given [size] with given [value]
*/

View File

@ -5,6 +5,7 @@ import kscience.kmath.linear.asMatrix
import kscience.kmath.linear.transpose
import kscience.kmath.operations.invoke
import kscience.kmath.real.RealVector
import kscience.kmath.real.plus
import kotlin.test.Test
import kotlin.test.assertEquals