Packageflare.util.math
Classpublic class SparseMatrix
ImplementsIMatrix

A matrix of numbers implemented using a hashtable of values.



Public Properties
 PropertyDefined by
  cols : int
[read-only] The number of columns.
SparseMatrix
  nnz : int
[read-only] The number of non-zero values.
SparseMatrix
  rows : int
[read-only] The number of rows.
SparseMatrix
  sum : Number
[read-only] The sum of all the entries in this matrix.
SparseMatrix
  sumsq : Number
[read-only] The sum of squares of all the entries in this matrix.
SparseMatrix
Public Methods
 MethodDefined by
  
SparseMatrix(rows:int, cols:int)
Creates a new SparseMatrix with the given size.
SparseMatrix
  
Creates a copy of this matrix.
SparseMatrix
  
get(i:int, j:int):Number
SparseMatrix
  
init(rows:int, cols:int):void
Initializes the matrix to desired dimensions.
SparseMatrix
  
like(rows:int, cols:int):IMatrix
Creates a new matrix of the same type.
SparseMatrix
  
Multiplies this matrix by another.
SparseMatrix
  
scale(s:Number):void
Multiplies all values in this matrix by the input scalar.
SparseMatrix
  
set(i:int, j:int, v:Number):Number
SparseMatrix
  
visit(f:Function):void
Visit all values in the matrix.
SparseMatrix
  
visitNonZero(f:Function):void
Visit all non-zero values in the matrix.
SparseMatrix
Property detail
colsproperty
cols:int  [read-only]

The number of columns.

Implementation
    public function get cols():int
nnzproperty 
nnz:int  [read-only]

The number of non-zero values.

Implementation
    public function get nnz():int
rowsproperty 
rows:int  [read-only]

The number of rows.

Implementation
    public function get rows():int
sumproperty 
sum:Number  [read-only]

The sum of all the entries in this matrix.

Implementation
    public function get sum():Number
sumsqproperty 
sumsq:Number  [read-only]

The sum of squares of all the entries in this matrix.

Implementation
    public function get sumsq():Number
Constructor detail
SparseMatrix()constructor
public function SparseMatrix(rows:int, cols:int)

Creates a new SparseMatrix with the given size.

Parameters
rows:int — the number of rows
 
cols:int — the number of columns
Method detail
clone()method
public function clone():IMatrix

Creates a copy of this matrix.

Returns
IMatrix
get()method 
public function get(i:int, j:int):Number

Parameters
i:int
 
j:int

Returns
Number
init()method 
public function init(rows:int, cols:int):void

Initializes the matrix to desired dimensions. This method also resets all values in the matrix to zero.

Parameters
rows:int — the number of rows in this matrix
 
cols:int — the number of columns in this matrix
like()method 
public function like(rows:int, cols:int):IMatrix

Creates a new matrix of the same type.

Parameters
rows:int — the number of rows in the new matrix
 
cols:int — the number of columns in the new matrix

Returns
IMatrix — a new matrix
multiply()method 
public function multiply(b:IMatrix):IMatrix

Multiplies this matrix by another. The number of rows in this matrix must match the number of columns in the input matrix.

Parameters
b:IMatrix — the matrix to multiply by.

Returns
IMatrix — a new matrix that is the product of this matrix with the input matrix. The new matrix will be of the same type as this one.
scale()method 
public function scale(s:Number):void

Multiplies all values in this matrix by the input scalar.

Parameters
s:Number — the scalar to multiply by.
set()method 
public function set(i:int, j:int, v:Number):Number

Parameters
i:int
 
j:int
 
v:Number

Returns
Number
visit()method 
public function visit(f:Function):void

Visit all values in the matrix. The input function is expected to take three arguments--the row index, the column index, and the cell value--and return a number which then becomes the new value for the cell.

Parameters
f:Function — the function to invoke for each value
visitNonZero()method 
public function visitNonZero(f:Function):void

Visit all non-zero values in the matrix. The input function is expected to take three arguments--the row index, the column index, and the cell value--and return a number which then becomes the new value for the cell.

Parameters
f:Function — the function to invoke for each non-zero value