utes x = y + z. Even in-place methods return the result, such that you can easily chain in-place methods, for example:
x.addi(y).addi(z) // computes x += y; x += z Methods which operate element-wise only make sure that the length of the matrices is correct. Therefore, you can add a 3 * 3 matrix to a 1 * 9 matrix, for example.
Finally, there exist versions which take doubles instead of DoubleMatrix Objects as arguments. These then compute the operation with the same value as the right-hand-side. The same effect can be achieved by passing a DoubleMatrix with exactly one element.
Operation | Method | Comment |
---|
x + y | x.add(y) | |
x - y | x.sub(y), y.rsub(x) | rsub subtracts left from right hand side |
x * y | x.mul(y) | element-wise multiplication |
x.mmul(y) | matrix-matrix multiplication |
x.dot(y) | scalar-product |
x / y | x.div(y), y.rdiv(x) | rdiv divides right hand side by left hand side. |
- x | x.neg() | |
There also exist operations which work on whole columns or rows.
Method | Description |
---|
x.addRowVector | adds a vector to each row (addiRowVector works in-place) |
x.addColumnVector | adds a vector to each column |
x.subRowVector | subtracts a vector from each row |
x.subColumnVector | subtracts a vector from each column |
x.mulRow | Multiplies a row by a scalar |
x.mulColumn | multiplies a row by a column |
In principle, you could achieve the same result by first calling getColumn(), adding, and then calling putColumn, but these methods are much faster.
The following comparison operations are available
Operation | Method |
---|
x < y | x.lt(y) |
x <= y | x.le(y) |
x > y | x.gt(y) |
x >= y | x.ge(y) |
x == y | x.eq(y) |
x != y | x.ne(y) |
Logical operations are also supported. For these operations, a value different from zero is treated as "true" and zero is treated as "false". All operations are carried out elementwise.
Operation | Method |
---|
x & y | x.and(y) |
x | y | x.or(y) |
x ^ y | x.xor(y) |
! x | x.not() |
Finally, there are a few more methods to compute various things:
Method | Description |
---|
x.max() | Return maximal element |
x.argmax() | Return index of largest element |
x.min() | Return minimal element |
x.argmin() | Return index of largest element |
x.columnMins() | Return column-wise minima |
x.columnArgmins() | Return column-wise index of minima |
x.columnMaxs() | Return column-wise maxima |
x.columnArgmaxs() | Return column-wise index of maxima |
@author Mikio Braun, Johannes Schaback