public class DenseDoubleMatrix1D extends DoubleMatrix1D
Implementation:
Internally holds one single contigous one-dimensional array. Note that this implementation is not synchronized.
Time complexity:
O(1) (i.e. constant time) for the basic operations get, getQuick, set, setQuick and size,
| Constructor and Description |
|---|
DenseDoubleMatrix1D(double[] values)
Constructs a matrix with a copy of the given values.
|
DenseDoubleMatrix1D(int size)
Constructs a matrix with a given number of cells.
|
DenseDoubleMatrix1D(int size,
double[] elements,
int zero,
int stride,
boolean isView)
Constructs a matrix with the given parameters.
|
| Modifier and Type | Method and Description |
|---|---|
double |
aggregate(DoubleDoubleFunction aggr,
DoubleFunction f)
Applies a function to each cell and aggregates the results.
|
double |
aggregate(DoubleDoubleFunction aggr,
DoubleFunction f,
IntArrayList indexList)
Applies a function to all cells with a given indexes and aggregates the
results.
|
double |
aggregate(DoubleMatrix1D other,
DoubleDoubleFunction aggr,
DoubleDoubleFunction f)
Applies a function to each corresponding cell of two matrices and
aggregates the results.
|
DoubleMatrix1D |
assign(double value)
Sets all cells to the state specified by value.
|
DoubleMatrix1D |
assign(double[] values)
Sets all cells to the state specified by values.
|
DoubleMatrix1D |
assign(DoubleFunction function)
Assigns the result of a function to each cell;
x[i] = function(x[i]).
|
DoubleMatrix1D |
assign(DoubleMatrix1D source)
Replaces all cell values of the receiver with the values of another
matrix.
|
DoubleMatrix1D |
assign(DoubleMatrix1D y,
DoubleDoubleFunction function)
Assigns the result of a function to each cell;
x[i] = function(x[i],y[i]).
|
DoubleMatrix1D |
assign(DoubleProcedure cond,
double value)
Assigns a value to all cells that satisfy a condition.
|
DoubleMatrix1D |
assign(DoubleProcedure cond,
DoubleFunction function)
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.
|
void |
dct(boolean scale)
Computes the discrete cosine transform (DCT-II) of this matrix.
|
void |
dht()
Computes the discrete Hartley transform (DHT) of this matrix.
|
void |
dst(boolean scale)
Computes the discrete sine transform (DST-II) of this matrix.
|
double[] |
elements()
Returns the elements of this matrix.
|
void |
fft()
Computes the discrete Fourier transform (DFT) of this matrix.
|
DenseDComplexMatrix1D |
getFft()
Returns new complex matrix which is the discrete Fourier transform (DFT)
of this matrix.
|
DenseDComplexMatrix1D |
getIfft(boolean scale)
Returns new complex matrix which is the inverse of the discrete Fourier
(IDFT) transform of this matrix.
|
double[] |
getMaxLocation()
Return the maximum value of this matrix together with its location
|
double[] |
getMinLocation()
Return the minimum value of this matrix together with its location
|
void |
getNegativeValues(IntArrayList indexList,
DoubleArrayList valueList)
Fills the coordinates and values of cells having negative values into the
specified lists.
|
void |
getNonZeros(IntArrayList indexList,
DoubleArrayList valueList)
Fills the coordinates and values of cells having non-zero values into the
specified lists.
|
void |
getPositiveValues(IntArrayList indexList,
DoubleArrayList valueList)
Fills the coordinates and values of cells having positive values into the
specified lists.
|
double |
getQuick(int index)
Returns the matrix cell value at coordinate index.
|
void |
idct(boolean scale)
Computes the inverse of the discrete cosine transform (DCT-III) of this
matrix.
|
void |
idht(boolean scale)
Computes the inverse of the discrete Hartley transform (IDHT) of this
matrix.
|
void |
idst(boolean scale)
Computes the inverse of discrete sine transform (DST-III) of this matrix.
|
void |
ifft(boolean scale)
Computes the inverse of the discrete Fourier transform (DFT) of this
matrix.
|
long |
index(int rank)
Returns the position of the element with the given relative rank within
the (virtual or non-virtual) internal 1-dimensional array.
|
DoubleMatrix1D |
like(int size)
Construct and returns a new empty matrix of the same dynamic type
as the receiver, having the specified size.
|
DoubleMatrix2D |
like2D(int rows,
int columns)
Construct and returns a new 2-d matrix of the corresponding dynamic
type, entirelly independent of the receiver.
|
DoubleMatrix2D |
reshape(int rows,
int columns)
Returns new DoubleMatrix2D of size rows x columns whose elements are
taken column-wise from this matrix.
|
DoubleMatrix3D |
reshape(int slices,
int rows,
int columns)
Returns new DoubleMatrix3D of size slices x rows x columns, whose
elements are taken column-wise from this matrix.
|
void |
setQuick(int index,
double value)
Sets the matrix cell at coordinate index to the specified value.
|
void |
swap(DoubleMatrix1D other)
Swaps each element this[i] with other[i].
|
void |
toArray(double[] values)
Fills the cell values into the specified 1-dimensional array.
|
double |
zDotProduct(DoubleMatrix1D y,
int from,
int length)
Returns the dot product of two vectors x and y, which is
Sum(x[i]*y[i]).
|
double |
zSum()
Returns the sum of all cells; Sum( x[i] ).
|
assign, copy, equals, equals, get, getNonZeros, like, normalize, set, toArray, toString, viewFlip, viewPart, viewSelection, viewSelection, viewSorted, viewStrides, zDotProduct, zDotProductcheckSize, size, stride, toStringShortensureCapacity, isView, trimToSizeclonepublic DenseDoubleMatrix1D(double[] values)
values - The values to be filled into the new matrix.public DenseDoubleMatrix1D(int size)
size - the number of cells the matrix shall have.IllegalArgumentException - if size<0.public DenseDoubleMatrix1D(int size,
double[] elements,
int zero,
int stride,
boolean isView)
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 constructedIllegalArgumentException - if size<0.public double aggregate(DoubleDoubleFunction aggr, DoubleFunction f)
DoubleMatrix1DExample:
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.aggregate in class DoubleMatrix1Daggr - 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.DoubleFunctionspublic double aggregate(DoubleDoubleFunction aggr, DoubleFunction f, IntArrayList indexList)
DoubleMatrix1Daggregate in class DoubleMatrix1Daggr - 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.DoubleFunctionspublic double aggregate(DoubleMatrix1D other, DoubleDoubleFunction aggr, DoubleDoubleFunction f)
DoubleMatrix1DExample:
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.aggregate in class DoubleMatrix1Daggr - 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.DoubleFunctionspublic DoubleMatrix1D assign(DoubleFunction function)
DoubleMatrix1DExample:
// 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.assign in class DoubleMatrix1Dfunction - a function object taking as argument the current cell's value.DoubleFunctionspublic DoubleMatrix1D assign(DoubleProcedure cond, DoubleFunction function)
DoubleMatrix1Dassign in class DoubleMatrix1Dcond - a condition.function - a function object.DoubleFunctionspublic DoubleMatrix1D assign(DoubleProcedure cond, double value)
DoubleMatrix1Dassign in class DoubleMatrix1Dcond - a condition.value - a value.public DoubleMatrix1D assign(double value)
DoubleMatrix1Dassign in class DoubleMatrix1Dvalue - the value to be filled into the cells.public DoubleMatrix1D assign(double[] values)
DoubleMatrix1DThe values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa.
assign in class DoubleMatrix1Dvalues - the values to be filled into the cells.public DoubleMatrix1D assign(DoubleMatrix1D source)
DoubleMatrix1Dassign in class DoubleMatrix1Dsource - the source matrix to copy from (may be identical to the
receiver).public DoubleMatrix1D assign(DoubleMatrix1D y, DoubleDoubleFunction function)
DoubleMatrix1DExample:
// 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.assign in class DoubleMatrix1Dy - 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,DoubleFunctionspublic int cardinality()
DoubleMatrix1Dcardinality in class DoubleMatrix1Dpublic void dct(boolean scale)
scale - if true then scaling is performedpublic void dht()
public void dst(boolean scale)
scale - if true then scaling is performedpublic double[] elements()
DoubleMatrix1Delements in class DoubleMatrix1Dpublic void fft()
this[2*k] = Re[k], 0<=k<size/2 this[2*k+1] = Im[k], 0<k<size/2 this[1] = Re[size/2]This method computes only half of the elements of the real transform. The other half satisfies the symmetry condition. If you want the full real forward transform, use
getFft. To get back the original
data, use ifft.public DenseDComplexMatrix1D getFft()
public DenseDComplexMatrix1D getIfft(boolean scale)
public void getNonZeros(IntArrayList indexList, DoubleArrayList valueList)
DoubleMatrix1DIn 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.getNonZeros in class DoubleMatrix1DindexList - 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 getPositiveValues(IntArrayList indexList, DoubleArrayList valueList)
DoubleMatrix1DgetPositiveValues in class DoubleMatrix1DindexList - 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 getNegativeValues(IntArrayList indexList, DoubleArrayList valueList)
DoubleMatrix1DgetNegativeValues in class DoubleMatrix1DindexList - the list to be filled with indexes, can have any size.valueList - the list to be filled with values, can have any size.public double[] getMaxLocation()
DoubleMatrix1DgetMaxLocation in class DoubleMatrix1Dpublic double[] getMinLocation()
DoubleMatrix1DgetMinLocation in class DoubleMatrix1Dpublic double getQuick(int index)
DoubleMatrix1DProvided 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().
getQuick in class DoubleMatrix1Dindex - the index of the cell.public void idct(boolean scale)
scale - if true then scaling is performedpublic void idht(boolean scale)
scale - if true then scaling is performedpublic void idst(boolean scale)
scale - if true then scaling is performedpublic void ifft(boolean scale)
this[2*k] = Re[k], 0<=k<size/2 this[2*k+1] = Im[k], 0<k<size/2 this[1] = Re[size/2]This method computes only half of the elements of the real transform. The other half satisfies the symmetry condition. If you want the full real inverse transform, use
getIfft.public DoubleMatrix1D like(int size)
DoubleMatrix1Dlike in class DoubleMatrix1Dsize - the number of cell the matrix shall have.public DoubleMatrix2D like2D(int rows, int columns)
DoubleMatrix1Dlike2D in class DoubleMatrix1Drows - the number of rows the matrix shall have.columns - the number of columns the matrix shall have.public DoubleMatrix2D reshape(int rows, int columns)
DoubleMatrix1Dreshape in class DoubleMatrix1Drows - number of rowscolumns - number of columnspublic DoubleMatrix3D reshape(int slices, int rows, int columns)
DoubleMatrix1Dreshape in class DoubleMatrix1Drows - number of rowscolumns - number of columnspublic void setQuick(int index,
double value)
DoubleMatrix1DProvided 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().
setQuick in class DoubleMatrix1Dindex - the index of the cell.value - the value to be filled into the specified cell.public void swap(DoubleMatrix1D other)
DoubleMatrix1Dswap in class DoubleMatrix1Dpublic void toArray(double[] values)
DoubleMatrix1DtoArray in class DoubleMatrix1Dpublic double zDotProduct(DoubleMatrix1D y, int from, int length)
DoubleMatrix1DzDotProduct in class DoubleMatrix1Dy - the second vector.from - the first index to be considered.length - the number of cells to be considered.public double zSum()
DoubleMatrix1DzSum in class DoubleMatrix1Dpublic long index(int rank)
AbstractMatrix1Dindex in class AbstractMatrix1Drank - the rank of the element.Jump to the Parallel Colt Homepage