Added features to Matrix

This commit is contained in:
Alexander Nozik 2019-01-07 17:24:10 +03:00
parent c161ef0b57
commit 83e24acdc5

View File

@ -66,6 +66,11 @@ interface MatrixSpace<T : Any, R : Ring<T>> : Space<Matrix<T, R>> {
} }
} }
/**
* A marker interface representing some matrix feature like diagonal, sparce, zero, etc. Features used to optimize matrix
* operations performance in some cases.
*/
interface MatrixFeature
/** /**
* Specialized 2-d structure * Specialized 2-d structure
@ -91,6 +96,8 @@ interface Matrix<T : Any, R : Ring<T>> : NDStructure<T>, SpaceElement<Matrix<T,
context.point(numRows) { i -> get(i, j) } context.point(numRows) { i -> get(i, j) }
} }
val features: Set<MatrixFeature>
companion object { companion object {
fun real(rows: Int, columns: Int, initializer: (Int, Int) -> Double) = fun real(rows: Int, columns: Int, initializer: (Int, Int) -> Double) =
MatrixSpace.real(rows, columns).produce(rows, columns, initializer) MatrixSpace.real(rows, columns).produce(rows, columns, initializer)
@ -147,7 +154,8 @@ data class StructureMatrixSpace<T : Any, R : Ring<T>>(
data class StructureMatrix<T : Any, R : Ring<T>>( data class StructureMatrix<T : Any, R : Ring<T>>(
override val context: StructureMatrixSpace<T, R>, override val context: StructureMatrixSpace<T, R>,
val structure: NDStructure<T> val structure: NDStructure<T>,
override val features: Set<MatrixFeature> = emptySet()
) : Matrix<T, R> { ) : Matrix<T, R> {
init { init {
if (structure.shape.size != 2 || structure.shape[0] != context.rowNum || structure.shape[1] != context.colNum) { if (structure.shape.size != 2 || structure.shape[0] != context.rowNum || structure.shape[1] != context.colNum) {