Package org.la4j.vector
Class DenseVector
- java.lang.Object
-
- org.la4j.Vector
-
- org.la4j.vector.DenseVector
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.Double>
- Direct Known Subclasses:
BasicVector
public abstract class DenseVector extends Vector
A dense vector. A vector represents an array of elements. It can be re-sized. A dense data structure usually stores data in an underlying array. Zero elements take up memory space. If you want a data structure that will not have zero elements take up memory space, try a sparse structure. However, fetch/store operations on dense data structures only take O(1) time, instead of the O(log n) time on sparse structures.
-
-
Constructor Summary
Constructors Constructor Description DenseVector(int length)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T> Tapply(VectorMatrixOperation<T> operation, Matrix that)Pipes this vector to a givenoperation.<T> Tapply(VectorOperation<T> operation)Pipes this vector to a givenoperation.<T> Tapply(VectorVectorOperation<T> operation, Vector that)Pipes this vector to a givenoperation.static DenseVectorconstant(int length, double value)static DenseVectorfromArray(double[] array)Creates a newDenseVectorfrom the givenarrayw/o copying the underlying array.static DenseVectorfromCollection(java.util.Collection<? extends java.lang.Number> list)Creates newDenseVectorfromstatic DenseVectorfromCSV(java.lang.String csv)ParsesDenseVectorfrom the given CSV string.static DenseVectorfromMap(java.util.Map<java.lang.Integer,? extends java.lang.Number> map, int length)Creates newDenseVectorfrom index-value mapstatic DenseVectorfromMatrixMarket(java.lang.String mm)ParsesDenseVectorfrom the given Matrix Market string.static DenseVectorrandom(int length, java.util.Random random)abstract double[]toArray()Converts this dense vector to a double array.MatrixtoColumnMatrix()Converts this vector to matrix with only one column.MatrixtoDiagonalMatrix()Converts this vector to a diagonal matrix.java.lang.StringtoMatrixMarket(java.text.NumberFormat formatter)Converts this vector into the string in Matrix Market format using the givenformatter;MatrixtoRowMatrix()Converts this vector to matrix with only one row.static DenseVectorunit(int length)Creates an unitDenseVectorof the givenlength.static DenseVectorzero(int length)Creates a zeroDenseVectorof the givenlength.-
Methods inherited from class org.la4j.Vector
add, add, blank, blankOfLength, copy, copyOfLength, divide, each, ensureLengthIsCorrect, equals, equals, euclideanNorm, fail, fold, get, hadamardProduct, hashCode, infinityNorm, innerProduct, is, iterator, length, manhattanNorm, max, min, mkString, mkString, multiply, multiply, non, norm, outerProduct, product, select, set, setAll, shuffle, slice, sliceLeft, sliceRight, subtract, subtract, sum, swapElements, to, toBinary, toCSV, toCSV, toDenseVector, toMatrixMarket, toSparseVector, toString, transform, update, updateAt
-
-
-
-
Method Detail
-
zero
public static DenseVector zero(int length)
Creates a zeroDenseVectorof the givenlength.
-
constant
public static DenseVector constant(int length, double value)
-
unit
public static DenseVector unit(int length)
Creates an unitDenseVectorof the givenlength.
-
random
public static DenseVector random(int length, java.util.Random random)
-
fromArray
public static DenseVector fromArray(double[] array)
Creates a newDenseVectorfrom the givenarrayw/o copying the underlying array.
-
fromCSV
public static DenseVector fromCSV(java.lang.String csv)
ParsesDenseVectorfrom the given CSV string.- Parameters:
csv- the CSV string representing a vector- Returns:
- a parsed vector
-
fromMatrixMarket
public static DenseVector fromMatrixMarket(java.lang.String mm)
ParsesDenseVectorfrom the given Matrix Market string.- Parameters:
mm- the string in Matrix Market format- Returns:
- a parsed vector
-
fromCollection
public static DenseVector fromCollection(java.util.Collection<? extends java.lang.Number> list)
Creates newDenseVectorfrom- Parameters:
list- list containing doubles- Returns:
- new vector from given double list
-
fromMap
public static DenseVector fromMap(java.util.Map<java.lang.Integer,? extends java.lang.Number> map, int length)
Creates newDenseVectorfrom index-value map- Parameters:
map- index-value maplength- vector length- Returns:
- created vector
-
apply
public <T> T apply(VectorOperation<T> operation)
Description copied from class:VectorPipes this vector to a givenoperation.
-
apply
public <T> T apply(VectorVectorOperation<T> operation, Vector that)
Description copied from class:VectorPipes this vector to a givenoperation.
-
apply
public <T> T apply(VectorMatrixOperation<T> operation, Matrix that)
Description copied from class:VectorPipes this vector to a givenoperation.- Specified by:
applyin classVector- Type Parameters:
T- the result type- Parameters:
operation- the vector-matrix operation (an operation that takes vector and matrix and returnsT)that- the right hand matrix for the given operation- Returns:
- the result of an operation applied to this vector and
thatmatrix
-
toArray
public abstract double[] toArray()
Converts this dense vector to a double array.- Returns:
- an array representation of this vector
-
toRowMatrix
public Matrix toRowMatrix()
Description copied from class:VectorConverts this vector to matrix with only one row.- Specified by:
toRowMatrixin classVector- Returns:
- the row matrix
-
toColumnMatrix
public Matrix toColumnMatrix()
Description copied from class:VectorConverts this vector to matrix with only one column.- Specified by:
toColumnMatrixin classVector- Returns:
- the column matrix
-
toDiagonalMatrix
public Matrix toDiagonalMatrix()
Description copied from class:VectorConverts this vector to a diagonal matrix.- Specified by:
toDiagonalMatrixin classVector- Returns:
- a diagonal matrix
-
toMatrixMarket
public java.lang.String toMatrixMarket(java.text.NumberFormat formatter)
Description copied from class:VectorConverts this vector into the string in Matrix Market format using the givenformatter;- Specified by:
toMatrixMarketin classVector- Parameters:
formatter- the number formater- Returns:
- a Matrix Market string representing this vector
-
-