Package ucar.ma2
Class MAMatrix
- java.lang.Object
-
- ucar.ma2.MAMatrix
-
public class MAMatrix extends Object
Abstraction for matrix operations. A matrix is a rank-2 Array: m[rows, cols]. All operations done in double precision
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MAVectorcolumn(int j)Get the jth column, return as a MAVector: same backing store.MAMatrixcopy()Create a new MAMatrix that is the same as this one, with a copy of the backing store.MAVectordot(MAVector v)Dot product of matrix and vector: return M dot vdoublegetDouble(int i, int j)intgetNcols()intgetNrows()static MAMatrixmultiply(MAMatrix m1, MAMatrix m2)Matrix multiply: return m1 * m2.voidpostMultiplyDiagonal(MAVector diag)Matrix multiply by a diagonal matrix, store result in this: this = this * diagvoidpreMultiplyDiagonal(MAVector diag)Matrix multiply by a diagonal matrix, store result in this: this = diag * thisMAVectorrow(int i)Get the ith row, return as a MAVector: same backing store.voidsetDouble(int i, int j, double val)MAMatrixtranspose()Create a MAMatrix that is the transpose of this one, with the same backing store.
-
-
-
Constructor Detail
-
MAMatrix
public MAMatrix(int nrows, int ncols)Create an MAMatrix of the given shape.- Parameters:
nrows- number of rowsncols- number of cols
-
MAMatrix
public MAMatrix(Array a)
Create an MAMatrix using the given rank-2 array.- Parameters:
a- rank-2 array- Throws:
IllegalArgumentException- is a is not rank 2
-
-
Method Detail
-
getNrows
public int getNrows()
-
getNcols
public int getNcols()
-
getDouble
public double getDouble(int i, int j)
-
setDouble
public void setDouble(int i, int j, double val)
-
copy
public MAMatrix copy()
Create a new MAMatrix that is the same as this one, with a copy of the backing store.
-
transpose
public MAMatrix transpose()
Create a MAMatrix that is the transpose of this one, with the same backing store. Use copy() to get a copy.
-
column
public MAVector column(int j)
Get the jth column, return as a MAVector: same backing store.
-
row
public MAVector row(int i)
Get the ith row, return as a MAVector: same backing store.
-
dot
public MAVector dot(MAVector v)
Dot product of matrix and vector: return M dot v- Parameters:
v- dot product with this vector- Returns:
- MAVector result: new vector
- Throws:
IllegalArgumentException- if ncols != v.getSize().
-
multiply
public static MAMatrix multiply(MAMatrix m1, MAMatrix m2)
Matrix multiply: return m1 * m2.- Parameters:
m1- left matrixm2- right matrix- Returns:
- MAMatrix result: new matrix
- Throws:
IllegalArgumentException- if m1.getNcols() != m2.getNrows().
-
postMultiplyDiagonal
public void postMultiplyDiagonal(MAVector diag)
Matrix multiply by a diagonal matrix, store result in this: this = this * diag- Parameters:
diag- diagonal matrix stored as a Vector- Throws:
IllegalArgumentException- if ncols != diag.getNelems().
-
preMultiplyDiagonal
public void preMultiplyDiagonal(MAVector diag)
Matrix multiply by a diagonal matrix, store result in this: this = diag * this- Parameters:
diag- diagonal matrix stored as a Vector- Throws:
IllegalArgumentException- if nrows != diag.getNelems().
-
-