public class FloatFactory2D extends PersistentObject
Construction | Use idioms like FloatFactory2D.dense.make(4,4) to construct dense matrices, FloatFactory2D.sparse.make(4,4) to construct sparse matrices. |
Construction with initial values | Use other make methods to construct matrices with given initial values. |
Appending rows and columns | Use methods appendColumns , appendRows and repeat to append rows
and columns. |
General block matrices | Use methods compose and
decompose to work with
general block matrices. |
Diagonal matrices | Use methods diagonal(vector) ,
diagonal(matrix) and identity to work with diagonal matrices. |
Diagonal block matrices | Use method
composeDiagonal to work with diagonal block matrices. |
Random | Use methods random and
sample to construct random matrices. |
If the factory is used frequently it might be useful to streamline the notation. For example by aliasing:
FloatFactory2D F = FloatFactory2D.dense; F.make(4,4); F.descending(10,20); F.random(4,4); ... |
Modifier and Type | Field and Description |
---|---|
static FloatFactory2D |
dense
A factory producing dense matrices.
|
static FloatFactory2D |
sparse
A factory producing sparse hash matrices.
|
Modifier and Type | Method and Description |
---|---|
FloatMatrix2D |
appendColumn(FloatMatrix2D A,
FloatMatrix1D b)
C = A||b; Constructs a new matrix which is the column-wise concatenation
of two other matrices.
|
FloatMatrix2D |
appendColumns(FloatMatrix2D A,
FloatMatrix2D B)
C = A||B; Constructs a new matrix which is the column-wise concatenation
of two other matrices.
|
FloatMatrix2D |
appendRow(FloatMatrix2D A,
FloatMatrix1D b)
C = A||b; Constructs a new matrix which is the row-wise concatenation of
two other matrices.
|
FloatMatrix2D |
appendRows(FloatMatrix2D A,
FloatMatrix2D B)
C = A||B; Constructs a new matrix which is the row-wise concatenation of
two other matrices.
|
FloatMatrix2D |
ascending(int rows,
int columns)
Constructs a matrix with cells having ascending values.
|
FloatMatrix2D |
compose(FloatMatrix2D[][] parts)
Constructs a block matrix made from the given parts.
|
FloatMatrix2D |
composeBidiagonal(FloatMatrix2D A,
FloatMatrix2D B)
Constructs a bidiagonal block matrix from the given parts.
|
FloatMatrix2D |
composeDiagonal(FloatMatrix2D A,
FloatMatrix2D B)
Constructs a diagonal block matrix from the given parts (the direct
sum of two matrices).
|
FloatMatrix2D |
composeDiagonal(FloatMatrix2D A,
FloatMatrix2D B,
FloatMatrix2D C)
Constructs a diagonal block matrix from the given parts.
|
void |
decompose(FloatMatrix2D[][] parts,
FloatMatrix2D matrix)
Splits a block matrix into its constituent blocks; Copies blocks of a
matrix into the given parts.
|
void |
demo1()
Demonstrates usage of this class.
|
void |
demo2()
Demonstrates usage of this class.
|
FloatMatrix2D |
descending(int rows,
int columns)
Constructs a matrix with cells having descending values.
|
FloatMatrix2D |
diagonal(float[] vector)
Constructs a new diagonal matrix whose diagonal elements are the elements
of vector.
|
FloatMatrix2D |
diagonal(FloatMatrix1D vector)
Constructs a new diagonal matrix whose diagonal elements are the elements
of vector.
|
FloatMatrix1D |
diagonal(FloatMatrix2D A)
Constructs a new vector consisting of the diagonal elements of A
.
|
FloatMatrix2D |
identity(int rowsAndColumns)
Constructs an identity matrix (having ones on the diagonal and zeros
elsewhere).
|
FloatMatrix2D |
make(float[][] values)
Constructs a matrix with the given cell values.
|
FloatMatrix2D |
make(float[] values,
int rows)
Construct a matrix from a one-dimensional column-major packed array, ala
Fortran.
|
FloatMatrix2D |
make(int rows,
int columns)
Constructs a matrix with the given shape, each cell initialized with
zero.
|
FloatMatrix2D |
make(int rows,
int columns,
float initialValue)
Constructs a matrix with the given shape, each cell initialized with the
given value.
|
FloatMatrix2D |
random(int rows,
int columns)
Constructs a matrix with uniformly distributed values in (0,1)
(exclusive).
|
FloatMatrix2D |
repeat(FloatMatrix2D A,
int rowRepeat,
int columnRepeat)
C = A||A||..||A; Constructs a new matrix which is duplicated both along
the row and column dimension.
|
FloatMatrix2D |
sample(FloatMatrix2D matrix,
float value,
float nonZeroFraction)
Modifies the given matrix to be a randomly sampled matrix.
|
FloatMatrix2D |
sample(int rows,
int columns,
float value,
float nonZeroFraction)
Constructs a randomly sampled matrix with the given shape.
|
clone
public static final FloatFactory2D dense
public static final FloatFactory2D sparse
public FloatMatrix2D appendColumn(FloatMatrix2D A, FloatMatrix1D b)
0 1 2 3 4 5 appendColumn 6 8 --> 0 1 2 6 3 4 5 8
public FloatMatrix2D appendColumns(FloatMatrix2D A, FloatMatrix2D B)
0 1 2 3 4 5 appendColumns 6 7 8 9 --> 0 1 2 6 7 3 4 5 8 9
public FloatMatrix2D appendRow(FloatMatrix2D A, FloatMatrix1D b)
0 1 2 3 4 5 appendRow 6 7 --> 0 1 2 3 4 5 6 7
public FloatMatrix2D appendRows(FloatMatrix2D A, FloatMatrix2D B)
0 1 2 3 4 5 appendRows 6 7 8 9 --> 0 1 2 3 4 5 6 7 8 9
public FloatMatrix2D ascending(int rows, int columns)
0 1 2 3 4 5
public FloatMatrix2D compose(FloatMatrix2D[][] parts)
decompose(FloatMatrix2D[][], FloatMatrix2D)
.
All matrices of a given column within parts must have the same number of columns. All matrices of a given row within parts must have the same number of rows. Otherwise an IllegalArgumentException is thrown. Note that nulls within parts[row,col] are an exception to this rule: they are ignored. Cells are copied. Example:
Code | Result |
FloatMatrix2D[][] parts1 = { { null, make(2, 2, 1), null }, { make(4, 4, 2), null, make(4, 3, 3) }, { null, make(2, 2, 4), null } }; System.out.println(compose(parts1)); |
8 x 9 matrix 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 0 2 2 2 2 0 0 3 3 3 2 2 2 2 0 0 3 3 3 2 2 2 2 0 0 3 3 3 2 2 2 2 0 0 3 3 3 0 0 0 0 4 4 0 0 0 0 0 0 0 4 4 0 0 0 |
FloatMatrix2D[][] parts3 = { { identity(3), null, }, { null, identity(3).viewColumnFlip() }, { identity(3).viewRowFlip(), null } }; System.out.println("\n" + make(parts3)); |
9 x 6 matrix 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 |
FloatMatrix2D A = ascending(2, 2); FloatMatrix2D B = descending(2, 2); FloatMatrix2D _ = null; FloatMatrix2D[][] parts4 = { { A, _, A, _ }, { _, A, _, B } }; System.out.println("\n" + make(parts4)); |
4 x 8 matrix 1 2 0 0 1 2 0 0 3 4 0 0 3 4 0 0 0 0 1 2 0 0 3 2 0 0 3 4 0 0 1 0 |
FloatMatrix2D[][] parts2 = { { null, make(2, 2, 1), null }, { make(4, 4, 2), null, make(4, 3, 3) }, { null, make(2, 3, 4), null } }; System.out.println("\n" + Factory2D.make(parts2)); |
IllegalArgumentException A[0,1].columns != A[2,1].columns (2 != 3) |
IllegalArgumentException
- subject to the conditions outlined above.public FloatMatrix2D composeBidiagonal(FloatMatrix2D A, FloatMatrix2D B)
A 0 0 0 B 0 0 0 Cfrom the given parts. Cells are copied.
A
- bidiagonal matrixB
- bidiagonal matrixpublic FloatMatrix2D composeDiagonal(FloatMatrix2D A, FloatMatrix2D B)
A 0 0 B(The direct sum has A.rows()+B.rows() rows and A.columns()+B.columns() columns). Cells are copied.
public FloatMatrix2D composeDiagonal(FloatMatrix2D A, FloatMatrix2D B, FloatMatrix2D C)
A 0 0 0 B 0 0 0 Cfrom the given parts. Cells are copied.
public void decompose(FloatMatrix2D[][] parts, FloatMatrix2D matrix)
compose(FloatMatrix2D[][])
.
All matrices of a given column within parts must have the same number of columns. All matrices of a given row within parts must have the same number of rows. Otherwise an IllegalArgumentException is thrown. Note that nulls within parts[row,col] are an exception to this rule: they are ignored. Cells are copied. Example:
Code | matrix | --> parts |
FloatMatrix2D matrix = ... ; FloatMatrix2D _ = null; FloatMatrix2D A,B,C,D; A = make(2,2); B = make (4,4); C = make(4,3); D = make (2,2); FloatMatrix2D[][] parts = { { _, A, _ }, { B, _, C }, { _, D, _ } }; decompose(parts,matrix); System.out.println("\nA = "+A); System.out.println("\nB = "+B); System.out.println("\nC = "+C); System.out.println("\nD = "+D); |
8 x 9 matrix 9 9 9 9 1 1 9 9 9 9 9 9 9 1 1 9 9 9 2 2 2 2 9 9 3 3 3 2 2 2 2 9 9 3 3 3 2 2 2 2 9 9 3 3 3 2 2 2 2 9 9 3 3 3 9 9 9 9 4 4 9 9 9 9 9 9 9 4 4 9 9 9 |
A = 2 x 2 matrix
B = 4 x 4 matrix
C = 4 x 3 matrix
D = 2 x 2 matrix |
IllegalArgumentException
- subject to the conditions outlined above.public void demo1()
public void demo2()
public FloatMatrix2D descending(int rows, int columns)
5 4 3 2 1 0
public FloatMatrix2D diagonal(float[] vector)
5 4 3 --> 5 0 0 0 4 0 0 0 3
public FloatMatrix2D diagonal(FloatMatrix1D vector)
5 4 3 --> 5 0 0 0 4 0 0 0 3
public FloatMatrix1D diagonal(FloatMatrix2D A)
5 0 0 9 0 4 0 9 0 0 3 9 --> 5 4 3
A
- the matrix, need not be square.public FloatMatrix2D identity(int rowsAndColumns)
public FloatMatrix2D make(float[] values, int rows)
values
- One-dimensional array of floats, packed by columns (ala
Fortran).rows
- the number of rows.IllegalArgumentException
- values.length must be a multiple of rows
.public FloatMatrix2D make(float[][] values)
The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa.
values
- The values to be filled into the new matrix.IllegalArgumentException
- if
for any 1 <= row < values.length: values[row].length != values[row-1].length
.public FloatMatrix2D make(int rows, int columns)
public FloatMatrix2D make(int rows, int columns, float initialValue)
public FloatMatrix2D random(int rows, int columns)
public FloatMatrix2D repeat(FloatMatrix2D A, int rowRepeat, int columnRepeat)
0 1 2 3 repeat(2,3) --> 0 1 0 1 0 1 2 3 2 3 2 3 0 1 0 1 0 1 2 3 2 3 2 3
public FloatMatrix2D sample(FloatMatrix2D matrix, float value, float nonZeroFraction)
IllegalArgumentException
- if nonZeroFraction < 0 || nonZeroFraction > 1.FloatRandomSampler
public FloatMatrix2D sample(int rows, int columns, float value, float nonZeroFraction)
IllegalArgumentException
- if nonZeroFraction < 0 || nonZeroFraction > 1.FloatRandomSampler
Jump to the Parallel Colt Homepage