Class Matrices
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Returns the number of non-zero entries in the given matrixstatic int
Returns the number of non-zero entries in the given vectorstatic int[]
Finds the number of non-zero entries on each columnstatic double[][]
Returns an array of arrays containing a copy of the given matrix.static double[]
Returns a dense array containing a copy of the given vectorstatic int
Finds the number of diagonals below the main diagonal.static int
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 sizestatic 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
Populates a matrix with random numbers drawn from a uniform distribution between 0 and 1static Vector
Populates a vector with random numbers drawn from a uniform distribution between 0 and 1static int[]
Finds the number of non-zero entries on each rowstatic Matrix
Returns a synchronized matrix which wraps the given matrix.static Matrix
Returns a synchronized matrix which wraps the given matrix.static Matrix
Returns a synchronized matrix which wraps the given matrix.static Vector
Returns a synchronized vector which wraps the given vector.static void
zeroColumns
(Matrix A, double diagonal, int... column) Sets the selected columns ofA
equal zero, and putsdiagonal
on the diagonal of those columns.static void
Sets the selected rows ofA
equal zero, and putsdiagonal
on the diagonal of those rows.
-
Method Details
-
cardinality
Returns the number of non-zero entries in the given vector -
cardinality
Returns the number of non-zero entries in the given matrix -
getArray
Returns an array of arrays containing a copy of the given matrix. Each array contains one row. -
getArray
Returns a dense array containing a copy of the given vector -
identity
Returns the identity matrix of the given size- Parameters:
size
- Number of rows/columns of the matrix- Returns:
- Matrix of the given size, with ones on the main diagonal
-
random
Creates a random vector. Numbers are drawn from a uniform distribution between 0 and 1- Parameters:
size
- Size of the vector
-
random
Populates a vector with random numbers drawn from a uniform distribution between 0 and 1- Parameters:
x
- Vector to populate
-
random
Creates a random matrix. Numbers are drawn from a uniform distribution between 0 and 1- Parameters:
numRows
- Number of rowsnumColumns
- Number of columns
-
random
Populates a matrix with random numbers drawn from a uniform distribution between 0 and 1- Parameters:
A
- Matrix to populate
-
synchronizedVector
Returns a synchronized vector which wraps the given vector. Only theset(int, double)
andadd(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.
- Parameters:
x
- Vector to be wrapped- Returns:
- A thin wrapper around
x
-
synchronizedMatrix
Returns a synchronized matrix which wraps the given matrix. Only theset(int, int, double)
andadd(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.
- Parameters:
A
- Matrix to be wrapped- Returns:
- A thin wrapper around
A
-
synchronizedMatrixByRows
Returns a synchronized matrix which wraps the given matrix. Only theset(int, int, double)
andadd(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.
- Parameters:
A
- Matrix to be wrapped- Returns:
- A thin wrapper around
A
. Individual rows are locked
-
synchronizedMatrixByColumns
Returns a synchronized matrix which wraps the given matrix. Only theset(int, int, double)
andadd(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.
- Parameters:
A
- Matrix to be wrapped- Returns:
- A thin wrapper around
A
. Individual columns are locked
-
getSubMatrix
Returns a view into the given matrix. This view is only for easing some matrix-assembly cases, not for general use. To extract a more higher-performing and general matrix, create a copy of the submatrix. The result is aDenseMatrix
.- Parameters:
A
- Matrix to create view onrow
- Rows to access. Must be within the bounds ofA
column
- Columns to access. Must be within the bounds ofA
- Returns:
- Submatrix of
A
. Changing it will change the backing matrix
-
getSubVector
Returns a view into the given vector. This view is only for easing some vector-assembly cases, not for general use. To extract a more higher-performing and general vector, create a copy of the subvector. The result is aDenseVector
.- Parameters:
x
- Vector to create view onindex
- Indices to access. Must be within the bounds ofx
- Returns:
- Submatrix of
x
. Changing it will change the backing matrix
-
index
public static int[] index(int from, int to) Creates a continuous linear index.- Parameters:
from
- Start, inclusiveto
- Stop, exclusive
-
index
public static int[] index(int from, int stride, int to) Creates a strided linear index.- Parameters:
from
- Start, inclusivestride
-stride=1
for continuous. Negative strides are allowedto
- Stop, exclusive
-
rowBandwidth
Finds the number of non-zero entries on each row -
columnBandwidth
Finds the number of non-zero entries on each column -
getNumSubDiagonals
Finds the number of diagonals below the main diagonal. Useful for converting a general matrix into a banded matrix -
getNumSuperDiagonals
Finds the number of diagonals above the main diagonal. Useful for converting a general matrix into a banded matrix -
zeroRows
Sets the selected rows ofA
equal zero, and putsdiagonal
on the diagonal of those rows. Useful for enforcing boundary conditions -
zeroColumns
Sets the selected columns ofA
equal zero, and putsdiagonal
on the diagonal of those columns. Useful for enforcing boundary conditions
-