public abstract class LongMatrix1D extends AbstractMatrix1D
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.
Modifier and Type | Method and Description |
---|---|
long |
aggregate(LongLongFunction aggr,
LongFunction f)
Applies a function to each cell and aggregates the results.
|
long |
aggregate(LongLongFunction aggr,
LongFunction f,
IntArrayList indexList)
Applies a function to all cells with a given indexes and aggregates the
results.
|
long |
aggregate(LongMatrix1D other,
LongLongFunction aggr,
LongLongFunction f)
Applies a function to each corresponding cell of two matrices and
aggregates the results.
|
LongMatrix1D |
assign(int[] values)
Sets all cells to the state specified by values.
|
LongMatrix1D |
assign(long value)
Sets all cells to the state specified by value.
|
LongMatrix1D |
assign(long[] values)
Sets all cells to the state specified by values.
|
LongMatrix1D |
assign(LongFunction f)
Assigns the result of a function to each cell;
x[i] = function(x[i]).
|
LongMatrix1D |
assign(LongMatrix1D other)
Replaces all cell values of the receiver with the values of another
matrix.
|
LongMatrix1D |
assign(LongMatrix1D y,
LongLongFunction function)
Assigns the result of a function to each cell;
x[i] = function(x[i],y[i]).
|
LongMatrix1D |
assign(LongMatrix1D y,
LongLongFunction function,
IntArrayList nonZeroIndexes)
Assigns the result of a function to each cell;
x[i] = function(x[i],y[i]).
|
LongMatrix1D |
assign(LongProcedure cond,
long value)
Assigns a value to all cells that satisfy a condition.
|
LongMatrix1D |
assign(LongProcedure cond,
LongFunction f)
Assigns the result of a function to all cells that satisfy a condition.
|
int |
cardinality()
Returns the number of cells having non-zero values; ignores tolerance.
|
LongMatrix1D |
copy()
Constructs and returns a deep copy of the receiver.
|
abstract Object |
elements()
Returns the elements of this matrix.
|
boolean |
equals(long value)
Returns whether all cells are equal to the given value.
|
boolean |
equals(Object obj)
Compares this object against the specified object.
|
long |
get(int index)
Returns the matrix cell value at coordinate index.
|
long[] |
getMaxLocation()
Return the maximum value of this matrix together with its location
|
long[] |
getMinLocation()
Return the minimum value of this matrix together with its location
|
void |
getNegativeValues(IntArrayList indexList,
LongArrayList valueList)
Fills the coordinates and values of cells having negative values into the
specified lists.
|
void |
getNonZeros(IntArrayList indexList,
LongArrayList valueList)
Fills the coordinates and values of cells having non-zero values into the
specified lists.
|
void |
getNonZeros(IntArrayList indexList,
LongArrayList valueList,
int maxCardinality)
Fills the coordinates and values of the first maxCardinality
cells having non-zero values into the specified lists.
|
void |
getPositiveValues(IntArrayList indexList,
LongArrayList valueList)
Fills the coordinates and values of cells having positive values into the
specified lists.
|
abstract long |
getQuick(int index)
Returns the matrix cell value at coordinate index.
|
LongMatrix1D |
like()
Construct and returns a new empty matrix of the same dynamic type
as the receiver, having the same size.
|
abstract LongMatrix1D |
like(int size)
Construct and returns a new empty matrix of the same dynamic type
as the receiver, having the specified size.
|
abstract LongMatrix2D |
like2D(int rows,
int columns)
Construct and returns a new 2-d matrix of the corresponding dynamic
type, entirelly independent of the receiver.
|
abstract LongMatrix2D |
reshape(int rows,
int columns)
Returns new LongMatrix2D of size rows x columns whose elements are taken
column-wise from this matrix.
|
abstract LongMatrix3D |
reshape(int slices,
int rows,
int columns)
Returns new LongMatrix3D of size slices x rows x columns, whose elements
are taken column-wise from this matrix.
|
void |
set(int index,
long value)
Sets the matrix cell at coordinate index to the specified value.
|
abstract void |
setQuick(int index,
long value)
Sets the matrix cell at coordinate index to the specified value.
|
void |
setSize(int size)
Sets the size of this matrix.
|
void |
swap(LongMatrix1D other)
Swaps each element this[i] with other[i].
|
long[] |
toArray()
Constructs and returns a 1-dimensional array containing the cell values.
|
void |
toArray(long[] values)
Fills the cell values into the specified 1-dimensional array.
|
String |
toString()
Returns a string representation using default formatting.
|
LongMatrix1D |
viewFlip()
Constructs and returns a new flip view.
|
LongMatrix1D |
viewPart(int index,
int width)
Constructs and returns a new sub-range view that is a
width sub matrix starting at index.
|
LongMatrix1D |
viewSelection(int[] indexes)
Constructs and returns a new selection view that is a matrix
holding the indicated cells.
|
LongMatrix1D |
viewSelection(LongProcedure condition)
Constructs and returns a new selection view that is a matrix
holding the cells matching the given condition.
|
LongMatrix1D |
viewSorted()
Sorts the vector into ascending order, according to the natural
ordering.
|
LongMatrix1D |
viewStrides(int stride)
Constructs and returns a new stride view which is a sub matrix
consisting of every i-th cell.
|
long |
zDotProduct(LongMatrix1D y)
Returns the dot product of two vectors x and y, which is
Sum(x[i]*y[i]).
|
long |
zDotProduct(LongMatrix1D y,
int from,
int length)
Returns the dot product of two vectors x and y, which is
Sum(x[i]*y[i]).
|
long |
zDotProduct(LongMatrix1D y,
int from,
int length,
IntArrayList nonZeroIndexes)
Returns the dot product of two vectors x and y, which is
Sum(x[i]*y[i]).
|
long |
zSum()
Returns the sum of all cells; Sum( x[i] ).
|
checkSize, index, size, stride, toStringShort
ensureCapacity, isView, trimToSize
clone
public long aggregate(LongLongFunction aggr, LongFunction f)
Example:
cern.jet.math.Functions F = cern.jet.math.Functions.functions; matrix = 0 1 2 3 // Sum( x[i]*x[i] ) matrix.aggregate(F.plus,F.square); --> 14For further examples, see the package doc.
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.LongFunctions
public long aggregate(LongLongFunction aggr, LongFunction f, IntArrayList indexList)
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.indexList
- indexes.LongFunctions
public long aggregate(LongMatrix1D other, LongLongFunction aggr, LongLongFunction f)
Example:
cern.jet.math.Functions F = cern.jet.math.Functions.functions; x = 0 1 2 3 y = 0 1 2 3 // Sum( x[i]*y[i] ) x.aggregate(y, F.plus, F.mult); --> 14 // Sum( (x[i]+y[i])ˆ2 ) x.aggregate(y, F.plus, F.chain(F.square,F.plus)); --> 56For further examples, see the package doc.
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.IllegalArgumentException
- if size() != other.size().LongFunctions
public LongMatrix1D assign(LongFunction f)
Example:
// change each cell to its sine matrix = 0.5 1.5 2.5 3.5 matrix.assign(cern.jet.math.Functions.sin); --> matrix == 0.479426 0.997495 0.598472 -0.350783For further examples, see the package doc.
f
- a function object taking as argument the current cell's value.LongFunctions
public LongMatrix1D assign(LongProcedure cond, LongFunction f)
cond
- a condition.f
- a function object.LongFunctions
public LongMatrix1D assign(LongProcedure cond, long value)
cond
- a condition.value
- a value.public LongMatrix1D assign(long value)
value
- the value to be filled into the cells.public LongMatrix1D assign(long[] values)
The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa.
values
- the values to be filled into the cells.IllegalArgumentException
- if values.length != size().public LongMatrix1D assign(int[] values)
The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa.
values
- the values to be filled into the cells.IllegalArgumentException
- if values.length != size().public LongMatrix1D assign(LongMatrix1D other)
other
- the source matrix to copy from (may be identical to the
receiver).IllegalArgumentException
- if size() != other.size().public LongMatrix1D assign(LongMatrix1D y, LongLongFunction function)
Example:
// assign x[i] = x[i]<sup>y[i]</sup> m1 = 0 1 2 3; m2 = 0 2 4 6; m1.assign(m2, cern.jet.math.Functions.pow); --> m1 == 1 1 16 729For further examples, see the package doc.
y
- the secondary matrix to operate on.function
- 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,IllegalArgumentException
- if size() != y.size().LongFunctions
public LongMatrix1D assign(LongMatrix1D y, LongLongFunction function, IntArrayList nonZeroIndexes)
Example:
// assign x[i] = x[i]<sup>y[i]</sup> m1 = 0 1 2 3; m2 = 0 2 4 6; m1.assign(m2, cern.jet.math.Functions.pow); --> m1 == 1 1 16 729 // for non-standard functions there is no shortcut: m1.assign(m2, new LongLongFunction() { public int apply(int x, int y) { return Math.pow(x,y); } } );For further examples, see the package doc.
y
- the secondary matrix to operate on.function
- 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.nonZeroIndexes
- list of indexes of non-zero valuesIllegalArgumentException
- if size() != y.size().LongFunctions
public int cardinality()
public LongMatrix1D copy()
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.
public abstract Object elements()
public boolean equals(long value)
value
- the value to test against.public boolean equals(Object obj)
true
if and only if the argument is not null
and is at least a LongMatrix1D
object that has the same
sizes as the receiver and has exactly the same values at the same
indexes.public long get(int index)
index
- the index of the cell.IndexOutOfBoundsException
- if index<0 || index>=size().public void getNegativeValues(IntArrayList indexList, LongArrayList valueList)
indexList
- the list to be filled with indexes, can have any size.valueList
- the list to be filled with values, can have any size.public void getNonZeros(IntArrayList indexList, LongArrayList valueList)
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).
Example:
0, 0, 8, 0, 7 --> indexList = (2,4) valueList = (8,7)In other words, get(2)==8, get(4)==7.
indexList
- the list to be filled with indexes, can have any size.valueList
- the list to be filled with values, can have any size.public void getNonZeros(IntArrayList indexList, LongArrayList valueList, int maxCardinality)
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).
Example:
0, 0, 8, 0, 7 --> indexList = (2,4) valueList = (8,7)In other words, get(2)==8, get(4)==7.
indexList
- the list to be filled with indexes, can have any size.valueList
- the list to be filled with values, can have any size.maxCardinality
- maximal cardinalitypublic void getPositiveValues(IntArrayList indexList, LongArrayList valueList)
indexList
- the list to be filled with indexes, can have any size.valueList
- the list to be filled with values, can have any size.public abstract long getQuick(int 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().
index
- the index of the cell.public LongMatrix1D like()
public abstract LongMatrix1D like(int size)
size
- the number of cell the matrix shall have.public abstract LongMatrix2D like2D(int rows, int columns)
rows
- the number of rows the matrix shall have.columns
- the number of columns the matrix shall have.public long[] getMaxLocation()
public long[] getMinLocation()
public abstract LongMatrix2D reshape(int rows, int columns)
rows
- number of rowscolumns
- number of columnspublic abstract LongMatrix3D reshape(int slices, int rows, int columns)
rows
- number of rowscolumns
- number of columnspublic void set(int index, long value)
index
- the index of the cell.value
- the value to be filled into the specified cell.IndexOutOfBoundsException
- if index<0 || index>=size().public abstract void setQuick(int index, long 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().
index
- the index of the cell.value
- the value to be filled into the specified cell.public void setSize(int size)
size
- public void swap(LongMatrix1D other)
IllegalArgumentException
- if size() != other.size().public long[] toArray()
public void toArray(long[] values)
IllegalArgumentException
- if values.length < size().public String toString()
toString
in class Object
LongFormatter
public LongMatrix1D viewFlip()
public LongMatrix1D viewPart(int index, int width)
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.
index
- The index of the first cell.width
- The width of the range.IndexOutOfBoundsException
- if index<0 || width<0 || index+width>size().public LongMatrix1D viewSelection(LongProcedure condition)
Example:
// extract and view all cells with even value matrix = 0 1 2 3 matrix.viewSelection( new LongProcedure() { public final boolean apply(int a) { return a % 2 == 0; } } ); --> matrix == 0 2For further examples, see the package doc. The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa.
condition
- The condition to be matched.public LongMatrix1D viewSelection(int[] indexes)
Example:
this = (0,0,8,0,7) indexes = (0,2,4,2) --> view = (0,8,7,8)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.
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.IndexOutOfBoundsException
- if !(0 <= indexes[i] < size()) for any
i=0..indexes.length()-1.public LongMatrix1D viewSorted()
LongSorting.sort(LongMatrix1D)
. For
more advanced sorting functionality, see
LongSorting
.public LongMatrix1D viewStrides(int stride)
stride
- the step factor.IndexOutOfBoundsException
- if stride <= 0.public long zDotProduct(LongMatrix1D y)
y
- the second vector.public long zDotProduct(LongMatrix1D y, int from, int length)
y
- the second vector.from
- the first index to be considered.length
- the number of cells to be considered.public long zDotProduct(LongMatrix1D y, int from, int length, IntArrayList nonZeroIndexes)
y
- the second vector.nonZeroIndexes
- the indexes of cells in yhaving a non-zero value.public long zSum()
Jump to the Parallel Colt Homepage