Parallel Colt 0.7.2

cern.colt.matrix.tfcomplex
Class FComplexMatrix1D

java.lang.Object
  extended by cern.colt.PersistentObject
      extended by cern.colt.matrix.AbstractMatrix
          extended by cern.colt.matrix.AbstractMatrix1D
              extended by cern.colt.matrix.tfcomplex.FComplexMatrix1D
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
DenseFComplexMatrix1D, SparseFComplexMatrix1D

public abstract class FComplexMatrix1D
extends AbstractMatrix1D

Abstract base class for 1-d matrices (aka vectors) holding complex elements. A matrix has a number of cells (its size), which are assigned upon instance construction. Elements are accessed via zero based indexes. Legal indexes are of the form [0..size()-1]. Any attempt to access an element at a coordinate index<0 || index>=size() will throw an IndexOutOfBoundsException.

Author:
Piotr Wendykier (piotr.wendykier@gmail.com)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class cern.colt.PersistentObject
serialVersionUID
 
Method Summary
 float[] aggregate(FComplexFComplexFComplexFunction aggr, FComplexFComplexFunction f)
          Applies a function to each cell and aggregates the results.
 float[] aggregate(FComplexMatrix1D other, FComplexFComplexFComplexFunction aggr, FComplexFComplexFComplexFunction f)
          Applies a function to each corresponding cell of two matrices and aggregates the results.
 FComplexMatrix1D assign(FComplexFComplexFunction f)
          Assigns the result of a function to each cell;
 FComplexMatrix1D assign(FComplexMatrix1D other)
          Replaces all cell values of the receiver with the values of another matrix.
 FComplexMatrix1D assign(FComplexMatrix1D y, FComplexFComplexFComplexFunction f)
          Assigns the result of a function to each cell;
 FComplexMatrix1D assign(FComplexProcedure cond, FComplexFComplexFunction f)
          Assigns the result of a function to all cells that satisfy a condition.
 FComplexMatrix1D assign(FComplexProcedure cond, float[] value)
          Assigns a value to all cells that satisfy a condition.
 FComplexMatrix1D assign(FComplexRealFunction f)
          Assigns the result of a function to the real part of the receiver.
 FComplexMatrix1D assign(float[] values)
          Sets all cells to the state specified by values.
 FComplexMatrix1D assign(float re, float im)
          Sets all cells to the state specified by re and im.
 FComplexMatrix1D assignImaginary(FloatMatrix1D other)
          Replaces imaginary part of the receiver with the values of another real matrix.
 FComplexMatrix1D assignReal(FloatMatrix1D other)
          Replaces real part of the receiver with the values of another real matrix.
 int cardinality()
          Returns the number of cells having non-zero values; ignores tolerance.
 FComplexMatrix1D copy()
          Constructs and returns a deep copy of the receiver.
abstract  Object elements()
          Returns the elements of this matrix.
 boolean equals(float[] value)
          Returns whether all cells are equal to the given value.
 boolean equals(Object obj)
          Compares this object against the specified object.
 float[] get(int index)
          Returns the matrix cell value at coordinate index.
abstract  FloatMatrix1D getImaginaryPart()
          Returns the imaginary part of this matrix
 void getNonZeros(IntArrayList indexList, ArrayList<float[]> valueList)
          Fills the coordinates and values of cells having non-zero values into the specified lists.
abstract  float[] getQuick(int index)
          Returns the matrix cell value at coordinate index.
abstract  FloatMatrix1D getRealPart()
          Returns the real part of this matrix
 FComplexMatrix1D like()
          Construct and returns a new empty matrix of the same dynamic type as the receiver, having the same size.
abstract  FComplexMatrix1D like(int size)
          Construct and returns a new empty matrix of the same dynamic type as the receiver, having the specified size.
abstract  FComplexMatrix2D like2D(int rows, int columns)
          Construct and returns a new 2-d matrix of the corresponding dynamic type, entirely independent of the receiver.
abstract  FComplexMatrix2D reshape(int rows, int cols)
          Returns new FloatMatrix2D of size rows x columns whose elements are taken column-wise from this matrix.
abstract  FComplexMatrix3D reshape(int slices, int rows, int cols)
          Returns new FloatMatrix3D of size slices x rows x columns, whose elements are taken column-wise from this matrix.
 void set(int index, float[] value)
          Sets the matrix cell at coordinate index to the specified value.
 void set(int index, float re, float im)
          Sets the matrix cell at coordinate index to the specified value.
abstract  void setQuick(int index, float[] value)
          Sets the matrix cell at coordinate index to the specified value.
abstract  void setQuick(int index, float re, float im)
          Sets the matrix cell at coordinate index to the specified value.
 void swap(FComplexMatrix1D other)
          Swaps each element this[i] with other[i].
 float[] toArray()
          Constructs and returns a 1-dimensional array containing the cell values.
 void toArray(float[] values)
          Fills the cell values into the specified 1-dimensional array.
 String toString()
          Returns a string representation using default formatting ("%.4f").
 String toString(String format)
          Returns a string representation using given format
 FComplexMatrix1D viewFlip()
          Constructs and returns a new flip view.
 FComplexMatrix1D viewPart(int index, int width)
          Constructs and returns a new sub-range view that is a width sub matrix starting at index.
 FComplexMatrix1D viewSelection(FComplexProcedure condition)
          Constructs and returns a new selection view that is a matrix holding the cells matching the given condition.
 FComplexMatrix1D viewSelection(int[] indexes)
          Constructs and returns a new selection view that is a matrix holding the indicated cells.
 FComplexMatrix1D viewStrides(int stride)
          Constructs and returns a new stride view which is a sub matrix consisting of every i-th cell.
 float[] zDotProduct(FComplexMatrix1D y)
          Returns the dot product of two vectors x and y.
 float[] zDotProduct(FComplexMatrix1D y, int from, int length)
          Returns the dot product of two vectors x and y.
 float[] zDotProduct(FComplexMatrix1D y, int from, int length, IntArrayList nonZeroIndexes)
          Returns the dot product of two vectors x and y.
 float[] zSum()
          Returns the sum of all cells.
 
Methods inherited from class cern.colt.matrix.AbstractMatrix1D
checkSize, index, size, stride, toStringShort
 
Methods inherited from class cern.colt.matrix.AbstractMatrix
ensureCapacity, isView, trimToSize
 
Methods inherited from class cern.colt.PersistentObject
clone
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

aggregate

public float[] aggregate(FComplexFComplexFComplexFunction aggr,
                         FComplexFComplexFunction f)
Applies a function to each cell and aggregates the results.

Parameters:
aggr - an aggregation function taking as first argument the current aggregation and as second argument the transformed current cell value.
f - a function transforming the current cell value.
Returns:
the aggregated measure.
See Also:
FComplexFunctions

aggregate

public float[] aggregate(FComplexMatrix1D other,
                         FComplexFComplexFComplexFunction aggr,
                         FComplexFComplexFComplexFunction f)
Applies a function to each corresponding cell of two matrices and aggregates the results.

Parameters:
other - the secondary matrix to operate on.
aggr - an aggregation function taking as first argument the current aggregation and as second argument the transformed current cell values.
f - a function transforming the current cell values.
Returns:
the aggregated measure.
Throws:
IllegalArgumentException - if size() != other.size().
See Also:
FComplexFunctions

assign

public FComplexMatrix1D assign(FComplexFComplexFunction f)
Assigns the result of a function to each cell;

Parameters:
f - a function object taking as argument the current cell's value.
Returns:
this (for convenience only).
See Also:
FComplexFunctions

assign

public FComplexMatrix1D assign(FComplexProcedure cond,
                               FComplexFComplexFunction f)
Assigns the result of a function to all cells that satisfy a condition.

Parameters:
cond - a condition.
f - a function object.
Returns:
this (for convenience only).
See Also:
FComplexFunctions

assign

public FComplexMatrix1D assign(FComplexProcedure cond,
                               float[] value)
Assigns a value to all cells that satisfy a condition.

Parameters:
cond - a condition.
value - a value (re=value[0], im=value[1]).
Returns:
this (for convenience only).

assign

public FComplexMatrix1D assign(FComplexRealFunction f)
Assigns the result of a function to the real part of the receiver. The imaginary part of the receiver is reset to zero.

Parameters:
f - a function object taking as argument the current cell's value.
Returns:
this (for convenience only).
See Also:
FComplexFunctions

assign

public FComplexMatrix1D assign(FComplexMatrix1D other)
Replaces all cell values of the receiver with the values of another matrix. Both matrices must have the same size. If both matrices share the same cells (as is the case if they are views derived from the same matrix) and intersect in an ambiguous way, then replaces as if using an intermediate auxiliary deep copy of other.

Parameters:
other - the source matrix to copy from (may be identical to the receiver).
Returns:
this (for convenience only).
Throws:
IllegalArgumentException - if size() != other.size().

assign

public FComplexMatrix1D assign(FComplexMatrix1D y,
                               FComplexFComplexFComplexFunction f)
Assigns the result of a function to each cell;

Parameters:
y - the secondary matrix to operate on.
f - a function object taking as first argument the current cell's value of this, and as second argument the current cell's value of y,
Returns:
this (for convenience only).
Throws:
IllegalArgumentException - if size() != y.size().
See Also:
FComplexFunctions

assign

public FComplexMatrix1D assign(float re,
                               float im)
Sets all cells to the state specified by re and im.

Parameters:
re - the real part of the value to be filled into the cells.
im - the imaginary part of the value to be filled into the cells.
Returns:
this (for convenience only).

assign

public FComplexMatrix1D assign(float[] values)
Sets all cells to the state specified by values. values is required to have the same number of cells as the receiver. Complex data is represented by 2 float values in sequence: the real and imaginary parts, i.e. input array must be of size 2*size().

The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa.

Parameters:
values - the values to be filled into the cells.
Returns:
this (for convenience only).
Throws:
IllegalArgumentException - if values.length != 2*size().

assignImaginary

public FComplexMatrix1D assignImaginary(FloatMatrix1D other)
Replaces imaginary part of the receiver with the values of another real matrix. The real part remains unchanged. Both matrices must have the same size.

Parameters:
other - the source matrix to copy from
Returns:
this (for convenience only).
Throws:
IllegalArgumentException - if size() != other.size().

assignReal

public FComplexMatrix1D assignReal(FloatMatrix1D other)
Replaces real part of the receiver with the values of another real matrix. The imaginary part remains unchanged. Both matrices must have the same size.

Parameters:
other - the source matrix to copy from
Returns:
this (for convenience only).
Throws:
IllegalArgumentException - if size() != other.size().

cardinality

public int cardinality()
Returns the number of cells having non-zero values; ignores tolerance.

Returns:
the number of cells having non-zero values.

copy

public FComplexMatrix1D copy()
Constructs and returns a deep copy of the receiver.

Note that the returned matrix is an independent deep copy. The returned matrix is not backed by this matrix, so changes in the returned matrix are not reflected in this matrix, and vice-versa.

Returns:
a deep copy of the receiver.

equals

public boolean equals(float[] value)
Returns whether all cells are equal to the given value.

Parameters:
value - the value to test against (re=value[0], im=value[1]).
Returns:
true if all cells are equal to the given value, false otherwise.

equals

public boolean equals(Object obj)
Compares this object against the specified object. The result is true if and only if the argument is not null and is at least a ComplexMatrix1D object that has the same sizes as the receiver and has exactly the same values at the same indexes.

Overrides:
equals in class Object
Parameters:
obj - the object to compare with.
Returns:
true if the objects are the same; false otherwise.

get

public float[] get(int index)
Returns the matrix cell value at coordinate index.

Parameters:
index - the index of the cell.
Returns:
the value of the specified cell.
Throws:
IndexOutOfBoundsException - if index<0 || index>=size().

elements

public abstract Object elements()
Returns the elements of this matrix.

Returns:
the elements

getImaginaryPart

public abstract FloatMatrix1D getImaginaryPart()
Returns the imaginary part of this matrix

Returns:
the imaginary part

getNonZeros

public void getNonZeros(IntArrayList indexList,
                        ArrayList<float[]> valueList)
Fills the coordinates and values of cells having non-zero values into the specified lists. Fills into the lists, starting at index 0. After this call returns the specified lists all have a new size, the number of non-zero values.

In general, fill order is unspecified. This implementation fills like: for (index = 0..size()-1) do ... . However, subclasses are free to us any other order, even an order that may change over time as cell values are changed. (Of course, result lists indexes are guaranteed to correspond to the same cell).

Parameters:
indexList - the list to be filled with indexes, can have any size.
valueList - the list to be filled with values, can have any size.

getQuick

public abstract float[] getQuick(int index)
Returns the matrix cell value at coordinate index.

Provided with invalid parameters this method may return invalid objects without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): index<0 || index>=size().

Parameters:
index - the index of the cell.
Returns:
the value of the specified cell.

getRealPart

public abstract FloatMatrix1D getRealPart()
Returns the real part of this matrix

Returns:
the real part

like

public FComplexMatrix1D like()
Construct and returns a new empty matrix of the same dynamic type as the receiver, having the same size. For example, if the receiver is an instance of type DenseComplexMatrix1D the new matrix must also be of type DenseComplexMatrix1D. In general, the new matrix should have internal parametrization as similar as possible.

Returns:
a new empty matrix of the same dynamic type.

like

public abstract FComplexMatrix1D like(int size)
Construct and returns a new empty matrix of the same dynamic type as the receiver, having the specified size. For example, if the receiver is an instance of type DenseFComplexMatrix1D the new matrix must also be of type DenseFComplexMatrix1D. In general, the new matrix should have internal parametrization as similar as possible.

Parameters:
size - the number of cell the matrix shall have.
Returns:
a new empty matrix of the same dynamic type.

like2D

public abstract FComplexMatrix2D like2D(int rows,
                                        int columns)
Construct and returns a new 2-d matrix of the corresponding dynamic type, entirely independent of the receiver. For example, if the receiver is an instance of type DenseFComplexMatrix1D the new matrix must be of type DenseFComplexMatrix2D.

Parameters:
rows - the number of rows the matrix shall have.
columns - the number of columns the matrix shall have.
Returns:
a new matrix of the corresponding dynamic type.

reshape

public abstract FComplexMatrix2D reshape(int rows,
                                         int cols)
Returns new FloatMatrix2D of size rows x columns whose elements are taken column-wise from this matrix.

Parameters:
rows - number of rows
cols - number of columns
Returns:
new 2D matrix with columns being the elements of this matrix.

reshape

public abstract FComplexMatrix3D reshape(int slices,
                                         int rows,
                                         int cols)
Returns new FloatMatrix3D of size slices x rows x columns, whose elements are taken column-wise from this matrix.

Parameters:
rows - number of rows
cols - number of columns
Returns:
new 2D matrix with columns being the elements of this matrix.

set

public void set(int index,
                float re,
                float im)
Sets the matrix cell at coordinate index to the specified value.

Parameters:
index - the index of the cell.
re - the real part of the value to be filled into the specified cell.
im - the imaginary part of the value to be filled into the specified cell.
Throws:
IndexOutOfBoundsException - if index<0 || index>=size().

set

public void set(int index,
                float[] value)
Sets the matrix cell at coordinate index to the specified value.

Parameters:
index - the index of the cell.
value - the value to be filled into the specified cell (re=value[0], im=value[1]).
Throws:
IndexOutOfBoundsException - if index<0 || index>=size().

setQuick

public abstract void setQuick(int index,
                              float re,
                              float im)
Sets the matrix cell at coordinate index to the specified value.

Provided with invalid parameters this method may access illegal indexes without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): index<0 || index>=size().

Parameters:
index - the index of the cell.
re - the real part of the value to be filled into the specified cell.
im - the imaginary part of the value to be filled into the specified cell.

setQuick

public abstract void setQuick(int index,
                              float[] value)
Sets the matrix cell at coordinate index to the specified value.

Provided with invalid parameters this method may access illegal indexes without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): index<0 || index>=size().

Parameters:
index - the index of the cell.
value - the value to be filled into the specified cell (re=value[0], im=value[1]).

swap

public void swap(FComplexMatrix1D other)
Swaps each element this[i] with other[i].

Throws:
IllegalArgumentException - if size() != other.size().

toArray

public float[] toArray()
Constructs and returns a 1-dimensional array containing the cell values. The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa. The returned array values has the form
for (int i = 0; i < size; i++) { tmp = getQuick(i); values[2 * i] = tmp[0]; //real part values[2 * i + 1] = tmp[1]; //imaginary part }

Returns:
an array filled with the values of the cells.

toArray

public void toArray(float[] values)
Fills the cell values into the specified 1-dimensional array. The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa. After this call returns the array values has the form
for (int i = 0; i < size; i++) { tmp = getQuick(i); values[2 * i] = tmp[0]; //real part values[2 * i + 1] = tmp[1]; //imaginary part }

Throws:
IllegalArgumentException - if values.length < 2*size().

toString

public String toString()
Returns a string representation using default formatting ("%.4f").

Overrides:
toString in class Object
Returns:
a string representation of the matrix.

toString

public String toString(String format)
Returns a string representation using given format

Parameters:
format - a format for java.lang.String.format().
Returns:
a string representation of the matrix.

viewFlip

public FComplexMatrix1D viewFlip()
Constructs and returns a new flip view. What used to be index 0 is now index size()-1, ..., what used to be index size()-1 is now index 0. The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa.

Returns:
a new flip view.

viewPart

public FComplexMatrix1D viewPart(int index,
                                 int width)
Constructs and returns a new sub-range view that is a width sub matrix starting at index. Operations on the returned view can only be applied to the restricted range. Any attempt to access coordinates not contained in the view will throw an IndexOutOfBoundsException.

Note that the view is really just a range restriction: The returned matrix is backed by this matrix, so changes in the returned matrix are reflected in this matrix, and vice-versa.

The view contains the cells from index..index+width-1. and has view.size() == width. A view's legal coordinates are again zero based, as usual. In other words, legal coordinates of the view are 0 .. view.size()-1==width-1. As usual, any attempt to access a cell at other coordinates will throw an IndexOutOfBoundsException.

Parameters:
index - The index of the first cell.
width - The width of the range.
Returns:
the new view.
Throws:
IndexOutOfBoundsException - if index<0 || width<0 || index+width>size().

viewSelection

public FComplexMatrix1D viewSelection(FComplexProcedure condition)
Constructs and returns a new selection view that is a matrix holding the cells matching the given condition. Applies the condition to each cell and takes only those cells where condition.apply(get(i)) yields true. The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa.

Parameters:
condition - The condition to be matched.
Returns:
the new view.

viewSelection

public FComplexMatrix1D viewSelection(int[] indexes)
Constructs and returns a new selection view that is a matrix holding the indicated cells. There holds view.size() == indexes.length and view.get(i) == this.get(indexes[i]). Indexes can occur multiple times and can be in arbitrary order. Note that modifying indexes after this call has returned has no effect on the view. The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa.

Parameters:
indexes - The indexes of the cells that shall be visible in the new view. To indicate that all cells shall be visible, simply set this parameter to null.
Returns:
the new view.
Throws:
IndexOutOfBoundsException - if !(0 <= indexes[i] < size()) for any i=0..indexes.length()-1.

viewStrides

public FComplexMatrix1D viewStrides(int stride)
Constructs and returns a new stride view which is a sub matrix consisting of every i-th cell. More specifically, the view has size this.size()/stride holding cells this.get(i*stride) for all i = 0..size()/stride - 1.

Parameters:
stride - the step factor.
Returns:
the new view.
Throws:
IndexOutOfBoundsException - if stride <= 0.

zDotProduct

public float[] zDotProduct(FComplexMatrix1D y)
Returns the dot product of two vectors x and y. Operates on cells at indexes 0 .. Math.min(size(),y.size()).

Parameters:
y - the second vector.
Returns:
the sum of products.

zDotProduct

public float[] zDotProduct(FComplexMatrix1D y,
                           int from,
                           int length)
Returns the dot product of two vectors x and y. Operates on cells at indexes from .. Min(size(),y.size(),from+length)-1.

Parameters:
y - the second vector.
from - the first index to be considered.
length - the number of cells to be considered.
Returns:
the sum of products; zero if from<0 || length<0.

zDotProduct

public float[] zDotProduct(FComplexMatrix1D y,
                           int from,
                           int length,
                           IntArrayList nonZeroIndexes)
Returns the dot product of two vectors x and y.

Parameters:
y - the second vector.
nonZeroIndexes - the indexes of cells in yhaving a non-zero value.
Returns:
the sum of products.

zSum

public float[] zSum()
Returns the sum of all cells.

Returns:
the sum.

Parallel Colt 0.7.2

Jump to the Parallel Colt Homepage