Package org.la4j.vector
Class DenseVector
java.lang.Object
org.la4j.Vector
org.la4j.vector.DenseVector
- Direct Known Subclasses:
BasicVector
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.
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<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
(Collection<? extends Number> list) Creates newDenseVector
fromstatic DenseVector
ParsesDenseVector
from the given CSV string.static DenseVector
Creates newDenseVector
from index-value mapstatic DenseVector
ParsesDenseVector
from the given Matrix Market string.static DenseVector
abstract double[]
toArray()
Converts this dense vector to a double array.Converts this vector to matrix with only one column.Converts this vector to a diagonal matrix.toMatrixMarket
(NumberFormat formatter) Converts this vector into the string in Matrix Market format using the givenformatter
;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
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
DenseVector
public DenseVector(int length)
-
-
Method Details
-
zero
Creates a zeroDenseVector
of the givenlength
. -
constant
-
unit
Creates an unitDenseVector
of the givenlength
. -
random
-
fromArray
Creates a newDenseVector
from the givenarray
w/o copying the underlying array. -
fromCSV
ParsesDenseVector
from the given CSV string.- Parameters:
csv
- the CSV string representing a vector- Returns:
- a parsed vector
-
fromMatrixMarket
ParsesDenseVector
from the given Matrix Market string.- Parameters:
mm
- the string in Matrix Market format- Returns:
- a parsed vector
-
fromCollection
Creates newDenseVector
from- Parameters:
list
- list containing doubles- Returns:
- new vector from given double list
-
fromMap
Creates newDenseVector
from index-value map- Parameters:
map
- index-value maplength
- vector length- Returns:
- created vector
-
apply
Description copied from class:Vector
Pipes this vector to a givenoperation
. -
apply
Description copied from class:Vector
Pipes this vector to a givenoperation
. -
apply
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
Description copied from class:Vector
Converts this vector to matrix with only one row.- Specified by:
toRowMatrix
in classVector
- Returns:
- the row 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
Description copied from class:Vector
Converts this vector to a diagonal matrix.- Specified by:
toDiagonalMatrix
in classVector
- Returns:
- a diagonal matrix
-
toMatrixMarket
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
-