forked from kscience/kmath
removed unnecessary type-parameter in matrix
This commit is contained in:
parent
c3f0dbe161
commit
2503cb69d5
@ -85,7 +85,7 @@ class TransposedFeature<T : Any>(val original: Matrix<T>) : MatrixFeature
|
||||
/**
|
||||
* Create a virtual transposed matrix without copying anything. `A.transpose().transpose() === A`
|
||||
*/
|
||||
fun <T : Any, R : Ring<T>> Matrix<T>.transpose(): Matrix<T> {
|
||||
fun <T : Any> Matrix<T>.transpose(): Matrix<T> {
|
||||
return this.getFeature<TransposedFeature<T>>()?.original ?: VirtualMatrix(
|
||||
this.colNum,
|
||||
this.rowNum,
|
||||
|
@ -73,7 +73,8 @@ abstract class AutoDiffField : Field<Variable> {
|
||||
abstract fun <R> derive(value: R, block: (R) -> Unit): R
|
||||
|
||||
/**
|
||||
* A variable accessing inner state of derivatives. Use only in extensions
|
||||
* A variable accessing inner state of derivatives.
|
||||
* Use this function in inner builders to avoid creating additional derivative bindings
|
||||
*/
|
||||
abstract var Variable.d: Double
|
||||
|
||||
@ -113,6 +114,7 @@ private class AutoDiffContext : AutoDiffField() {
|
||||
*/
|
||||
class VariableWithDeriv(x: Double, var d: Double = 0.0) : Variable(x)
|
||||
|
||||
|
||||
override fun variable(value: Double): Variable = VariableWithDeriv(value)
|
||||
|
||||
override var Variable.d: Double
|
||||
|
@ -52,4 +52,26 @@ class MatrixTest {
|
||||
|
||||
assertEquals(2.0, matrix[1, 2])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMatrixExtension() {
|
||||
val transitionMatrix: Matrix<Double> = VirtualMatrix(6, 6) { row, col ->
|
||||
when {
|
||||
col == 0 -> .50
|
||||
row + 1 == col -> .50
|
||||
row == 5 && col == 5 -> 1.0
|
||||
else -> 0.0
|
||||
}
|
||||
}
|
||||
|
||||
infix fun Matrix<Double>.pow(power: Int): Matrix<Double> {
|
||||
var res = this
|
||||
repeat(power - 1) {
|
||||
res = res dot this
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
val toTenthPower = transitionMatrix pow 10
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user