public final class Matrices extends Object
Modifier and Type | Method and Description |
---|---|
static int |
cardinality(Matrix A)
Returns the number of non-zero entries in the given matrix
|
static int |
cardinality(Vector x)
Returns the number of non-zero entries in the given vector
|
static int[] |
columnBandwidth(Matrix A)
Finds the number of non-zero entries on each column
|
static double[][] |
getArray(Matrix A)
Returns an array of arrays containing a copy of the given matrix.
|
static double[] |
getArray(Vector x)
Returns a dense array containing a copy of the given vector
|
static DenseVector |
getColumn(Matrix m,
int j) |
static int |
getNumSubDiagonals(Matrix A)
Finds the number of diagonals below the main diagonal.
|
static int |
getNumSuperDiagonals(Matrix A)
Finds the number of diagonals above the main diagonal.
|
static Matrix |
getSubMatrix(Matrix A,
int[] row,
int[] column)
Returns a view into the given matrix.
|
static Vector |
getSubVector(Vector x,
int[] index)
Returns a view into the given vector.
|
static DenseMatrix |
identity(int size)
Returns the identity matrix of the given size
|
static int[] |
index(int from,
int to)
Creates a continuous linear index.
|
static int[] |
index(int from,
int stride,
int to)
Creates a strided linear index.
|
static Vector |
random(int size)
Creates a random vector.
|
static Matrix |
random(int numRows,
int numColumns)
Creates a random matrix.
|
static Matrix |
random(Matrix A)
Populates a matrix with random numbers drawn from a uniform distribution
between 0 and 1
|
static Vector |
random(Vector x)
Populates a vector with random numbers drawn from a uniform distribution
between 0 and 1
|
static int[] |
rowBandwidth(Matrix A)
Finds the number of non-zero entries on each row
|
static Matrix |
synchronizedMatrix(Matrix A)
Returns a synchronized matrix which wraps the given matrix.
|
static Matrix |
synchronizedMatrixByColumns(Matrix A)
Returns a synchronized matrix which wraps the given matrix.
|
static Matrix |
synchronizedMatrixByRows(Matrix A)
Returns a synchronized matrix which wraps the given matrix.
|
static Vector |
synchronizedVector(Vector x)
Returns a synchronized vector which wraps the given vector.
|
static void |
zeroColumns(Matrix A,
double diagonal,
int... column)
Sets the selected columns of
A equal zero, and puts
diagonal on the diagonal of those columns. |
static void |
zeroRows(Matrix A,
double diagonal,
int... row)
Sets the selected rows of
A equal zero, and puts
diagonal on the diagonal of those rows. |
public static int cardinality(Vector x)
public static int cardinality(Matrix A)
public static double[][] getArray(Matrix A)
public static double[] getArray(Vector x)
public static DenseMatrix identity(int size)
size
- Number of rows/columns of the matrixpublic static Vector random(int size)
size
- Size of the vectorpublic static Vector random(Vector x)
x
- Vector to populatepublic static Matrix random(int numRows, int numColumns)
numRows
- Number of rowsnumColumns
- Number of columnspublic static Matrix random(Matrix A)
A
- Matrix to populatepublic static Vector synchronizedVector(Vector x)
set(int, double)
and add(int, double)
methods
and their blocked versions are synchronized.
Note: Do not use the wrapped vector for any operations besides matrix assembly, as these operations may be very slow.
x
- Vector to be wrappedx
public static Matrix synchronizedMatrix(Matrix A)
set(int, int, double)
and add(int, int, double)
methods and their blocked versions are synchronized.
Note: Do not use the wrapped matrix for any operations besides matrix assembly, as these operations may be very slow.
A
- Matrix to be wrappedA
public static Matrix synchronizedMatrixByRows(Matrix A)
set(int, int, double)
and add(int, int, double)
methods and their blocked versions are synchronized.
The locking provided is finer than the locking of the whole matrix, as different threads can access different rows simultaneous, while only one thread can access a given row at a time. Use this for row-major matrices, not for column-major matrices.
Note: Do not use the wrapped matrix for any operations besides matrix assembly, as these operations may be very slow.
A
- Matrix to be wrappedA
. Individual rows are lockedpublic static Matrix synchronizedMatrixByColumns(Matrix A)
set(int, int, double)
and add(int, int, double)
methods and their blocked versions are synchronized.
The locking provided is finer than the locking of the whole matrix, as different threads can access different columns simultaneous, while only one thread can access a given column at a time. Use this for column-major matrices, not for row-major matrices.
Note: Do not use the wrapped matrix for any operations besides matrix assembly, as these operations may be very slow.
A
- Matrix to be wrappedA
. Individual columns are
lockedpublic static Matrix getSubMatrix(Matrix A, int[] row, int[] column)
DenseMatrix
.A
- Matrix to create view onrow
- Rows to access. Must be within the bounds of A
column
- Columns to access. Must be within the bounds of A
A
. Changing it will change the backing
matrixpublic static Vector getSubVector(Vector x, int[] index)
DenseVector
.x
- Vector to create view onindex
- Indices to access. Must be within the bounds of x
x
. Changing it will change the backing
matrixpublic static int[] index(int from, int to)
from
- Start, inclusiveto
- Stop, exclusivepublic static int[] index(int from, int stride, int to)
from
- Start, inclusivestride
- stride=1
for continuous. Negative strides are
allowedto
- Stop, exclusivepublic static int[] rowBandwidth(Matrix A)
public static int[] columnBandwidth(Matrix A)
public static int getNumSubDiagonals(Matrix A)
public static int getNumSuperDiagonals(Matrix A)
public static void zeroRows(Matrix A, double diagonal, int... row)
A
equal zero, and puts
diagonal
on the diagonal of those rows. Useful for enforcing
boundary conditionspublic static void zeroColumns(Matrix A, double diagonal, int... column)
A
equal zero, and puts
diagonal
on the diagonal of those columns. Useful for
enforcing boundary conditionspublic static DenseVector getColumn(Matrix m, int j)
Copyright © 2015. All Rights Reserved.