pre-0.0.3 #46

Merged
altavir merged 75 commits from dev into master 2019-02-20 13:05:39 +03:00
5 changed files with 24 additions and 8 deletions
Showing only changes of commit bb64012992 - Show all commits

3
doc/contexts.md Normal file
View File

@ -0,0 +1,3 @@
# Context-oriented programming
One of problems

View File

@ -198,7 +198,6 @@ class RealLUDecomposition(matrix: RealMatrix, private val singularityThreshold:
/** Specialized solver. */ /** Specialized solver. */
object RealLUSolver : LinearSolver<Double, DoubleField> { object RealLUSolver : LinearSolver<Double, DoubleField> {
fun decompose(mat: Matrix<Double, DoubleField>, threshold: Double = 1e-11): RealLUDecomposition = RealLUDecomposition(mat, threshold) fun decompose(mat: Matrix<Double, DoubleField>, threshold: Double = 1e-11): RealLUDecomposition = RealLUDecomposition(mat, threshold)
override fun solve(a: RealMatrix, b: RealMatrix): RealMatrix { override fun solve(a: RealMatrix, b: RealMatrix): RealMatrix {

View File

@ -6,12 +6,14 @@ package scientifik.kmath.operations
object ComplexField : Field<Complex> { object ComplexField : Field<Complex> {
override val zero: Complex = Complex(0.0, 0.0) override val zero: Complex = Complex(0.0, 0.0)
override val one: Complex = Complex(1.0, 0.0)
val i = Complex(0.0, 1.0)
override fun add(a: Complex, b: Complex): Complex = Complex(a.re + b.re, a.im + b.im) override fun add(a: Complex, b: Complex): Complex = Complex(a.re + b.re, a.im + b.im)
override fun multiply(a: Complex, k: Double): Complex = Complex(a.re * k, a.im * k) override fun multiply(a: Complex, k: Double): Complex = Complex(a.re * k, a.im * k)
override val one: Complex = Complex(1.0, 0.0)
override fun multiply(a: Complex, b: Complex): Complex = Complex(a.re * b.re - a.im * b.im, a.re * b.im + a.im * b.re) override fun multiply(a: Complex, b: Complex): Complex = Complex(a.re * b.re - a.im * b.im, a.re * b.im + a.im * b.re)
override fun divide(a: Complex, b: Complex): Complex = Complex(a.re * b.re + a.im * b.im, a.re * b.im - a.im * b.re) / b.square override fun divide(a: Complex, b: Complex): Complex = Complex(a.re * b.re + a.im * b.im, a.re * b.im - a.im * b.re) / b.square
@ -41,5 +43,16 @@ data class Complex(val re: Double, val im: Double) : FieldElement<Complex, Compl
companion object { companion object {
} }
} }
fun Double.toComplex() = Complex(this, 0.0)
operator fun Double.plus(c: Complex) = this.toComplex() + c
operator fun Double.minus(c: Complex) = this.toComplex() - c
operator fun Complex.plus(d: Double) = d + this
operator fun Complex.minus(d: Double) = this - d.toComplex()
operator fun Double.times(c: Complex) = Complex(c.re * this, c.im * this)

View File

@ -68,8 +68,7 @@ class ArrayBuffer<T>(private val array: Array<T>) : MutableBuffer<T> {
} }
inline class DoubleBuffer(private val array: DoubleArray) : MutableBuffer<Double> { inline class DoubleBuffer(private val array: DoubleArray) : MutableBuffer<Double> {
override val size: Int override val size: Int get() = array.size
get() = array.size
override fun get(index: Int): Double = array[index] override fun get(index: Int): Double = array[index]
@ -83,8 +82,7 @@ inline class DoubleBuffer(private val array: DoubleArray) : MutableBuffer<Double
} }
inline class IntBuffer(private val array: IntArray) : MutableBuffer<Int> { inline class IntBuffer(private val array: IntArray) : MutableBuffer<Int> {
override val size: Int override val size: Int get() = array.size
get() = array.size
override fun get(index: Int): Int = array[index] override fun get(index: Int): Int = array[index]

View File

@ -49,6 +49,9 @@ interface Strides {
*/ */
fun index(offset: Int): IntArray fun index(offset: Int): IntArray
/**
* The size of linear buffer to accommodate all elements of ND-structure corresponding to strides
*/
val linearSize: Int val linearSize: Int
/** /**