public class DenseMatrix extends Object implements Serializable
Constructor and Description |
---|
DenseMatrix(double[][] data)
Construct a matrix from a 2-D array.
|
DenseMatrix(int m,
int n)
Construct an m-by-n matrix of zeros.
|
DenseMatrix(int m,
int n,
double[] data)
Construct a matrix from a 1-D array.
|
DenseMatrix(int m,
int n,
double[] data,
boolean inRowMajor)
Construct a matrix from a 1-D array.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int i,
int j,
double s)
Add the given value to a single element.
|
DenseMatrix |
clone()
Clone the Matrix object.
|
static DenseMatrix |
eye(int n)
Create an identity matrix.
|
static DenseMatrix |
eye(int m,
int n)
Create a m * n identity matrix.
|
double |
get(int i,
int j)
Get a single element.
|
double[] |
getArrayCopy1D(boolean inRowMajor)
Get all matrix data, returned as a 1-D array.
|
double[][] |
getArrayCopy2D()
Get all the matrix data, returned as a 2-D array.
|
double[] |
getColumn(int col)
Get one column.
|
double[] |
getData()
Get the data array of this matrix.
|
double[] |
getRow(int row)
Get one row.
|
DenseMatrix |
getSubMatrix(int m0,
int m1,
int n0,
int n1)
Get sub matrix.
|
boolean |
isSquare()
Check whether the matrix is square matrix.
|
boolean |
isSymmetric()
Check whether the matrix is symmetric matrix.
|
DenseMatrix |
minus(DenseMatrix mat)
Create a new matrix by subtracting another matrix.
|
void |
minusEquals(DenseMatrix mat)
Minus with another vector.
|
DenseMatrix |
multiplies(DenseMatrix mat)
Multiply with another matrix.
|
DenseVector |
multiplies(DenseVector x)
Multiply with a dense vector.
|
DenseVector |
multiplies(SparseVector x)
Multiply with a sparse vector.
|
int |
numCols()
Get the number of columns.
|
int |
numRows()
Get the number of rows.
|
static DenseMatrix |
ones(int m,
int n)
Create a matrix with all elements set to 1.
|
DenseMatrix |
plus(DenseMatrix mat)
Create a new matrix by plussing another matrix.
|
DenseMatrix |
plus(double alpha)
Create a new matrix by plussing a constant.
|
void |
plusEquals(DenseMatrix mat)
Plus with another matrix.
|
void |
plusEquals(double alpha)
Plus with a constant.
|
static DenseMatrix |
rand(int m,
int n)
Create a random matrix.
|
static DenseMatrix |
randSymmetric(int n)
Create a random symmetric matrix.
|
DenseMatrix |
scale(double v)
Scale the vector by value "v" and create a new matrix to store the result.
|
void |
scaleEqual(double v)
Scale the matrix by value "v".
|
DenseMatrix |
selectRows(int[] rows)
Create a new matrix by selecting some of the rows.
|
void |
set(int i,
int j,
double s)
Set a single element.
|
void |
setSubMatrix(DenseMatrix sub,
int m0,
int m1,
int n0,
int n1)
Set part of the matrix values from the values of another matrix.
|
double |
sum()
Sum of all elements of the matrix.
|
String |
toString() |
DenseMatrix |
transpose()
Create a new matrix by transposing current matrix.
|
static DenseMatrix |
zeros(int m,
int n)
Create a zero matrix.
|
public DenseMatrix(int m, int n)
m
- Number of rows.n
- Number of columns.public DenseMatrix(int m, int n, double[] data)
m
- Number of rows.n
- Number of cols.data
- One-dimensional array of doubles.public DenseMatrix(int m, int n, double[] data, boolean inRowMajor)
m
- Number of rows.n
- Number of cols.data
- One-dimensional array of doubles.inRowMajor
- Whether the matrix in 'data' is in row major format.public DenseMatrix(double[][] data)
data
- Two-dimensional array of doubles.IllegalArgumentException
- All rows must have the same sizepublic static DenseMatrix eye(int n)
n
- the dimension of the eye matrix.public static DenseMatrix eye(int m, int n)
m
- the row dimension.n
- the column dimension.epublic static DenseMatrix zeros(int m, int n)
m
- the row dimension.n
- the column dimension.public static DenseMatrix ones(int m, int n)
m
- the row dimensionn
- the column dimensionpublic static DenseMatrix rand(int m, int n)
m
- the row dimensionn
- the column dimension.public static DenseMatrix randSymmetric(int n)
n
- the dimension of the symmetric matrix.public double get(int i, int j)
i
- Row index.j
- Column index.ArrayIndexOutOfBoundsException
public double[] getData()
public double[][] getArrayCopy2D()
public double[] getArrayCopy1D(boolean inRowMajor)
inRowMajor
- Whether to return data in row major.public double[] getRow(int row)
row
- the row index.public double[] getColumn(int col)
col
- the column index.public DenseMatrix clone()
public DenseMatrix selectRows(int[] rows)
rows
- the array of row indexes to select.public DenseMatrix getSubMatrix(int m0, int m1, int n0, int n1)
m0
- the starting row index (inclusive)m1
- the ending row index (exclusive)n0
- the starting column index (inclusive)n1
- the ending column index (exclusive)public void setSubMatrix(DenseMatrix sub, int m0, int m1, int n0, int n1)
sub
- the matrix whose element values will be assigned to the sub matrix of this matrix.m0
- the starting row index (inclusive)m1
- the ending row index (exclusive)n0
- the starting column index (inclusive)n1
- the ending column index (exclusive)public void set(int i, int j, double s)
i
- Row index.j
- Column index.s
- A(i,j).ArrayIndexOutOfBoundsException
public void add(int i, int j, double s)
i
- Row index.j
- Column index.s
- A(i,j).ArrayIndexOutOfBoundsException
public boolean isSquare()
true
if this matrix is a square matrix, false
otherwise.public boolean isSymmetric()
true
if this matrix is a symmetric matrix, false
otherwise.public int numRows()
public int numCols()
public double sum()
public DenseMatrix scale(double v)
public void scaleEqual(double v)
public DenseMatrix plus(DenseMatrix mat)
public DenseMatrix plus(double alpha)
public void plusEquals(DenseMatrix mat)
public void plusEquals(double alpha)
public DenseMatrix minus(DenseMatrix mat)
public void minusEquals(DenseMatrix mat)
public DenseMatrix multiplies(DenseMatrix mat)
public DenseVector multiplies(DenseVector x)
public DenseVector multiplies(SparseVector x)
public DenseMatrix transpose()
Use cache-oblivious matrix transpose algorithm.
Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.