@@ -4,61 +4,60 @@ import org.ejml.dense.row.CommonOps_DDRM
4
4
import org.ejml.dense.row.NormOps_DDRM
5
5
import org.ejml.simple.SimpleMatrix
6
6
7
- open class Matrix <R : Num , C : Num >(private val rows : Nat <R >, private val cols : Nat <C >, internal val storage : SimpleMatrix ) {
8
- val numCols get() = cols.i
7
+ open class Matrix <R : Num , C : Num > internal constructor(internal val storage : SimpleMatrix ) {
8
+ val numCols get(): Int = storage.numCols()
9
+ val numRows get(): Int = storage.numRows()
9
10
10
- val numRows get() = rows.i
11
-
12
- operator fun get (i : Int , j : Int ) = storage[i, j]
11
+ operator fun get (i : Int , j : Int ): Double = storage[i, j]
13
12
14
13
operator fun set (i : Int , j : Int , k : Double ) {
15
14
storage[i, j] = k
16
15
}
17
16
18
- fun diag () = Matrix (rows, cols, storage.diag())
19
- fun maxInternal () = CommonOps_DDRM .elementMax(this .storage.ddrm)
20
- fun minInternal () = CommonOps_DDRM .elementMin(this .storage.ddrm)
17
+ fun diag (): Matrix < R , C > = Matrix ( storage.diag())
18
+ fun maxInternal (): Double = CommonOps_DDRM .elementMax(this .storage.ddrm)
19
+ fun minInternal (): Double = CommonOps_DDRM .elementMin(this .storage.ddrm)
21
20
fun mean () = elementSum() / storage.numElements.toDouble()
22
21
23
22
operator fun <C2 : Num > times (other : Matrix <C , C2 >): Matrix <R , C2 >
24
- = Matrix (rows, other.cols, this .storage.mult(other.storage))
23
+ = Matrix (this .storage.mult(other.storage))
25
24
26
25
operator fun times (value : Double ): Matrix <R , C >
27
- = Matrix (rows, cols, this .storage.scale(value))
26
+ = Matrix (this .storage.scale(value))
28
27
29
28
fun elementTimes (other : Matrix <R , C >): Matrix <R , C >
30
- = Matrix (rows, cols, this .storage.elementMult(other.storage))
29
+ = Matrix (this .storage.elementMult(other.storage))
31
30
32
- operator fun unaryMinus () = Matrix (rows, cols, storage.scale(- 1.0 ))
31
+ operator fun unaryMinus (): Matrix < R , C > = Matrix ( storage.scale(- 1.0 ))
33
32
34
- operator fun minus (value : Double ) = Matrix (rows, cols, storage.minus(value))
33
+ operator fun minus (value : Double ): Matrix < R , C > = Matrix ( storage.minus(value))
35
34
36
- operator fun minus (value : Matrix <R , C >) = Matrix (rows, cols, storage.minus(value.storage))
35
+ operator fun minus (value : Matrix <R , C >): Matrix < R , C > = Matrix ( storage.minus(value.storage))
37
36
38
- operator fun plus (value : Double ) = Matrix (rows, cols, storage.plus(value))
37
+ operator fun plus (value : Double ): Matrix < R , C > = Matrix ( storage.plus(value))
39
38
40
- operator fun plus (value : Matrix <R , C >) = Matrix (rows, cols, storage.plus(value.storage))
39
+ operator fun plus (value : Matrix <R , C >): Matrix < R , C > = Matrix ( storage.plus(value.storage))
41
40
42
- operator fun div (value : Int ) = Matrix (rows, cols, storage.divide(value.toDouble()))
41
+ operator fun div (value : Int ): Matrix < R , C > = Matrix ( storage.divide(value.toDouble()))
43
42
44
- operator fun div (value : Double ) = Matrix (rows, cols, storage.divide(value))
43
+ operator fun div (value : Double ): Matrix < R , C > = Matrix ( storage.divide(value))
45
44
46
- fun transpose (): Matrix <C , R > = Matrix (cols, rows, storage.transpose())
45
+ fun transpose (): Matrix <C , R > = Matrix (storage.transpose())
47
46
48
- fun copy () = Matrix (cols, rows, storage.copy())
47
+ fun copy (): Matrix < R , C > = Matrix ( storage.copy())
49
48
50
- fun inv (): Matrix <R , C > = Matrix (rows, cols, storage.invert())
49
+ fun inv (): Matrix <R , C > = Matrix (storage.invert())
51
50
52
51
fun det (): Double = storage.determinant()
53
52
54
- fun normF () = storage.normF()
53
+ fun normF (): Double = storage.normF()
55
54
56
- fun normIndP1 () = NormOps_DDRM .inducedP1(this .storage.ddrm)
55
+ fun normIndP1 (): Double = NormOps_DDRM .inducedP1(this .storage.ddrm)
57
56
58
- fun elementSum () = this .storage.elementSum()
57
+ fun elementSum (): Double = this .storage.elementSum()
59
58
60
- fun trace () = this .storage.trace()
59
+ fun trace (): Double = this .storage.trace()
61
60
62
- fun epow (other : Double ): Matrix <R , C > = Matrix (rows, cols, storage.elementPower(other))
63
- fun epow (other : Int ): Matrix <R , C > = Matrix (rows, cols, storage.elementPower(other.toDouble()))
61
+ fun epow (other : Double ): Matrix <R , C > = Matrix (storage.elementPower(other))
62
+ fun epow (other : Int ): Matrix <R , C > = Matrix (storage.elementPower(other.toDouble()))
64
63
}
0 commit comments