forked from kscience/kmath
Merge branch 'dev' into gsl-experiment
This commit is contained in:
commit
df4ea2c1e4
@ -3,16 +3,26 @@ package kscience.kmath.real
|
|||||||
import kscience.kmath.linear.Point
|
import kscience.kmath.linear.Point
|
||||||
import kscience.kmath.operations.Norm
|
import kscience.kmath.operations.Norm
|
||||||
import kscience.kmath.structures.Buffer
|
import kscience.kmath.structures.Buffer
|
||||||
|
import kscience.kmath.structures.RealBuffer
|
||||||
|
import kscience.kmath.structures.asBuffer
|
||||||
import kscience.kmath.structures.asIterable
|
import kscience.kmath.structures.asIterable
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
import kotlin.math.sqrt
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
public typealias RealVector = Point<Double>
|
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> {
|
public object VectorL2Norm : Norm<Point<out Number>, Double> {
|
||||||
override fun norm(arg: Point<out Number>): Double = sqrt(arg.asIterable().sumByDouble(Number::toDouble))
|
override fun norm(arg: Point<out Number>): Double = sqrt(arg.asIterable().sumByDouble(Number::toDouble))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill the vector of given [size] with given [value]
|
* Fill the vector of given [size] with given [value]
|
||||||
*/
|
*/
|
||||||
|
@ -5,6 +5,7 @@ import kscience.kmath.linear.asMatrix
|
|||||||
import kscience.kmath.linear.transpose
|
import kscience.kmath.linear.transpose
|
||||||
import kscience.kmath.operations.invoke
|
import kscience.kmath.operations.invoke
|
||||||
import kscience.kmath.real.RealVector
|
import kscience.kmath.real.RealVector
|
||||||
|
import kscience.kmath.real.plus
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user