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> T
apply(VectorMatrixOperation<T> operation, Matrix that)
Pipes this vector to a givenoperation
.<T> T
apply(VectorOperation<T> operation)
Pipes this vector to a givenoperation
.<T> T
apply(VectorVectorOperation<T> operation, Vector that)
Pipes this vector to a givenoperation
.static DenseVector
constant(int length, double value)
static DenseVector
fromArray(double[] array)
Creates a newDenseVector
from the givenarray
w/o copying the underlying array.static DenseVector
fromCollection(java.util.Collection<? extends java.lang.Number> list)
Creates newDenseVector
fromstatic DenseVector
fromCSV(java.lang.String csv)
ParsesDenseVector
from the given CSV string.static DenseVector
fromMap(java.util.Map<java.lang.Integer,? extends java.lang.Number> map, int length)
Creates newDenseVector
from index-value mapstatic DenseVector
fromMatrixMarket(java.lang.String mm)
ParsesDenseVector
from the given Matrix Market string.static DenseVector
random(int length, java.util.Random random)
abstract double[]
toArray()
Converts this dense vector to a double array.Matrix
toColumnMatrix()
Converts this vector to matrix with only one column.Matrix
toDiagonalMatrix()
Converts this vector to a diagonal matrix.java.lang.String
toMatrixMarket(java.text.NumberFormat formatter)
Converts this vector into the string in Matrix Market format using the givenformatter
;Matrix
toRowMatrix()
Converts this vector to matrix with only one row.static DenseVector
unit(int length)
Creates an unitDenseVector
of the givenlength
.static DenseVector
zero(int length)
Creates a zeroDenseVector
of 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 zeroDenseVector
of the givenlength
.
-
constant
public static DenseVector constant(int length, double value)
-
unit
public static DenseVector unit(int length)
Creates an unitDenseVector
of the givenlength
.
-
random
public static DenseVector random(int length, java.util.Random random)
-
fromArray
public static DenseVector fromArray(double[] array)
Creates a newDenseVector
from the givenarray
w/o copying the underlying array.
-
fromCSV
public static DenseVector fromCSV(java.lang.String csv)
ParsesDenseVector
from 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)
ParsesDenseVector
from 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 newDenseVector
from- 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 newDenseVector
from 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:Vector
Pipes this vector to a givenoperation
.
-
apply
public <T> T apply(VectorVectorOperation<T> operation, Vector that)
Description copied from class:Vector
Pipes this vector to a givenoperation
.
-
apply
public <T> T apply(VectorMatrixOperation<T> operation, Matrix that)
Description copied from class:Vector
Pipes this vector to a givenoperation
.- Specified by:
apply
in 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
that
matrix
-
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:Vector
Converts this vector to matrix with only one row.- Specified by:
toRowMatrix
in classVector
- Returns:
- the row matrix
-
toColumnMatrix
public Matrix toColumnMatrix()
Description copied from class:Vector
Converts this vector to matrix with only one column.- Specified by:
toColumnMatrix
in classVector
- Returns:
- the column matrix
-
toDiagonalMatrix
public Matrix toDiagonalMatrix()
Description copied from class:Vector
Converts this vector to a diagonal matrix.- Specified by:
toDiagonalMatrix
in classVector
- Returns:
- a diagonal matrix
-
toMatrixMarket
public java.lang.String toMatrixMarket(java.text.NumberFormat formatter)
Description copied from class:Vector
Converts this vector into the string in Matrix Market format using the givenformatter
;- Specified by:
toMatrixMarket
in classVector
- Parameters:
formatter
- the number formater- Returns:
- a Matrix Market string representing this vector
-
-