Class DenseDoubleMatrix1D
- java.lang.Object
-
- cern.colt.PersistentObject
-
- cern.colt.matrix.impl.AbstractMatrix
-
- cern.colt.matrix.impl.AbstractMatrix1D
-
- cern.colt.matrix.DoubleMatrix1D
-
- cern.colt.matrix.impl.DenseDoubleMatrix1D
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class DenseDoubleMatrix1D extends DoubleMatrix1D
Dense 1-d matrix (aka vector) holding double elements. First see the package summary and javadoc tree view to get the broad picture.Implementation:
Internally 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,
- Version:
- 1.0, 09/24/99
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected double[]
elements
The elements of this matrix.-
Fields inherited from class cern.colt.matrix.impl.AbstractMatrix1D
size, stride, zero
-
Fields inherited from class cern.colt.matrix.impl.AbstractMatrix
isNoView
-
Fields inherited from class cern.colt.PersistentObject
serialVersionUID
-
-
Constructor Summary
Constructors Modifier Constructor 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.protected
DenseDoubleMatrix1D(int size, double[] elements, int zero, int stride)
Constructs a matrix view with the given parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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]).protected int
cardinality(int maxCardinality)
Returns the number of cells having non-zero values, but at most maxCardinality; ignores tolerance.double
getQuick(int index)
Returns the matrix cell value at coordinate index.protected boolean
haveSharedCellsRaw(DoubleMatrix1D other)
Returns true if both matrices share at least one identical cell.protected int
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.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.protected DoubleMatrix1D
viewSelectionLike(int[] offsets)
Construct and returns a new selection view.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] ).-
Methods inherited from class cern.colt.matrix.DoubleMatrix1D
aggregate, aggregate, assign, cardinality, copy, equals, equals, get, getContent, getNonZeros, getNonZeros, haveSharedCells, like, set, toArray, toString, view, viewFlip, viewPart, viewSelection, viewSelection, viewSorted, viewStrides, zDotProduct, zDotProduct, zDotProduct
-
Methods inherited from class cern.colt.matrix.impl.AbstractMatrix1D
_offset, _rank, checkIndex, checkIndexes, checkRange, checkSize, checkSize, setUp, setUp, size, stride, toStringShort, vFlip, vPart, vStrides
-
Methods inherited from class cern.colt.matrix.impl.AbstractMatrix
ensureCapacity, isView, trimToSize
-
Methods inherited from class cern.colt.PersistentObject
clone
-
-
-
-
Constructor Detail
-
DenseDoubleMatrix1D
public DenseDoubleMatrix1D(double[] 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.
-
DenseDoubleMatrix1D
public DenseDoubleMatrix1D(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.
-
DenseDoubleMatrix1D
protected DenseDoubleMatrix1D(int size, double[] elements, int zero, int stride)
Constructs a matrix view 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).- Throws:
java.lang.IllegalArgumentException
- if size<0.
-
-
Method Detail
-
assign
public DoubleMatrix1D assign(double[] values)
Sets 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:
assign
in classDoubleMatrix1D
- Parameters:
values
- the values to be filled into the cells.- Returns:
- this (for convenience only).
- Throws:
java.lang.IllegalArgumentException
- if values.length != size().
-
assign
public DoubleMatrix1D assign(double value)
Sets all cells to the state specified by value.- Overrides:
assign
in classDoubleMatrix1D
- Parameters:
value
- the value to be filled into the cells.- Returns:
- this (for convenience only).
-
assign
public DoubleMatrix1D assign(DoubleFunction function)
Assigns 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:
assign
in classDoubleMatrix1D
- Parameters:
function
- a function object taking as argument the current cell's value.- Returns:
- this (for convenience only).
- See Also:
Functions
-
assign
public DoubleMatrix1D assign(DoubleMatrix1D source)
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.- Overrides:
assign
in classDoubleMatrix1D
- Parameters:
source
- the source matrix to copy from (may be identical to the receiver).- Returns:
- this (for convenience only).
- Throws:
java.lang.IllegalArgumentException
- if size() != other.size().
-
assign
public DoubleMatrix1D assign(DoubleMatrix1D y, DoubleDoubleFunction function)
Assigns the result of a function to each cell; x[i] = function(x[i],y[i]). (Iterates downwards from [size()-1] to [0]).Example:
// assign x[i] = x[i]y[i] 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 DoubleDoubleFunction() { public double apply(double x, double y) { return Math.pow(x,y); } } );
For further examples, see the package doc.- Overrides:
assign
in classDoubleMatrix1D
- 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).
- Throws:
java.lang.IllegalArgumentException
- if size() != y.size().- See Also:
Functions
-
cardinality
protected int cardinality(int maxCardinality)
Returns the number of cells having non-zero values, but at most maxCardinality; ignores tolerance.- Overrides:
cardinality
in classDoubleMatrix1D
-
getQuick
public double 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().
- Specified by:
getQuick
in classDoubleMatrix1D
- Parameters:
index
- the index of the cell.- Returns:
- the value of the specified cell.
-
haveSharedCellsRaw
protected boolean haveSharedCellsRaw(DoubleMatrix1D other)
Returns true if both matrices share at least one identical cell.- Overrides:
haveSharedCellsRaw
in classDoubleMatrix1D
-
index
protected int index(int rank)
Returns 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:
index
in classAbstractMatrix1D
- Parameters:
rank
- the rank of the element.
-
like
public DoubleMatrix1D 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 DenseDoubleMatrix1D the new matrix must also be of type DenseDoubleMatrix1D, if the receiver is an instance of type SparseDoubleMatrix1D the new matrix must also be of type SparseDoubleMatrix1D, etc. In general, the new matrix should have internal parametrization as similar as possible.- Specified by:
like
in classDoubleMatrix1D
- Parameters:
size
- the number of cell the matrix shall have.- Returns:
- a new empty matrix of the same dynamic type.
-
like2D
public DoubleMatrix2D like2D(int rows, int columns)
Construct 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 DenseDoubleMatrix1D the new matrix must be of type DenseDoubleMatrix2D, if the receiver is an instance of type SparseDoubleMatrix1D the new matrix must be of type SparseDoubleMatrix2D, etc.- Specified by:
like2D
in classDoubleMatrix1D
- 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.
-
setQuick
public void setQuick(int index, double 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().
- Specified by:
setQuick
in classDoubleMatrix1D
- Parameters:
index
- the index of the cell.value
- the value to be filled into the specified cell.
-
swap
public void swap(DoubleMatrix1D other)
Swaps each element this[i] with other[i].- Overrides:
swap
in classDoubleMatrix1D
- Throws:
java.lang.IllegalArgumentException
- if size() != other.size().
-
toArray
public void toArray(double[] 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++) values[i] = get(i);- Overrides:
toArray
in classDoubleMatrix1D
- Throws:
java.lang.IllegalArgumentException
- if values.length < size().
-
viewSelectionLike
protected DoubleMatrix1D viewSelectionLike(int[] offsets)
Construct and returns a new selection view.- Specified by:
viewSelectionLike
in classDoubleMatrix1D
- Parameters:
offsets
- the offsets of the visible elements.- Returns:
- a new view.
-
zDotProduct
public 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]). Where x == this. Operates on cells at indexes from .. Min(size(),y.size(),from+length)-1.- Overrides:
zDotProduct
in classDoubleMatrix1D
- 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 double zSum()
Returns the sum of all cells; Sum( x[i] ).- Overrides:
zSum
in classDoubleMatrix1D
- Returns:
- the sum.
-
-