Logo Search packages:      
Sourcecode: jblas version File versions  Download package

org::jblas::la::FloatMatrix Class Reference

List of all members.


Detailed Description

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.

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 row by row.
FloatMatrix(new float[][] {{value1, value2, ...}, ...}Inner arrays are columns.
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.

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

MethodDescription
FloatMatrix(m)Constructs a column vector.
FloatMatrix(new float[] {value1, value2, ...})Constructs a column vector.
FloatMatrix.zeros(m) Initial values set to 1.0f.
FloatMatrix.ones(m) Initial values set to 0.0f.
FloatMatrix.rand(m) Values drawn at random between 0.0f and 1.0f.
FloatMatrix.randn(m) Values drawn from normal distribution.

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.

Element Access, Copying and Duplication

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

x.Method<th>Description
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 columns i and j.

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

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.

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).

Size and Shape

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

x.Method<th>Description
x.rows<td>Number of rows.
x.columns<td>Number of columns.
x.length<td>Total 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.

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 which are directly garbage collected again is reduced.

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()

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

Method Description
x.addRowVector<td>adds a vector to each row (addiRowVector works in-place)
x.addColumnVector<td>adds a vector to each column
x.subRowVector<td>subtracts a vector from each row
x.subColumnVector<td>subtracts a vector from each column
x.mulRow<td>Multiplies a row by a scalar
x.mulColumn<td>multiplies a row by a column

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)

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()

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 largest 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

Author:
Mikio Braun, Johannes Schaback

Definition at line 274 of file FloatMatrix.java.


Public Member Functions

FloatMatrix add (float v)
FloatMatrix add (FloatMatrix other)
FloatMatrix addColumnVector (FloatMatrix x)
FloatMatrix addi (float v)
FloatMatrix addi (FloatMatrix other)
FloatMatrix addi (float v, FloatMatrix result)
FloatMatrix addi (FloatMatrix other, FloatMatrix result)
FloatMatrix addiColumnVector (FloatMatrix x)
FloatMatrix addiRowVector (FloatMatrix x)
FloatMatrix addRowVector (FloatMatrix x)
FloatMatrix and (float value)
FloatMatrix and (FloatMatrix other)
FloatMatrix andi (float value)
FloatMatrix andi (float value, FloatMatrix result)
FloatMatrix andi (FloatMatrix other)
FloatMatrix andi (FloatMatrix other, FloatMatrix result)
int argmax ()
int argmin ()
void assertMultipliesWith (FloatMatrix a)
void assertSameLength (FloatMatrix a)
void assertSameSize (FloatMatrix a)
void assertSquare ()
void checkColumns (int c)
void checkLength (int l)
void checkRows (int r)
int[] columnArgmaxs ()
int[] columnArgmins ()
FloatMatrix columnMaxs ()
FloatMatrix columnMeans ()
FloatMatrix columnMins ()
int[][] columnSortingPermutations ()
FloatMatrix columnSums ()
FloatMatrix copy (FloatMatrix a)
FloatMatrix cumulativeSum ()
FloatMatrix cumulativeSumi ()
FloatMatrix diag ()
FloatMatrix div (float v)
FloatMatrix div (FloatMatrix other)
FloatMatrix divi (float v)
FloatMatrix divi (FloatMatrix other)
FloatMatrix divi (float a, FloatMatrix result)
FloatMatrix divi (FloatMatrix other, FloatMatrix result)
float dot (FloatMatrix other)
FloatMatrix dup ()
FloatMatrix eq (float value)
FloatMatrix eq (FloatMatrix other)
FloatMatrix eqi (float value)
FloatMatrix eqi (float value, FloatMatrix result)
FloatMatrix eqi (FloatMatrix other)
FloatMatrix eqi (FloatMatrix other, FloatMatrix result)
boolean equals (Object o)
FloatMatrix fill (float value)
int[] findIndices ()
 FloatMatrix (float[][] data)
 FloatMatrix (String filename) throws IOException
 FloatMatrix (float[] newData)
 FloatMatrix (int len)
 FloatMatrix ()
 FloatMatrix (int newRows, int newColumns)
 FloatMatrix (int newRows, int newColumns, float...newData)
FloatMatrix ge (float value)
FloatMatrix ge (FloatMatrix other)
FloatMatrix gei (float value)
FloatMatrix gei (float value, FloatMatrix result)
FloatMatrix gei (FloatMatrix other)
FloatMatrix gei (FloatMatrix other, FloatMatrix result)
float get (int i)
float get (int rowIndex, int columnIndex)
FloatMatrix get (FloatMatrix rindices, FloatMatrix cindices)
FloatMatrix get (FloatMatrix indices, int c)
FloatMatrix get (int r, FloatMatrix indices)
FloatMatrix get (FloatMatrix indices)
FloatMatrix get (Range rs, Range cs)
FloatMatrix get (int[] rindices, int[] cindices)
FloatMatrix get (int[] indices, int c)
FloatMatrix get (int r, int[] indices)
FloatMatrix get (int[] indices)
FloatMatrix getColumn (int c, FloatMatrix result)
FloatMatrix getColumn (int c)
FloatMatrix getColumnRange (int r, int a, int b)
int getColumns ()
FloatMatrix getColumns (FloatMatrix cindices)
FloatMatrix getColumns (int[] cindices)
int getLength ()
FloatMatrix getRange (int ra, int rb, int ca, int cb)
FloatMatrix getRange (int a, int b)
FloatMatrix getRow (int r, FloatMatrix result)
FloatMatrix getRow (int r)
FloatMatrix getRowRange (int a, int b, int c)
int getRows ()
FloatMatrix getRows (FloatMatrix rindices)
FloatMatrix getRows (int[] rindices)
FloatMatrix gt (float value)
FloatMatrix gt (FloatMatrix other)
FloatMatrix gti (float value)
FloatMatrix gti (float value, FloatMatrix result)
FloatMatrix gti (FloatMatrix other)
FloatMatrix gti (FloatMatrix other, FloatMatrix result)
void in (DataInputStream dis) throws IOException
int index (int rowIndex, int columnIndex)
int indexColumns (int i)
int indexRows (int i)
boolean isColumnVector ()
boolean isEmpty ()
boolean isRowVector ()
boolean isScalar ()
boolean isSquare ()
boolean isVector ()
FloatMatrix le (float value)
FloatMatrix le (FloatMatrix other)
FloatMatrix lei (float value)
FloatMatrix lei (float value, FloatMatrix result)
FloatMatrix lei (FloatMatrix other)
FloatMatrix lei (FloatMatrix other, FloatMatrix result)
void load (String filename) throws IOException
FloatMatrix lt (float value)
FloatMatrix lt (FloatMatrix other)
FloatMatrix lti (float value)
FloatMatrix lti (float value, FloatMatrix result)
FloatMatrix lti (FloatMatrix other)
FloatMatrix lti (FloatMatrix other, FloatMatrix result)
FloatMatrix max (float v)
FloatMatrix max (FloatMatrix other)
float max ()
FloatMatrix maxi (float v)
FloatMatrix maxi (float v, FloatMatrix result)
FloatMatrix maxi (FloatMatrix other)
FloatMatrix maxi (FloatMatrix other, FloatMatrix result)
float mean ()
FloatMatrix min (float v)
FloatMatrix min (FloatMatrix other)
float min ()
FloatMatrix mini (float v)
FloatMatrix mini (float v, FloatMatrix result)
FloatMatrix mini (FloatMatrix other)
FloatMatrix mini (FloatMatrix other, FloatMatrix result)
FloatMatrix mmul (float v)
FloatMatrix mmul (FloatMatrix other)
FloatMatrix mmuli (float v)
FloatMatrix mmuli (FloatMatrix other)
FloatMatrix mmuli (float v, FloatMatrix result)
FloatMatrix mmuli (FloatMatrix other, FloatMatrix result)
FloatMatrix mul (float v)
FloatMatrix mul (FloatMatrix other)
FloatMatrix mulColumn (int c, float scale)
FloatMatrix mulColumnVector (FloatMatrix x)
FloatMatrix muli (float v)
FloatMatrix muli (FloatMatrix other)
FloatMatrix muli (float v, FloatMatrix result)
FloatMatrix muli (FloatMatrix other, FloatMatrix result)
FloatMatrix muliColumnVector (FloatMatrix x)
FloatMatrix muliRowVector (FloatMatrix x)
FloatMatrix mulRow (int r, float scale)
FloatMatrix mulRowVector (FloatMatrix x)
boolean multipliesWith (FloatMatrix a)
FloatMatrix ne (float value)
FloatMatrix ne (FloatMatrix other)
FloatMatrix neg ()
FloatMatrix negi ()
FloatMatrix nei (float value)
FloatMatrix nei (float value, FloatMatrix result)
FloatMatrix nei (FloatMatrix other)
FloatMatrix nei (FloatMatrix other, FloatMatrix result)
float norm1 ()
float norm2 ()
float normmax ()
FloatMatrix not ()
FloatMatrix noti ()
FloatMatrix or (float value)
FloatMatrix or (FloatMatrix other)
FloatMatrix ori (float value)
FloatMatrix ori (float value, FloatMatrix result)
FloatMatrix ori (FloatMatrix other)
FloatMatrix ori (FloatMatrix other, FloatMatrix result)
void out (DataOutputStream dos) throws IOException
void print ()
FloatMatrix put (int i, float v)
FloatMatrix put (int rowIndex, int columnIndex, float value)
FloatMatrix put (FloatMatrix rindices, FloatMatrix cindices, float v)
FloatMatrix put (FloatMatrix indices, int c, float v)
FloatMatrix put (int r, FloatMatrix indices, float v)
FloatMatrix put (FloatMatrix indices, float v)
FloatMatrix put (FloatMatrix rindices, FloatMatrix cindices, FloatMatrix v)
FloatMatrix put (FloatMatrix indices, int c, FloatMatrix v)
FloatMatrix put (int r, FloatMatrix indices, FloatMatrix v)
FloatMatrix put (FloatMatrix indices, FloatMatrix v)
FloatMatrix put (int[] rindices, int[] cindices, float v)
FloatMatrix put (int[] indices, int c, float v)
FloatMatrix put (int r, int[] indices, float v)
FloatMatrix put (int[] indices, float v)
FloatMatrix put (Range rs, Range cs, FloatMatrix x)
FloatMatrix put (int[] rindices, int[] cindices, FloatMatrix x)
FloatMatrix put (int[] indices, int c, FloatMatrix x)
FloatMatrix put (int r, int[] indices, FloatMatrix x)
FloatMatrix put (int[] indices, FloatMatrix x)
void putColumn (int c, FloatMatrix v)
void putRow (int r, FloatMatrix v)
FloatMatrix rankOneUpdate (FloatMatrix x, FloatMatrix y)
FloatMatrix rankOneUpdate (FloatMatrix x)
FloatMatrix rankOneUpdate (float alpha, FloatMatrix x)
FloatMatrix rankOneUpdate (float alpha, FloatMatrix x, FloatMatrix y)
FloatMatrix rdiv (float v)
FloatMatrix rdiv (FloatMatrix other)
FloatMatrix rdivi (float v)
FloatMatrix rdivi (FloatMatrix other)
FloatMatrix rdivi (float a, FloatMatrix result)
FloatMatrix rdivi (FloatMatrix other, FloatMatrix result)
FloatMatrix repmat (int rowMult, int columnMult)
FloatMatrix reshape (int newRows, int newColumns)
void resize (int newRows, int newColumns)
int[] rowArgmaxs ()
int[] rowArgmins ()
FloatMatrix rowMaxs ()
FloatMatrix rowMeans ()
FloatMatrix rowMins ()
int[][] rowSortingPermutations ()
FloatMatrix rowSums ()
FloatMatrix rsub (float v)
FloatMatrix rsub (FloatMatrix other)
FloatMatrix rsubi (float v)
FloatMatrix rsubi (FloatMatrix other)
FloatMatrix rsubi (float a, FloatMatrix result)
FloatMatrix rsubi (FloatMatrix other, FloatMatrix result)
boolean sameLength (FloatMatrix a)
boolean sameSize (FloatMatrix a)
void save (String filename) throws IOException
float scalar ()
FloatMatrix sort ()
FloatMatrix sortColumns ()
FloatMatrix sortColumnsi ()
FloatMatrix sorti ()
int[] sortingPermutation ()
FloatMatrix sortRows ()
FloatMatrix sortRowsi ()
FloatMatrix sub (float v)
FloatMatrix sub (FloatMatrix other)
FloatMatrix subColumnVector (FloatMatrix x)
FloatMatrix subi (float v)
FloatMatrix subi (FloatMatrix other)
FloatMatrix subi (float v, FloatMatrix result)
FloatMatrix subi (FloatMatrix other, FloatMatrix result)
FloatMatrix subiColumnVector (FloatMatrix x)
FloatMatrix subiRowVector (FloatMatrix x)
FloatMatrix subRowVector (FloatMatrix x)
float sum ()
FloatMatrix swapColumns (int i, int j)
FloatMatrix swapRows (int i, int j)
float[] toArray ()
float[][] toArray2 ()
boolean[] toBooleanArray ()
boolean[][] toBooleanArray2 ()
FloatMatrix toFloatMatrix ()
int[] toIntArray ()
int[][] toIntArray2 ()
String toString (String fmt)
String toString ()
FloatMatrix transpose ()
FloatMatrix truth ()
FloatMatrix truthi ()
FloatMatrix xor (float value)
FloatMatrix xor (FloatMatrix other)
FloatMatrix xori (float value)
FloatMatrix xori (float value, FloatMatrix result)
FloatMatrix xori (FloatMatrix other)
FloatMatrix xori (FloatMatrix other, FloatMatrix result)

Static Public Member Functions

static FloatMatrix concatHorizontally (FloatMatrix A, FloatMatrix B)
static FloatMatrix concatVertically (FloatMatrix A, FloatMatrix B)
static FloatMatrix diag (FloatMatrix x)
static FloatMatrix eye (int n)
static FloatMatrix loadAsciiFile (String filename) throws IOException
static FloatMatrix ones (int length)
static FloatMatrix ones (int rows, int columns)
static FloatMatrix rand (int len)
static FloatMatrix rand (int rows, int columns)
static FloatMatrix randn (int len)
static FloatMatrix randn (int rows, int columns)
static FloatMatrix scalar (float s)
static FloatMatrix zeros (int length)
static FloatMatrix zeros (int rows, int columns)

Public Attributes

int columns
float[] data = null
int length
int rows

Static Public Attributes

static final FloatMatrix EMPTY = new FloatMatrix()

Private Member Functions

void ensureResultLength (FloatMatrix other, FloatMatrix result)

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index