forked from kscience/kmath
cleanup
This commit is contained in:
parent
0aa73cd48f
commit
8179be2f62
@ -9,7 +9,7 @@ import space.kscience.kmath.structures.VirtualBuffer
|
|||||||
import space.kscience.kmath.structures.indices
|
import space.kscience.kmath.structures.indices
|
||||||
|
|
||||||
|
|
||||||
public class LinearSpaceOverNd<T : Any, A : Ring<T>>(
|
public class BufferLinearSpace<T : Any, A : Ring<T>>(
|
||||||
override val elementAlgebra: A,
|
override val elementAlgebra: A,
|
||||||
private val bufferFactory: BufferFactory<T>,
|
private val bufferFactory: BufferFactory<T>,
|
||||||
) : LinearSpace<T, A> {
|
) : LinearSpace<T, A> {
|
||||||
@ -35,7 +35,7 @@ public class LinearSpaceOverNd<T : Any, A : Ring<T>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun Matrix<T>.minus(other: Matrix<T>): Matrix<T> = ndRing(rowNum, colNum).run {
|
override fun Matrix<T>.minus(other: Matrix<T>): Matrix<T> = ndRing(rowNum, colNum).run {
|
||||||
require(shape.contentEquals(other.shape)) { "Shape mismatch on Matrix::plus. Expected $shape but found ${other.shape}" }
|
require(shape.contentEquals(other.shape)) { "Shape mismatch on Matrix::minus. Expected $shape but found ${other.shape}" }
|
||||||
unwrap().minus(other.unwrap()).as2D()
|
unwrap().minus(other.unwrap()).as2D()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +50,6 @@ public class LinearSpaceOverNd<T : Any, A : Ring<T>>(
|
|||||||
return elementAlgebra {
|
return elementAlgebra {
|
||||||
val rows = this@dot.rows.map{it.linearize()}
|
val rows = this@dot.rows.map{it.linearize()}
|
||||||
val columns = other.columns.map { it.linearize() }
|
val columns = other.columns.map { it.linearize() }
|
||||||
//TODO optimize buffers
|
|
||||||
buildMatrix(rowNum, other.colNum) { i, j ->
|
buildMatrix(rowNum, other.colNum) { i, j ->
|
||||||
val r = rows[i]
|
val r = rows[i]
|
||||||
val c = columns[j]
|
val c = columns[j]
|
||||||
@ -67,7 +66,6 @@ public class LinearSpaceOverNd<T : Any, A : Ring<T>>(
|
|||||||
require(colNum == vector.size) { "Matrix dot vector operation dimension mismatch: ($rowNum, $colNum) x (${vector.size})" }
|
require(colNum == vector.size) { "Matrix dot vector operation dimension mismatch: ($rowNum, $colNum) x (${vector.size})" }
|
||||||
return elementAlgebra {
|
return elementAlgebra {
|
||||||
val rows = this@dot.rows
|
val rows = this@dot.rows
|
||||||
//TODO optimize buffers
|
|
||||||
buildVector(rowNum) { i ->
|
buildVector(rowNum) { i ->
|
||||||
val r = rows[i]
|
val r = rows[i]
|
||||||
var res = zero
|
var res = zero
|
@ -171,7 +171,7 @@ public interface LinearSpace<T : Any, out A : Ring<T>> {
|
|||||||
public fun <T : Any, A : Ring<T>> buffered(
|
public fun <T : Any, A : Ring<T>> buffered(
|
||||||
algebra: A,
|
algebra: A,
|
||||||
bufferFactory: BufferFactory<T> = Buffer.Companion::boxing,
|
bufferFactory: BufferFactory<T> = Buffer.Companion::boxing,
|
||||||
): LinearSpace<T, A> = LinearSpaceOverNd(algebra,bufferFactory)
|
): LinearSpace<T, A> = BufferLinearSpace(algebra,bufferFactory)
|
||||||
|
|
||||||
public val real: LinearSpace<Double, RealField> = buffered(RealField, Buffer.Companion::real)
|
public val real: LinearSpace<Double, RealField> = buffered(RealField, Buffer.Companion::real)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user