Package org.jblas

Class FloatMatrix

java.lang.Object
org.jblas.FloatMatrix
All Implemented Interfaces:
Serializable

public class FloatMatrix extends Object implements Serializable
A general matrix class for float typed values. Don't be intimidated by the large number of methods this function defines. Most are overloads provided for ease of use. For example, for each arithmetic operation, up to six overloaded versions exist to handle in-place computations, and scalar arguments (like adding a number to all elements of a matrix).

Construction

To construct a two-dimensional matrices, you can use the following constructors and static methods.

MethodDescription
FloatMatrix(m,n, [value1, value2, value3...])Values are filled in column by column.
FloatMatrix(new float[][] {{value1, value2, ...}, ...}Inner arrays are rows.
FloatMatrix.zeros(m,n) Initial values set to 0.0f.
FloatMatrix.ones(m,n) Initial values set to 1.0f.
FloatMatrix.rand(m,n) Values drawn at random between 0.0f and 1.0f.
FloatMatrix.randn(m,n) Values drawn from normal distribution.
FloatMatrix.eye(n) Unit matrix (values 0.0f except for 1.0f on the diagonal).
FloatMatrix.diag(array) Diagonal matrix with given diagonal elements.
Matrix constructors.

Alternatively, you can construct (column) vectors, if you just supply the length using the following constructors and static methods.

Method Description
FloatMatrix(m) Constructs a column vector.
FloatMatrix(new float[] {value1, value2, ...})Constructs a column vector.
FloatMatrix.zeros(m) Initial values set to 0.0f.
FloatMatrix.ones(m) Initial values set to 1.0f.
FloatMatrix.rand(m) Values drawn at random between 0.0f and 1.0f.
FloatMatrix.randn(m) Values drawn from normal distribution.
FloatMatrix.linspace(a, b, n)n linearly spaced values from a to b.
FloatMatrix.logspace(a, b, n)n logarithmically spaced values form 10^a to 10^b.
Column vector constructors.

You can also construct new matrices by concatenating matrices either horziontally or vertically:

MethodDescription
x.concatHorizontally(y)New matrix will be x next to y.
x.concatVertically(y)New matrix will be x atop y.
Matrix concatenation.

Element Access, Copying and Duplication

To access individual elements, or whole rows and columns, use the following methods:

x.MethodDescription
x.get(i,j)Get element in row i and column j.
x.put(i, j, v)Set element in row i and column j to value v
x.get(i)Get the ith element of the matrix (traversing rows first).
x.put(i, v)Set the ith element of the matrix (traversing rows first).
x.getColumn(i)Get a copy of column i.
x.putColumn(i, c)Put matrix c into column i.
x.getRow(i)Get a copy of row i.
x.putRow(i, c)Put matrix c into row i.
x.swapColumns(i, j)Swap the contents of columns i and j.
x.swapRows(i, j)Swap the contents of rows i and j.
Element access.

For get and put, you can also pass integer arrays, FloatMatrix objects, or Range objects, which then specify the indices used as follows:

  • integer array: the elements will be used as indices.
  • FloatMatrix object: non-zero entries specify the indices.
  • Range object: see below.

When using put with multiple indices, the assigned object must have the correct size or be a scalar.

There exist the following Range objects. The Class RangeUtils also contains the a number of handy helper methods for constructing these ranges.

Class RangeUtils method Indices
AllRange all() All legal indices.
PointRange point(i) A single point.
IntervalRange interval(a, b) All indices from a to b (inclusive)
IndicesRange indices(int[]) The specified indices.
indices(FloatMatrix)The specified indices.
find(FloatMatrix)The non-zero entries of the matrix.
Range objects.

The following methods can be used for duplicating and copying matrices.

MethodDescription
x.dup()Get a copy of x.
x.copy(y)Copy the contents of y to x (possible resizing x).
Copying matrices.

Size and Shape

The following methods permit to access the size of a matrix and change its size or shape.

x.MethodDescription
x.rowsNumber of rows.
x.columnsNumber of columns.
x.lengthTotal number of elements.
x.isEmpty()Checks whether rows == 0 and columns == 0.
x.isRowVector()Checks whether rows == 1.
x.isColumnVector()Checks whether columns == 1.
x.isVector()Checks whether rows == 1 or columns == 1.
x.isSquare()Checks whether rows == columns.
x.isScalar()Checks whether length == 1.
x.resize(r, c)Resize the matrix to r rows and c columns, discarding the content.
x.reshape(r, c)Resize the matrix to r rows and c columns.
Number of elements must not change.
Size and size checks.

The size is stored in the rows and columns member variables. The total number of elements is stored in length. Do not change these values unless you know what you're doing!

Arithmetics

The usual arithmetic operations are implemented. Each operation exists in a in-place version, recognizable by the suffix "i", to which you can supply the result matrix (or this is used, if missing). Using in-place operations can also lead to a smaller memory footprint, as the number of temporary objects is reduced (although the JVM garbage collector is usually pretty good at reusing these temporary object immediately with little overhead.)

Whenever you specify a result vector, the result vector must already have the correct dimensions.

For example, you can add two matrices using the add method. If you want to store the result in of x + y in z, type x.addi(y, z) // computes x = y + z. Even in-place methods return the result, such that you can easily chain in-place methods, for example: x.addi(y).addi(z) // computes x += y; x += z

Methods which operate element-wise only make sure that the length of the matrices is correct. Therefore, you can add a 3 * 3 matrix to a 1 * 9 matrix, for example.

Finally, there exist versions which take floats instead of FloatMatrix Objects as arguments. These then compute the operation with the same value as the right-hand-side. The same effect can be achieved by passing a FloatMatrix with exactly one element.

Operation Method Comment
x + y x.add(y)
x - y x.sub(y), y.rsub(x) rsub subtracts left from right hand side
x * y x.mul(y) element-wise multiplication
x.mmul(y)matrix-matrix multiplication
x.dot(y) scalar-product
x / y x.div(y), y.rdiv(x) rdiv divides right hand side by left hand side.
- x x.neg()
Basic arithmetics.

There also exist operations which work on whole columns or rows.

Method Description
x.addRowVector adds a vector to each row (addiRowVector works in-place)
x.addColumnVectoradds a vector to each column
x.subRowVector subtracts a vector from each row
x.subColumnVectorsubtracts a vector from each column
x.mulRowVector Multiplies each row by a vector (elementwise)
x.mulColumnVectorMultiplies each column by a vector (elementwise)
x.divRowVector Divide each row by a vector (elementwise)
x.divColumnVectorDivide each column by a vector (elementwise)
x.mulRow Multiplies a row by a scalar
x.mulColumn Multiplies a column by a scalar
Row and column arithmetics.

In principle, you could achieve the same result by first calling getColumn(), adding, and then calling putColumn, but these methods are much faster.

The following comparison operations are available

Operation Method
x < y x.lt(y)
x <= y x.le(y)
x > y x.gt(y)
x >= y x.ge(y)
x == y x.eq(y)
x != y x.ne(y)
Comparison operations.

Logical operations are also supported. For these operations, a value different from zero is treated as "true" and zero is treated as "false". All operations are carried out elementwise.

Operation Method
x & y x.and(y)
x | y x.or(y)
x ^ y x.xor(y)
! x x.not()
Logical operations.

Finally, there are a few more methods to compute various things:

Method Description
x.max() Return maximal element
x.argmax() Return index of largest element
x.min() Return minimal element
x.argmin() Return index of smallest element
x.columnMins() Return column-wise minima
x.columnArgmins() Return column-wise index of minima
x.columnMaxs() Return column-wise maxima
x.columnArgmaxs() Return column-wise index of maxima
Minimum and maximum.
See Also:
  • Field Details

    • rows

      public int rows
      Number of rows.
    • columns

      public int columns
      Number of columns.
    • length

      public int length
      Total number of elements (for convenience).
    • data

      public float[] data
      The actual data stored by rows (that is, row 0, row 1...).
    • EMPTY

      public static final FloatMatrix EMPTY
    • serialVersionUID

      static final long serialVersionUID
      See Also:
    • SEMICOLON

      private static final Pattern SEMICOLON
    • WHITESPACES

      private static final Pattern WHITESPACES
    • COMMA

      private static final Pattern COMMA
  • Constructor Details

    • FloatMatrix

      public FloatMatrix(int newRows, int newColumns, float... newData)
      Create a new matrix with newRows rows, newColumns columns using newData as the data. Note that any change to the FloatMatrix will change the input array, too.
      Parameters:
      newRows - the number of rows of the new matrix
      newColumns - the number of columns of the new matrix
      newData - the data array to be used. Data must be stored by column (column-major)
    • FloatMatrix

      public FloatMatrix(int newRows, int newColumns)
      Creates a new n times m FloatMatrix.
      Parameters:
      newRows - the number of rows (n) of the new matrix.
      newColumns - the number of columns (m) of the new matrix.
    • FloatMatrix

      public FloatMatrix()
      Creates a new FloatMatrix of size 0 times 0.
    • FloatMatrix

      public FloatMatrix(int len)
      Create a Matrix of length len. This creates a column vector.
      Parameters:
      len -
    • FloatMatrix

      public FloatMatrix(float[] newData)
      Create a a column vector using newData as the data array. Note that any change to the created FloatMatrix will change in input array.
    • FloatMatrix

      public FloatMatrix(String filename) throws IOException
      Creates a new matrix by reading it from a file.
      Parameters:
      filename - the path and name of the file to read the matrix from
      Throws:
      IOException
    • FloatMatrix

      public FloatMatrix(float[][] data)
      Creates a new n times m FloatMatrix from the given n times m 2D data array. Note that the input array is copied and any change to the FloatMatrix will not change the input array. The first dimension of the array makes the rows (n) and the second dimension the columns (m). For example, the given code

      new FloatMatrix(new float[][]{{1d, 2d, 3d}, {4d, 5d, 6d}, {7d, 8d, 9d}}).print();

      will constructs the following matrix:
       1.0f   2.0f    3.0f
       4.0f   5.0f    6.0f
       7.0f   8.0f    9.0f
       
      .
      Parameters:
      data - n times m data array
    • FloatMatrix

      public FloatMatrix(List<Float> data)
      Creates a FloatMatrix column vector from the given List<Double>.
      Parameters:
      data - data from which the entries are taken.
  • Method Details

    • valueOf

      public static FloatMatrix valueOf(String text)
      Construct FloatMatrix from ASCII representation. This is not very fast, but can be quiet useful when you want to "just" construct a matrix, for example when testing. The format is semicolon separated rows of space separated values, for example "1 2 3; 4 5 6; 7 8 9".
    • writeObject

      private void writeObject(ObjectOutputStream s) throws IOException
      Serialization
      Throws:
      IOException
    • readObject

      private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • rand

      public static FloatMatrix rand(int rows, int columns)
      Create matrix with random values uniformly in 0..1.
    • rand

      public static FloatMatrix rand(int len)
      Creates a column vector with random values uniformly in 0..1.
    • randn

      public static FloatMatrix randn(int rows, int columns)
      Create matrix with normally distributed random values.
    • randn

      public static FloatMatrix randn(int len)
      Create column vector with normally distributed random values.
    • zeros

      public static FloatMatrix zeros(int rows, int columns)
      Creates a new matrix in which all values are equal 0.
    • zeros

      public static FloatMatrix zeros(int length)
      Creates a column vector of given length.
    • ones

      public static FloatMatrix ones(int rows, int columns)
      Creates a new matrix in which all values are equal 1.
    • ones

      public static FloatMatrix ones(int length)
      Creates a column vector with all elements equal to 1.
    • eye

      public static FloatMatrix eye(int n)
      Construct a new n-by-n identity matrix.
    • diag

      public static FloatMatrix diag(FloatMatrix x)
      Creates a new matrix where the values of the given vector are the diagonal values of the matrix.
    • diag

      public static FloatMatrix diag(FloatMatrix x, int rows, int columns)
      Construct a matrix of arbitrary shape and set the diagonal according to a passed vector. length of needs to be smaller than rows or columns.
      Parameters:
      x - vector to fill the diagonal with
      rows - number of rows of the resulting matrix
      columns - number of columns of the resulting matrix
      Returns:
      a matrix with dimensions rows * columns whose diagonal elements are filled by x
    • scalar

      public static FloatMatrix scalar(float s)
      Create a 1-by-1 matrix. For many operations, this matrix functions like a normal float.
    • isScalar

      public boolean isScalar()
      Test whether a matrix is scalar.
    • scalar

      public float scalar()
      Return the first element of the matrix.
    • logspace

      public static FloatMatrix logspace(float lower, float upper, int size)
      Construct a column vector whose entries are logarithmically spaced points from 10^lower to 10^upper using the specified number of steps
      Parameters:
      lower - starting exponent
      upper - ending exponent
      size - number of steps
      Returns:
      a column vector with (10^lower, ... 10^upper) with size many entries.
    • linspace

      public static FloatMatrix linspace(int lower, int upper, int size)
      Construct a column vector whose entries are linearly spaced points from lower to upper with size many steps.
      Parameters:
      lower - starting value
      upper - end value
      size - number of steps
      Returns:
      a column vector of size (lower, ..., upper) with size many entries.
    • concatHorizontally

      public static FloatMatrix concatHorizontally(FloatMatrix A, FloatMatrix B)
      Concatenates two matrices horizontally. Matrices must have identical numbers of rows.
    • concatVertically

      public static FloatMatrix concatVertically(FloatMatrix A, FloatMatrix B)
      Concatenates two matrices vertically. Matrices must have identical numbers of columns.
    • get

      public FloatMatrix get(int[] indices)
      Get all elements specified by the linear indices.
    • get

      public FloatMatrix get(int r, int[] indices)
      Get all elements for a given row and the specified columns.
    • get

      public FloatMatrix get(int[] indices, int c)
      Get all elements for a given column and the specified rows.
    • get

      public FloatMatrix get(int[] rindices, int[] cindices)
      Get all elements from the specified rows and columns.
    • get

      public FloatMatrix get(Range rs, Range cs)
      Get elements from specified rows and columns.
    • get

      public FloatMatrix get(Range rs, int c)
    • get

      public FloatMatrix get(int r, Range cs)
    • get

      public FloatMatrix get(FloatMatrix indices)
      Get elements specified by the non-zero entries of the passed matrix.
    • get

      public FloatMatrix get(int r, FloatMatrix indices)
      Get elements from a row and columns as specified by the non-zero entries of a matrix.
    • get

      public FloatMatrix get(FloatMatrix indices, int c)
      Get elements from a column and rows as specified by the non-zero entries of a matrix.
    • get

      public FloatMatrix get(FloatMatrix rindices, FloatMatrix cindices)
      Get elements from columns and rows as specified by the non-zero entries of the passed matrices.
    • getRange

      public FloatMatrix getRange(int a, int b)
      Return all elements with linear index a, a + 1, ..., b - 1.
    • getColumnRange

      public FloatMatrix getColumnRange(int r, int a, int b)
      Get elements from a row and columns a to b.
    • getRowRange

      public FloatMatrix getRowRange(int a, int b, int c)
      Get elements from a column and rows a to b.
    • getRange

      public FloatMatrix getRange(int ra, int rb, int ca, int cb)
      Get elements from rows ra to rb and columns ca to cb.
    • getRows

      public FloatMatrix getRows(int[] rindices)
      Get whole rows from the passed indices.
    • getRows

      public FloatMatrix getRows(FloatMatrix rindices)
      Get whole rows as specified by the non-zero entries of a matrix.
    • getRows

      public FloatMatrix getRows(Range indices, FloatMatrix result)
    • getRows

      public FloatMatrix getRows(Range indices)
    • getColumns

      public FloatMatrix getColumns(int[] cindices)
      Get whole columns from the passed indices.
    • getColumns

      public FloatMatrix getColumns(FloatMatrix cindices)
      Get whole columns as specified by the non-zero entries of a matrix.
    • getColumns

      public FloatMatrix getColumns(Range indices, FloatMatrix result)
      Get whole columns as specified by Range.
    • getColumns

      public FloatMatrix getColumns(Range indices)
    • checkLength

      public void checkLength(int l)
      Assert that the matrix has a certain length.
      Throws:
      SizeException
    • checkRows

      public void checkRows(int r)
      Asserts that the matrix has a certain number of rows.
      Throws:
      SizeException
    • checkColumns

      public void checkColumns(int c)
      Asserts that the amtrix has a certain number of columns.
      Throws:
      SizeException
    • put

      public FloatMatrix put(int[] indices, FloatMatrix x)
      Set elements in linear ordering in the specified indices. For example, a.put(new int[]{ 1, 2, 0 }, new FloatMatrix(3, 1, 2.0f, 4.0f, 8.0f) does a.put(1, 2.0f), a.put(2, 4.0f), a.put(0, 8.0f).
    • put

      public FloatMatrix put(int r, int[] indices, FloatMatrix x)
      Set multiple elements in a row.
    • put

      public FloatMatrix put(int[] indices, int c, FloatMatrix x)
      Set multiple elements in a row.
    • put

      public FloatMatrix put(int[] rindices, int[] cindices, FloatMatrix x)
      Put a sub-matrix as specified by the indices.
    • put

      public FloatMatrix put(Range rs, Range cs, FloatMatrix x)
      Put a matrix into specified indices.
    • put

      public FloatMatrix put(int[] indices, float v)
      Put a single value into the specified indices (linear adressing).
    • put

      public FloatMatrix put(int r, int[] indices, float v)
      Put a single value into a row and the specified columns.
    • put

      public FloatMatrix put(int[] indices, int c, float v)
      Put a single value into the specified rows of a column.
    • put

      public FloatMatrix put(int[] rindices, int[] cindices, float v)
      Put a single value into the specified rows and columns.
    • put

      public FloatMatrix put(FloatMatrix indices, FloatMatrix v)
      Put a sub-matrix into the indices specified by the non-zero entries of indices (linear adressing).
    • put

      public FloatMatrix put(int r, FloatMatrix indices, FloatMatrix v)
      Put a sub-vector into the specified columns (non-zero entries of indices) of a row.
    • put

      public FloatMatrix put(FloatMatrix indices, int c, FloatMatrix v)
      Put a sub-vector into the specified rows (non-zero entries of indices) of a column.
    • put

      public FloatMatrix put(FloatMatrix rindices, FloatMatrix cindices, FloatMatrix v)
      Put a sub-matrix into the specified rows and columns (non-zero entries of rindices and cindices.
    • put

      public FloatMatrix put(FloatMatrix indices, float v)
      Put a single value into the elements specified by the non-zero entries of indices (linear adressing).
    • put

      public FloatMatrix put(int r, FloatMatrix indices, float v)
      Put a single value into the specified columns (non-zero entries of indices) of a row.
    • put

      public FloatMatrix put(FloatMatrix indices, int c, float v)
      Put a single value into the specified rows (non-zero entries of indices) of a column.
    • put

      public FloatMatrix put(FloatMatrix rindices, FloatMatrix cindices, float v)
      Put a single value in the specified rows and columns (non-zero entries of rindices and cindices.
    • findIndices

      public int[] findIndices()
      Find the linear indices of all non-zero elements.
    • transpose

      public FloatMatrix transpose()
      Return transposed copy of this matrix.
    • compare

      public boolean compare(Object o, float tolerance)
      Compare two matrices. Returns true if and only if other is also a FloatMatrix which has the same size and the maximal absolute difference in matrix elements is smaller than the specified tolerance
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • resize

      public void resize(int newRows, int newColumns)
      Resize the matrix. All elements will be set to zero.
    • reshape

      public FloatMatrix reshape(int newRows, int newColumns)
      Reshape the matrix. Number of elements must not change.
    • repmat

      public FloatMatrix repmat(int rowMult, int columnMult)
      Generate a new matrix which has the given number of replications of this.
    • sameSize

      public boolean sameSize(FloatMatrix a)
      Checks whether two matrices have the same size.
    • assertSameSize

      public void assertSameSize(FloatMatrix a)
      Throws SizeException unless two matrices have the same size.
    • multipliesWith

      public boolean multipliesWith(FloatMatrix a)
      Checks whether two matrices can be multiplied (that is, number of columns of this must equal number of rows of a.
    • assertMultipliesWith

      public void assertMultipliesWith(FloatMatrix a)
      Throws SizeException unless matrices can be multiplied with one another.
    • sameLength

      public boolean sameLength(FloatMatrix a)
      Checks whether two matrices have the same length.
    • assertSameLength

      public void assertSameLength(FloatMatrix a)
      Throws SizeException unless matrices have the same length.
    • copy

      public FloatMatrix copy(FloatMatrix a)
      Copy FloatMatrix a to this. this a is resized if necessary.
    • dup

      public FloatMatrix dup()
      Returns a duplicate of this matrix. Geometry is the same (including offsets, transpose, etc.), but the buffer is not shared.
    • swapColumns

      public FloatMatrix swapColumns(int i, int j)
      Swap two columns of a matrix.
    • swapRows

      public FloatMatrix swapRows(int i, int j)
      Swap two rows of a matrix.
    • put

      public FloatMatrix put(int rowIndex, int columnIndex, float value)
      Set matrix element
    • get

      public float get(int rowIndex, int columnIndex)
      Retrieve matrix element
    • index

      public int index(int rowIndex, int columnIndex)
      Get index of an element
    • indexRows

      public int indexRows(int i)
      Compute the row index of a linear index.
    • indexColumns

      public int indexColumns(int i)
      Compute the column index of a linear index.
    • get

      public float get(int i)
      Get a matrix element (linear indexing).
    • put

      public FloatMatrix put(int i, float v)
      Set a matrix element (linear indexing).
    • fill

      public FloatMatrix fill(float value)
      Set all elements to a value.
    • getRows

      public int getRows()
      Get number of rows.
    • getColumns

      public int getColumns()
      Get number of columns.
    • getLength

      public int getLength()
      Get total number of elements.
    • isEmpty

      public boolean isEmpty()
      Checks whether the matrix is empty.
    • isSquare

      public boolean isSquare()
      Checks whether the matrix is square.
    • assertSquare

      public void assertSquare()
      Throw SizeException unless matrix is square.
    • isVector

      public boolean isVector()
      Checks whether the matrix is a vector.
    • isRowVector

      public boolean isRowVector()
      Checks whether the matrix is a row vector.
    • isColumnVector

      public boolean isColumnVector()
      Checks whether the matrix is a column vector.
    • diag

      public FloatMatrix diag()
      Returns the diagonal of the matrix.
    • print

      public void print()
      Pretty-print this matrix to System.out.
    • toString

      public String toString()
      Generate string representation of the matrix.
      Overrides:
      toString in class Object
    • toString

      public String toString(String fmt)
      Generate string representation of the matrix, with specified format for the entries. For example, x.toString("%.1f") generates a string representations having only one position after the decimal point.
    • toString

      public String toString(String fmt, String open, String close, String colSep, String rowSep)
      Generate string representation of the matrix, with specified format for the entries, and delimiters.
      Parameters:
      fmt - entry format (passed to String.format())
      open - opening parenthesis
      close - closing parenthesis
      colSep - separator between columns
      rowSep - separator between rows
    • toArray

      public float[] toArray()
      Converts the matrix to a one-dimensional array of floats.
    • toArray2

      public float[][] toArray2()
      Converts the matrix to a two-dimensional array of floats.
    • toIntArray

      public int[] toIntArray()
      Converts the matrix to a one-dimensional array of integers.
    • toIntArray2

      public int[][] toIntArray2()
      Convert the matrix to a two-dimensional array of integers.
    • toBooleanArray

      public boolean[] toBooleanArray()
      Convert the matrix to a one-dimensional array of boolean values.
    • toBooleanArray2

      public boolean[][] toBooleanArray2()
      Convert the matrix to a two-dimensional array of boolean values.
    • toFloat

      public FloatMatrix toFloat()
    • elementsAsList

      public List<Float> elementsAsList()
    • rowsAsList

      public List<FloatMatrix> rowsAsList()
    • columnsAsList

      public List<FloatMatrix> columnsAsList()
    • ensureResultLength

      private void ensureResultLength(FloatMatrix other, FloatMatrix result)
      Ensures that the result vector has the same length as this. If not, resizing result is tried, which fails if result == this or result == other.
    • addi

      public FloatMatrix addi(FloatMatrix other, FloatMatrix result)
      Add two matrices (in-place).
    • addi

      public FloatMatrix addi(float v, FloatMatrix result)
      Add a scalar to a matrix (in-place).
    • subi

      public FloatMatrix subi(FloatMatrix other, FloatMatrix result)
      Subtract two matrices (in-place).
    • subi

      public FloatMatrix subi(float v, FloatMatrix result)
      Subtract a scalar from a matrix (in-place).
    • rsubi

      public FloatMatrix rsubi(FloatMatrix other, FloatMatrix result)
      Subtract two matrices, but subtract first from second matrix, that is, compute result = other - this (in-place).
    • rsubi

      public FloatMatrix rsubi(float a, FloatMatrix result)
      Subtract a matrix from a scalar (in-place).
    • muli

      public FloatMatrix muli(FloatMatrix other, FloatMatrix result)
      Elementwise multiplication (in-place).
    • muli

      public FloatMatrix muli(float v, FloatMatrix result)
      Elementwise multiplication with a scalar (in-place).
    • mmuli

      public FloatMatrix mmuli(FloatMatrix other, FloatMatrix result)
      Matrix-matrix multiplication (in-place).
    • mmuli

      public FloatMatrix mmuli(float v, FloatMatrix result)
      Matrix-matrix multiplication with a scalar (for symmetry, does the same as muli(scalar) (in-place).
    • divi

      public FloatMatrix divi(FloatMatrix other, FloatMatrix result)
      Elementwise division (in-place).
    • divi

      public FloatMatrix divi(float a, FloatMatrix result)
      Elementwise division with a scalar (in-place).
    • rdivi

      public FloatMatrix rdivi(FloatMatrix other, FloatMatrix result)
      Elementwise division, with operands switched. Computes result = other / this (in-place).
    • rdivi

      public FloatMatrix rdivi(float a, FloatMatrix result)
      (Elementwise) division with a scalar, with operands switched. Computes result = a / this (in-place).
    • negi

      public FloatMatrix negi()
      Negate each element (in-place).
    • neg

      public FloatMatrix neg()
      Negate each element.
    • noti

      public FloatMatrix noti()
      Maps zero to 1.0f and all non-zero values to 0.0f (in-place).
    • not

      public FloatMatrix not()
      Maps zero to 1.0f and all non-zero values to 0.0f.
    • truthi

      public FloatMatrix truthi()
      Maps zero to 0.0f and all non-zero values to 1.0f (in-place).
    • truth

      public FloatMatrix truth()
      Maps zero to 0.0f and all non-zero values to 1.0f.
    • isNaNi

      public FloatMatrix isNaNi()
    • isNaN

      public FloatMatrix isNaN()
    • isInfinitei

      public FloatMatrix isInfinitei()
    • isInfinite

      public FloatMatrix isInfinite()
    • isLowerTriangular

      public boolean isLowerTriangular()
      Checks whether all entries (i, j) with i >= j are zero.
    • isUpperTriangular

      public boolean isUpperTriangular()
      Checks whether all entries (i, j) with i <= j are zero.
    • selecti

      public FloatMatrix selecti(FloatMatrix where)
    • select

      public FloatMatrix select(FloatMatrix where)
    • rankOneUpdate

      public FloatMatrix rankOneUpdate(float alpha, FloatMatrix x, FloatMatrix y)
      Computes a rank-1-update A = A + alpha * x * y'.
    • rankOneUpdate

      public FloatMatrix rankOneUpdate(float alpha, FloatMatrix x)
      Computes a rank-1-update A = A + alpha * x * x'.
    • rankOneUpdate

      public FloatMatrix rankOneUpdate(FloatMatrix x)
      Computes a rank-1-update A = A + x * x'.
    • rankOneUpdate

      public FloatMatrix rankOneUpdate(FloatMatrix x, FloatMatrix y)
      Computes a rank-1-update A = A + x * y'.
    • min

      public float min()
      Returns the minimal element of the matrix.
    • argmin

      public int argmin()
      Returns the linear index of the minimal element. If there are more than one elements with this value, the first one is returned.
    • mini

      public FloatMatrix mini(FloatMatrix other, FloatMatrix result)
      Computes the minimum between two matrices. Returns the smaller of the corresponding elements in the matrix (in-place).
    • mini

      public FloatMatrix mini(FloatMatrix other)
      Computes the minimum between two matrices. Returns the smaller of the corresponding elements in the matrix (in-place on this).
    • min

      public FloatMatrix min(FloatMatrix other)
      Computes the minimum between two matrices. Returns the smaller of the corresponding elements in the matrix (in-place on this).
    • mini

      public FloatMatrix mini(float v, FloatMatrix result)
    • mini

      public FloatMatrix mini(float v)
    • min

      public FloatMatrix min(float v)
    • max

      public float max()
      Returns the maximal element of the matrix.
    • argmax

      public int argmax()
      Returns the linear index of the maximal element of the matrix. If there are more than one elements with this value, the first one is returned.
    • maxi

      public FloatMatrix maxi(FloatMatrix other, FloatMatrix result)
      Computes the maximum between two matrices. Returns the larger of the corresponding elements in the matrix (in-place).
    • maxi

      public FloatMatrix maxi(FloatMatrix other)
      Computes the maximum between two matrices. Returns the smaller of the corresponding elements in the matrix (in-place on this).
    • max

      public FloatMatrix max(FloatMatrix other)
      Computes the maximum between two matrices. Returns the larger of the corresponding elements in the matrix (in-place on this).
    • maxi

      public FloatMatrix maxi(float v, FloatMatrix result)
    • maxi

      public FloatMatrix maxi(float v)
    • max

      public FloatMatrix max(float v)
    • sum

      public float sum()
      Computes the sum of all elements of the matrix.
    • prod

      public float prod()
      Computes the product of all elements of the matrix
    • mean

      public float mean()
      Computes the mean value of all elements in the matrix, that is, x.sum() / x.length.
    • cumulativeSumi

      public FloatMatrix cumulativeSumi()
      Computes the cumulative sum, that is, the sum of all elements of the matrix up to a given index in linear addressing (in-place).
    • cumulativeSum

      public FloatMatrix cumulativeSum()
      Computes the cumulative sum, that is, the sum of all elements of the matrix up to a given index in linear addressing.
    • dot

      public float dot(FloatMatrix other)
      The scalar product of this with other.
    • project

      public float project(FloatMatrix other)
      Computes the projection coefficient of other on this. The returned scalar times this is the orthogonal projection of other on this.
    • norm2

      public float norm2()
      The Euclidean norm of the matrix as vector, also the Frobenius norm of the matrix.
    • normmax

      public float normmax()
      The maximum norm of the matrix (maximal absolute value of the elements).
    • norm1

      public float norm1()
      The 1-norm of the matrix as vector (sum of absolute values of elements).
    • squaredDistance

      public float squaredDistance(FloatMatrix other)
      Returns the squared (Euclidean) distance.
    • distance2

      public float distance2(FloatMatrix other)
      Returns the (euclidean) distance.
    • distance1

      public float distance1(FloatMatrix other)
      Returns the (1-norm) distance.
    • sort

      public FloatMatrix sort()
      Return a new matrix with all elements sorted.
    • sorti

      public FloatMatrix sorti()
      Sort elements in-place.
    • sortingPermutation

      public int[] sortingPermutation()
      Get the sorting permutation.
      Returns:
      an int[] array such that which indexes the elements in sorted order.
    • sortColumnsi

      public FloatMatrix sortColumnsi()
      Sort columns (in-place).
    • sortColumns

      public FloatMatrix sortColumns()
      Sort columns.
    • columnSortingPermutations

      public int[][] columnSortingPermutations()
      Return matrix of indices which sort all columns.
    • sortRowsi

      public FloatMatrix sortRowsi()
      Sort rows (in-place).
    • sortRows

      public FloatMatrix sortRows()
      Sort rows.
    • rowSortingPermutations

      public int[][] rowSortingPermutations()
      Return matrix of indices which sort all columns.
    • columnSums

      public FloatMatrix columnSums()
      Return a vector containing the sums of the columns (having number of columns many entries)
    • columnMeans

      public FloatMatrix columnMeans()
      Return a vector containing the means of all columns.
    • rowSums

      public FloatMatrix rowSums()
      Return a vector containing the sum of the rows.
    • rowMeans

      public FloatMatrix rowMeans()
      Return a vector containing the means of the rows.
    • getColumn

      public FloatMatrix getColumn(int c)
      Get a copy of a column.
    • getColumn

      public FloatMatrix getColumn(int c, FloatMatrix result)
      Copy a column to the given vector.
    • putColumn

      public void putColumn(int c, FloatMatrix v)
      Copy a column back into the matrix.
    • getRow

      public FloatMatrix getRow(int r)
      Get a copy of a row.
    • getRow

      public FloatMatrix getRow(int r, FloatMatrix result)
      Copy a row to a given vector.
    • putRow

      public void putRow(int r, FloatMatrix v)
      Copy a row back into the matrix.
    • columnMins

      public FloatMatrix columnMins()
      Return column-wise minimums.
    • columnArgmins

      public int[] columnArgmins()
      Return index of minimal element per column.
    • columnMaxs

      public FloatMatrix columnMaxs()
      Return column-wise maximums.
    • columnArgmaxs

      public int[] columnArgmaxs()
      Return index of minimal element per column.
    • rowMins

      public FloatMatrix rowMins()
      Return row-wise minimums.
    • rowArgmins

      public int[] rowArgmins()
      Return index of minimal element per row.
    • rowMaxs

      public FloatMatrix rowMaxs()
      Return row-wise maximums.
    • rowArgmaxs

      public int[] rowArgmaxs()
      Return index of maximum element per row.
    • addiRowVector

      public FloatMatrix addiRowVector(FloatMatrix x)
      Add a row vector to all rows of the matrix (in place).
    • addRowVector

      public FloatMatrix addRowVector(FloatMatrix x)
      Add a row to all rows of the matrix.
    • addiColumnVector

      public FloatMatrix addiColumnVector(FloatMatrix x)
      Add a vector to all columns of the matrix (in-place).
    • addColumnVector

      public FloatMatrix addColumnVector(FloatMatrix x)
      Add a vector to all columns of the matrix.
    • subiRowVector

      public FloatMatrix subiRowVector(FloatMatrix x)
      Subtract a row vector from all rows of the matrix (in-place).
    • subRowVector

      public FloatMatrix subRowVector(FloatMatrix x)
      Subtract a row vector from all rows of the matrix.
    • subiColumnVector

      public FloatMatrix subiColumnVector(FloatMatrix x)
      Subtract a column vector from all columns of the matrix (in-place).
    • subColumnVector

      public FloatMatrix subColumnVector(FloatMatrix x)
      Subtract a vector from all columns of the matrix.
    • mulRow

      public FloatMatrix mulRow(int r, float scale)
      Multiply a row by a scalar.
    • mulColumn

      public FloatMatrix mulColumn(int c, float scale)
      Multiply a column by a scalar.
    • muliColumnVector

      public FloatMatrix muliColumnVector(FloatMatrix x)
      Multiply all columns with a column vector (in-place).
    • mulColumnVector

      public FloatMatrix mulColumnVector(FloatMatrix x)
      Multiply all columns with a column vector.
    • muliRowVector

      public FloatMatrix muliRowVector(FloatMatrix x)
      Multiply all rows with a row vector (in-place).
    • mulRowVector

      public FloatMatrix mulRowVector(FloatMatrix x)
      Multiply all rows with a row vector.
    • diviRowVector

      public FloatMatrix diviRowVector(FloatMatrix x)
    • divRowVector

      public FloatMatrix divRowVector(FloatMatrix x)
    • diviColumnVector

      public FloatMatrix diviColumnVector(FloatMatrix x)
    • divColumnVector

      public FloatMatrix divColumnVector(FloatMatrix x)
    • out

      public void out(DataOutputStream dos) throws IOException
      Writes out this matrix to the given data stream.
      Parameters:
      dos - the data output stream to write to.
      Throws:
      IOException
    • in

      public void in(DataInputStream dis) throws IOException
      Reads in a matrix from the given data stream. Note that the old data of this matrix will be discarded.
      Parameters:
      dis - the data input stream to read from.
      Throws:
      IOException
    • save

      public void save(String filename) throws IOException
      Saves this matrix to the specified file.
      Parameters:
      filename - the file to write the matrix in.
      Throws:
      IOException - thrown on errors while writing the matrix to the file
    • load

      public void load(String filename) throws IOException
      Loads a matrix from a file into this matrix. Note that the old data of this matrix will be discarded.
      Parameters:
      filename - the file to read the matrix from
      Throws:
      IOException - thrown on errors while reading the matrix
    • loadAsciiFile

      public static FloatMatrix loadAsciiFile(String filename) throws IOException
      Throws:
      IOException
    • loadCSVFile

      public static FloatMatrix loadCSVFile(String filename) throws IOException
      Throws:
      IOException
    • addi

      public FloatMatrix addi(FloatMatrix other)
      Add a matrix (in place).
    • add

      public FloatMatrix add(FloatMatrix other)
      Add a matrix.
    • addi

      public FloatMatrix addi(float v)
      Add a scalar (in place).
    • add

      public FloatMatrix add(float v)
      Add a scalar.
    • subi

      public FloatMatrix subi(FloatMatrix other)
      Subtract a matrix (in place).
    • sub

      public FloatMatrix sub(FloatMatrix other)
      Subtract a matrix.
    • subi

      public FloatMatrix subi(float v)
      Subtract a scalar (in place).
    • sub

      public FloatMatrix sub(float v)
      Subtract a scalar.
    • rsubi

      public FloatMatrix rsubi(FloatMatrix other)
      (right-)subtract a matrix (in place).
    • rsub

      public FloatMatrix rsub(FloatMatrix other)
      (right-)subtract a matrix.
    • rsubi

      public FloatMatrix rsubi(float v)
      (right-)subtract a scalar (in place).
    • rsub

      public FloatMatrix rsub(float v)
      (right-)subtract a scalar.
    • divi

      public FloatMatrix divi(FloatMatrix other)
      Elementwise divide by a matrix (in place).
    • div

      public FloatMatrix div(FloatMatrix other)
      Elementwise divide by a matrix.
    • divi

      public FloatMatrix divi(float v)
      Elementwise divide by a scalar (in place).
    • div

      public FloatMatrix div(float v)
      Elementwise divide by a scalar.
    • rdivi

      public FloatMatrix rdivi(FloatMatrix other)
      (right-)elementwise divide by a matrix (in place).
    • rdiv

      public FloatMatrix rdiv(FloatMatrix other)
      (right-)elementwise divide by a matrix.
    • rdivi

      public FloatMatrix rdivi(float v)
      (right-)elementwise divide by a scalar (in place).
    • rdiv

      public FloatMatrix rdiv(float v)
      (right-)elementwise divide by a scalar.
    • muli

      public FloatMatrix muli(FloatMatrix other)
      Elementwise multiply by a matrix (in place).
    • mul

      public FloatMatrix mul(FloatMatrix other)
      Elementwise multiply by a matrix.
    • muli

      public FloatMatrix muli(float v)
      Elementwise multiply by a scalar (in place).
    • mul

      public FloatMatrix mul(float v)
      Elementwise multiply by a scalar.
    • mmuli

      public FloatMatrix mmuli(FloatMatrix other)
      Matrix-multiply by a matrix (in place).
    • mmul

      public FloatMatrix mmul(FloatMatrix other)
      Matrix-multiply by a matrix.
    • mmuli

      public FloatMatrix mmuli(float v)
      Matrix-multiply by a scalar (in place).
    • mmul

      public FloatMatrix mmul(float v)
      Matrix-multiply by a scalar.
    • lti

      public FloatMatrix lti(FloatMatrix other, FloatMatrix result)
      Test for "less than" (in-place).
    • lti

      public FloatMatrix lti(FloatMatrix other)
      Test for "less than" (in-place).
    • lt

      public FloatMatrix lt(FloatMatrix other)
      Test for "less than".
    • lti

      public FloatMatrix lti(float value, FloatMatrix result)
      Test for "less than" against a scalar (in-place).
    • lti

      public FloatMatrix lti(float value)
      Test for "less than" against a scalar (in-place).
    • lt

      public FloatMatrix lt(float value)
      test for "less than" against a scalar.
    • gti

      public FloatMatrix gti(FloatMatrix other, FloatMatrix result)
      Test for "greater than" (in-place).
    • gti

      public FloatMatrix gti(FloatMatrix other)
      Test for "greater than" (in-place).
    • gt

      public FloatMatrix gt(FloatMatrix other)
      Test for "greater than".
    • gti

      public FloatMatrix gti(float value, FloatMatrix result)
      Test for "greater than" against a scalar (in-place).
    • gti

      public FloatMatrix gti(float value)
      Test for "greater than" against a scalar (in-place).
    • gt

      public FloatMatrix gt(float value)
      test for "greater than" against a scalar.
    • lei

      public FloatMatrix lei(FloatMatrix other, FloatMatrix result)
      Test for "less than or equal" (in-place).
    • lei

      public FloatMatrix lei(FloatMatrix other)
      Test for "less than or equal" (in-place).
    • le

      public FloatMatrix le(FloatMatrix other)
      Test for "less than or equal".
    • lei

      public FloatMatrix lei(float value, FloatMatrix result)
      Test for "less than or equal" against a scalar (in-place).
    • lei

      public FloatMatrix lei(float value)
      Test for "less than or equal" against a scalar (in-place).
    • le

      public FloatMatrix le(float value)
      test for "less than or equal" against a scalar.
    • gei

      public FloatMatrix gei(FloatMatrix other, FloatMatrix result)
      Test for "greater than or equal" (in-place).
    • gei

      public FloatMatrix gei(FloatMatrix other)
      Test for "greater than or equal" (in-place).
    • ge

      public FloatMatrix ge(FloatMatrix other)
      Test for "greater than or equal".
    • gei

      public FloatMatrix gei(float value, FloatMatrix result)
      Test for "greater than or equal" against a scalar (in-place).
    • gei

      public FloatMatrix gei(float value)
      Test for "greater than or equal" against a scalar (in-place).
    • ge

      public FloatMatrix ge(float value)
      test for "greater than or equal" against a scalar.
    • eqi

      public FloatMatrix eqi(FloatMatrix other, FloatMatrix result)
      Test for equality (in-place).
    • eqi

      public FloatMatrix eqi(FloatMatrix other)
      Test for equality (in-place).
    • eq

      public FloatMatrix eq(FloatMatrix other)
      Test for equality.
    • eqi

      public FloatMatrix eqi(float value, FloatMatrix result)
      Test for equality against a scalar (in-place).
    • eqi

      public FloatMatrix eqi(float value)
      Test for equality against a scalar (in-place).
    • eq

      public FloatMatrix eq(float value)
      test for equality against a scalar.
    • nei

      public FloatMatrix nei(FloatMatrix other, FloatMatrix result)
      Test for inequality (in-place).
    • nei

      public FloatMatrix nei(FloatMatrix other)
      Test for inequality (in-place).
    • ne

      public FloatMatrix ne(FloatMatrix other)
      Test for inequality.
    • nei

      public FloatMatrix nei(float value, FloatMatrix result)
      Test for inequality against a scalar (in-place).
    • nei

      public FloatMatrix nei(float value)
      Test for inequality against a scalar (in-place).
    • ne

      public FloatMatrix ne(float value)
      test for inequality against a scalar.
    • andi

      public FloatMatrix andi(FloatMatrix other, FloatMatrix result)
      Compute elementwise logical and (in-place).
    • andi

      public FloatMatrix andi(FloatMatrix other)
      Compute elementwise logical and (in-place).
    • and

      public FloatMatrix and(FloatMatrix other)
      Compute elementwise logical and.
    • andi

      public FloatMatrix andi(float value, FloatMatrix result)
      Compute elementwise logical and against a scalar (in-place).
    • andi

      public FloatMatrix andi(float value)
      Compute elementwise logical and against a scalar (in-place).
    • and

      public FloatMatrix and(float value)
      Compute elementwise logical and against a scalar.
    • ori

      public FloatMatrix ori(FloatMatrix other, FloatMatrix result)
      Compute elementwise logical or (in-place).
    • ori

      public FloatMatrix ori(FloatMatrix other)
      Compute elementwise logical or (in-place).
    • or

      public FloatMatrix or(FloatMatrix other)
      Compute elementwise logical or.
    • ori

      public FloatMatrix ori(float value, FloatMatrix result)
      Compute elementwise logical or against a scalar (in-place).
    • ori

      public FloatMatrix ori(float value)
      Compute elementwise logical or against a scalar (in-place).
    • or

      public FloatMatrix or(float value)
      Compute elementwise logical or against a scalar.
    • xori

      public FloatMatrix xori(FloatMatrix other, FloatMatrix result)
      Compute elementwise logical xor (in-place).
    • xori

      public FloatMatrix xori(FloatMatrix other)
      Compute elementwise logical xor (in-place).
    • xor

      public FloatMatrix xor(FloatMatrix other)
      Compute elementwise logical xor.
    • xori

      public FloatMatrix xori(float value, FloatMatrix result)
      Compute elementwise logical xor against a scalar (in-place).
    • xori

      public FloatMatrix xori(float value)
      Compute elementwise logical xor against a scalar (in-place).
    • xor

      public FloatMatrix xor(float value)
      Compute elementwise logical xor against a scalar.
    • toComplex

      public ComplexFloatMatrix toComplex()