Class DenseLongMatrix1D
- java.lang.Object
-
- cern.colt.PersistentObject
-
- cern.colt.matrix.AbstractMatrix
-
- cern.colt.matrix.AbstractMatrix1D
-
- cern.colt.matrix.tlong.LongMatrix1D
-
- cern.colt.matrix.tlong.impl.DenseLongMatrix1D
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
public class DenseLongMatrix1D extends LongMatrix1D
Dense 1-d matrix (aka vector) holding int elements. First see the package summary and javadoc tree view to get the broad picture.Implementation:
Longernally holds one single contigous one-dimensional array. Note that this implementation is not synchronized.
Memory requirements:
memory [bytes] = 8*size(). Thus, a 1000000 matrix uses 8 MB.
Time complexity:
O(1) (i.e. constant time) for the basic operations get, getQuick, set, setQuick and size,
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DenseLongMatrix1D(int size)Constructs a matrix with a given number of cells.DenseLongMatrix1D(int size, long[] elements, int zero, int stride, boolean isView)Constructs a matrix with the given parameters.DenseLongMatrix1D(long[] values)Constructs a matrix with a copy of the given values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description longaggregate(LongLongFunction aggr, LongFunction f)Applies a function to each cell and aggregates the results.longaggregate(LongLongFunction aggr, LongFunction f, IntArrayList indexList)Applies a function to all cells with a given indexes and aggregates the results.longaggregate(LongMatrix1D other, LongLongFunction aggr, LongLongFunction f)Applies a function to each corresponding cell of two matrices and aggregates the results.LongMatrix1Dassign(int[] values)Sets all cells to the state specified by values.LongMatrix1Dassign(long value)Sets all cells to the state specified by value.LongMatrix1Dassign(long[] values)Sets all cells to the state specified by values.LongMatrix1Dassign(LongFunction function)Assigns the result of a function to each cell; x[i] = function(x[i]).LongMatrix1Dassign(LongMatrix1D source)Replaces all cell values of the receiver with the values of another matrix.LongMatrix1Dassign(LongMatrix1D y, LongLongFunction function)Assigns the result of a function to each cell; x[i] = function(x[i],y[i]).LongMatrix1Dassign(LongProcedure cond, long value)Assigns a value to all cells that satisfy a condition.LongMatrix1Dassign(LongProcedure cond, LongFunction function)Assigns the result of a function to all cells that satisfy a condition.intcardinality()Returns the number of cells having non-zero values; ignores tolerance.long[]elements()Returns the elements of this matrix.long[]getMaxLocation()Return the maximum value of this matrix together with its locationlong[]getMinLocation()Return the minimum value of this matrix together with its locationvoidgetNegativeValues(LongArrayList indexList, LongArrayList valueList)voidgetNonZeros(LongArrayList indexList, LongArrayList valueList)voidgetPositiveValues(LongArrayList indexList, LongArrayList valueList)longgetQuick(int index)Returns the matrix cell value at coordinate index.longindex(int rank)Returns the position of the element with the given relative rank within the (virtual or non-virtual) internal 1-dimensional array.LongMatrix1Dlike(int size)Construct and returns a new empty matrix of the same dynamic type as the receiver, having the specified size.LongMatrix2Dlike2D(int rows, int columns)Construct and returns a new 2-d matrix of the corresponding dynamic type, entirelly independent of the receiver.LongMatrix2Dreshape(int rows, int columns)Returns new LongMatrix2D of size rows x columns whose elements are taken column-wise from this matrix.LongMatrix3Dreshape(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.voidsetQuick(int index, long value)Sets the matrix cell at coordinate index to the specified value.voidswap(LongMatrix1D other)Swaps each element this[i] with other[i].voidtoArray(long[] values)Fills the cell values into the specified 1-dimensional array.longzDotProduct(LongMatrix1D y)Returns the dot product of two vectors x and y, which is Sum(x[i]*y[i]).longzDotProduct(LongMatrix1D y, int from, int length)Returns the dot product of two vectors x and y, which is Sum(x[i]*y[i]).longzSum()Returns the sum of all cells; Sum( x[i] ).-
Methods inherited from class cern.colt.matrix.tlong.LongMatrix1D
assign, copy, equals, equals, get, getNegativeValues, getNonZeros, getNonZeros, getPositiveValues, like, set, setSize, toArray, toString, viewFlip, viewPart, viewSelection, viewSelection, viewSorted, viewStrides, zDotProduct
-
Methods inherited from class cern.colt.matrix.AbstractMatrix1D
checkSize, size, stride, toStringShort
-
Methods inherited from class cern.colt.matrix.AbstractMatrix
ensureCapacity, isView, trimToSize
-
Methods inherited from class cern.colt.PersistentObject
clone
-
-
-
-
Constructor Detail
-
DenseLongMatrix1D
public DenseLongMatrix1D(long[] values)
Constructs a matrix with a copy of the given values. 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 new matrix.
-
DenseLongMatrix1D
public DenseLongMatrix1D(int size)
Constructs a matrix with a given number of cells. All entries are initially 0.- Parameters:
size- the number of cells the matrix shall have.- Throws:
java.lang.IllegalArgumentException- if size<0.
-
DenseLongMatrix1D
public DenseLongMatrix1D(int size, long[] elements, int zero, int stride, boolean isView)Constructs a matrix with the given parameters.- Parameters:
size- the number of cells the matrix shall have.elements- the cells.zero- the index of the first element.stride- the number of indexes between any two elements, i.e. index(i+1)-index(i).isView- if true then a matrix view is constructed- Throws:
java.lang.IllegalArgumentException- if size<0.
-
-
Method Detail
-
aggregate
public long aggregate(LongLongFunction aggr, LongFunction f)
Description copied from class:LongMatrix1DApplies a function to each cell and aggregates the results. Returns a value v such that v==a(size()) where a(i) == aggr( a(i-1), f(get(i)) ) and terminators are a(1) == f(get(0)), a(0)==Long.NaN.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); --> 14
For further examples, see the package doc.- Overrides:
aggregatein classLongMatrix1D- 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:
LongFunctions
-
aggregate
public long aggregate(LongLongFunction aggr, LongFunction f, IntArrayList indexList)
Description copied from class:LongMatrix1DApplies a function to all cells with a given indexes and aggregates the results.- Overrides:
aggregatein classLongMatrix1D- 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.indexList- indexes.- Returns:
- the aggregated measure.
- See Also:
LongFunctions
-
aggregate
public long aggregate(LongMatrix1D other, LongLongFunction aggr, LongLongFunction f)
Description copied from class:LongMatrix1DApplies a function to each corresponding cell of two matrices and aggregates the results. Returns a value v such that v==a(size()) where a(i) == aggr( a(i-1), f(get(i),other.get(i)) ) and terminators are a(1) == f(get(0),other.get(0)), a(0)==Long.NaN.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)); --> 56
For further examples, see the package doc.- Overrides:
aggregatein classLongMatrix1Daggr- 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.
- See Also:
LongFunctions
-
assign
public LongMatrix1D assign(LongFunction function)
Description copied from class:LongMatrix1DAssigns the result of a function to each cell; x[i] = function(x[i]). (Iterates downwards from [size()-1] to [0]).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.350783
For further examples, see the package doc.- Overrides:
assignin classLongMatrix1D- Parameters:
function- a function object taking as argument the current cell's value.- Returns:
- this (for convenience only).
- See Also:
LongFunctions
-
assign
public LongMatrix1D assign(LongProcedure cond, LongFunction function)
Description copied from class:LongMatrix1DAssigns the result of a function to all cells that satisfy a condition.- Overrides:
assignin classLongMatrix1D- Parameters:
cond- a condition.function- a function object.- Returns:
- this (for convenience only).
- See Also:
LongFunctions
-
assign
public LongMatrix1D assign(LongProcedure cond, long value)
Description copied from class:LongMatrix1DAssigns a value to all cells that satisfy a condition.- Overrides:
assignin classLongMatrix1D- Parameters:
cond- a condition.value- a value.- Returns:
- this (for convenience only).
-
assign
public LongMatrix1D assign(long value)
Description copied from class:LongMatrix1DSets all cells to the state specified by value.- Overrides:
assignin classLongMatrix1D- Parameters:
value- the value to be filled into the cells.- Returns:
- this (for convenience only).
-
assign
public LongMatrix1D assign(long[] values)
Description copied from class:LongMatrix1DSets all cells to the state specified by values. values is required to have the same number of cells as the receiver.The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa.
- Overrides:
assignin classLongMatrix1D- Parameters:
values- the values to be filled into the cells.- Returns:
- this (for convenience only).
-
assign
public LongMatrix1D assign(int[] values)
Description copied from class:LongMatrix1DSets all cells to the state specified by values. values is required to have the same number of cells as the receiver.The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa.
- Overrides:
assignin classLongMatrix1D- Parameters:
values- the values to be filled into the cells.- Returns:
- this (for convenience only).
-
assign
public LongMatrix1D assign(LongMatrix1D source)
Description copied from class:LongMatrix1DReplaces 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.- Overrides:
assignin classLongMatrix1D- Parameters:
source- the source matrix to copy from (may be identical to the receiver).- Returns:
- this (for convenience only).
-
assign
public LongMatrix1D assign(LongMatrix1D y, LongLongFunction function)
Description copied from class:LongMatrix1DAssigns the result of a function to each cell; x[i] = function(x[i],y[i]).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 further examples, see the package doc.- Overrides:
assignin classLongMatrix1D- Parameters:
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,- Returns:
- this (for convenience only).
- See Also:
LongFunctions
-
cardinality
public int cardinality()
Description copied from class:LongMatrix1DReturns the number of cells having non-zero values; ignores tolerance.- Overrides:
cardinalityin classLongMatrix1D- Returns:
- the number of cells having non-zero values.
-
elements
public long[] elements()
Description copied from class:LongMatrix1DReturns the elements of this matrix.- Specified by:
elementsin classLongMatrix1D- Returns:
- the elements
-
getNonZeros
public void getNonZeros(LongArrayList indexList, LongArrayList valueList)
-
getPositiveValues
public void getPositiveValues(LongArrayList indexList, LongArrayList valueList)
-
getNegativeValues
public void getNegativeValues(LongArrayList indexList, LongArrayList valueList)
-
getMaxLocation
public long[] getMaxLocation()
Description copied from class:LongMatrix1DReturn the maximum value of this matrix together with its location- Overrides:
getMaxLocationin classLongMatrix1D- Returns:
- { maximum_value, location };
-
getMinLocation
public long[] getMinLocation()
Description copied from class:LongMatrix1DReturn the minimum value of this matrix together with its location- Overrides:
getMinLocationin classLongMatrix1D- Returns:
- { minimum_value, location };
-
getQuick
public long getQuick(int index)
Description copied from class:LongMatrix1DReturns 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().
- Specified by:
getQuickin classLongMatrix1D- Parameters:
index- the index of the cell.- Returns:
- the value of the specified cell.
-
like
public LongMatrix1D like(int size)
Description copied from class:LongMatrix1DConstruct 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 DenseLongMatrix1D the new matrix must also be of type DenseLongMatrix1D, if the receiver is an instance of type SparseLongMatrix1D the new matrix must also be of type SparseLongMatrix1D, etc. In general, the new matrix should have internal parametrization as similar as possible.- Specified by:
likein classLongMatrix1D- Parameters:
size- the number of cell the matrix shall have.- Returns:
- a new empty matrix of the same dynamic type.
-
like2D
public LongMatrix2D like2D(int rows, int columns)
Description copied from class:LongMatrix1DConstruct and returns a new 2-d matrix of the corresponding dynamic type, entirelly independent of the receiver. For example, if the receiver is an instance of type DenseLongMatrix1D the new matrix must be of type DenseLongMatrix2D, if the receiver is an instance of type SparseLongMatrix1D the new matrix must be of type SparseLongMatrix2D, etc.- Specified by:
like2Din classLongMatrix1D- 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 LongMatrix2D reshape(int rows, int columns)
Description copied from class:LongMatrix1DReturns new LongMatrix2D of size rows x columns whose elements are taken column-wise from this matrix.- Specified by:
reshapein classLongMatrix1D- Parameters:
rows- number of rowscolumns- number of columns- Returns:
- new 2D matrix with columns being the elements of this matrix.
-
reshape
public LongMatrix3D reshape(int slices, int rows, int columns)
Description copied from class:LongMatrix1DReturns new LongMatrix3D of size slices x rows x columns, whose elements are taken column-wise from this matrix.- Specified by:
reshapein classLongMatrix1Drows- number of rowscolumns- number of columns- Returns:
- new 2D matrix with columns being the elements of this matrix.
-
setQuick
public void setQuick(int index, long value)Description copied from class:LongMatrix1DSets 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().
- Specified by:
setQuickin classLongMatrix1D- Parameters:
index- the index of the cell.value- the value to be filled into the specified cell.
-
swap
public void swap(LongMatrix1D other)
Description copied from class:LongMatrix1DSwaps each element this[i] with other[i].- Overrides:
swapin classLongMatrix1D
-
toArray
public void toArray(long[] values)
Description copied from class:LongMatrix1DFills 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++) values[i] = get(i);- Overrides:
toArrayin classLongMatrix1D
-
zDotProduct
public long zDotProduct(LongMatrix1D y)
Description copied from class:LongMatrix1DReturns the dot product of two vectors x and y, which is Sum(x[i]*y[i]). Where x == this. Operates on cells at indexes 0 .. Math.min(size(),y.size()).- Overrides:
zDotProductin classLongMatrix1D- Parameters:
y- the second vector.- Returns:
- the sum of products.
-
zDotProduct
public long zDotProduct(LongMatrix1D y, int from, int length)
Description copied from class:LongMatrix1DReturns the dot product of two vectors x and y, which is Sum(x[i]*y[i]). Where x == this. Operates on cells at indexes from .. Min(size(),y.size(),from+length)-1.- Overrides:
zDotProductin classLongMatrix1D- 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.
-
zSum
public long zSum()
Description copied from class:LongMatrix1DReturns the sum of all cells; Sum( x[i] ).- Overrides:
zSumin classLongMatrix1D- Returns:
- the sum.
-
index
public long index(int rank)
Description copied from class:AbstractMatrix1DReturns the position of the element with the given relative rank within the (virtual or non-virtual) internal 1-dimensional array. You may want to override this method for performance.- Overrides:
indexin classAbstractMatrix1D- Parameters:
rank- the rank of the element.
-
-
DMelt 3.0 © DataMelt by jWork.ORG