Package org.la4j.vector.dense
Class BasicVector
java.lang.Object
org.la4j.Vector
org.la4j.vector.DenseVector
org.la4j.vector.dense.BasicVector
A basic dense vector implementation using an array.
A dense data structure stores data in an underlying array. Even 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.
BasicVector
stores the underlying data in a standard array.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionblankOfLength
(int length) Creates a blank (an empty vector) copy of this vector with the givenlength
.static BasicVector
constant
(int length, double value) copyOfLength
(int length) Copies this vector into the new vector with specifiedlength
.static BasicVector
fromArray
(double[] array) Creates a newBasicVector
from the givenarray
w/o copying the underlying array.static BasicVector
fromBinary
(byte[] array) DecodesBasicVector
from the given bytearray
.static BasicVector
fromCollection
(Collection<? extends Number> list) Creates newBasicVector
fromstatic BasicVector
ParsesBasicVector
from the given CSV string.static BasicVector
Creates newBasicVector
from index-value mapstatic BasicVector
ParsesBasicVector
from the given Matrix Market string.double
get
(int i) Gets the specified element of this vector.static BasicVector
void
set
(int i, double value) Sets the specified element of this matrix to givenvalue
.void
swapElements
(int i, int j) Swaps the specified elements of this vector.<T extends Vector>
Tto
(VectorFactory<T> factory) Converts this vector using the givenfactory
.double[]
toArray()
Converts this dense vector to a double array.byte[]
toBinary()
Encodes this vector into a byte array.static BasicVector
unit
(int length) Creates an unitBasicVector
of the givenlength
.static BasicVector
zero
(int length) Creates a zeroBasicVector
of the givenlength
.Methods inherited from class org.la4j.vector.DenseVector
apply, apply, apply, toColumnMatrix, toDiagonalMatrix, toMatrixMarket, toRowMatrix
Methods inherited from class org.la4j.Vector
add, add, blank, copy, divide, each, ensureLengthIsCorrect, equals, equals, euclideanNorm, fail, fold, hadamardProduct, hashCode, infinityNorm, innerProduct, is, iterator, length, manhattanNorm, max, min, mkString, mkString, multiply, multiply, non, norm, outerProduct, product, select, setAll, shuffle, slice, sliceLeft, sliceRight, subtract, subtract, sum, 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
-
Field Details
-
VECTOR_TAG
private static final byte VECTOR_TAG- See Also:
-
self
private double[] self
-
-
Constructor Details
-
BasicVector
public BasicVector() -
BasicVector
public BasicVector(int length) -
BasicVector
public BasicVector(double[] array)
-
-
Method Details
-
zero
Creates a zeroBasicVector
of the givenlength
. -
constant
-
unit
Creates an unitBasicVector
of the givenlength
. -
random
-
fromArray
Creates a newBasicVector
from the givenarray
w/o copying the underlying array. -
fromBinary
DecodesBasicVector
from the given bytearray
.- Parameters:
array
- the byte array representing a vector- Returns:
- a decoded vector
-
fromCSV
ParsesBasicVector
from the given CSV string.- Parameters:
csv
- the CSV string representing a vector- Returns:
- a parsed vector
-
fromMatrixMarket
ParsesBasicVector
from the given Matrix Market string.- Parameters:
mm
- the string in Matrix Market format- Returns:
- a parsed vector
-
fromCollection
Creates newBasicVector
from- Parameters:
list
- list containing doubles- Returns:
- new vector from given double list
-
fromMap
Creates newBasicVector
from index-value map- Parameters:
map
- index-value maplength
- vector length- Returns:
- created vector
-
get
public double get(int i) Description copied from class:Vector
Gets the specified element of this vector. -
set
public void set(int i, double value) Description copied from class:Vector
Sets the specified element of this matrix to givenvalue
. -
swapElements
public void swapElements(int i, int j) Description copied from class:Vector
Swaps the specified elements of this vector.- Overrides:
swapElements
in classVector
- Parameters:
i
- element's indexj
- element's index
-
copyOfLength
Description copied from class:Vector
Copies this vector into the new vector with specifiedlength
.- Specified by:
copyOfLength
in classVector
- Parameters:
length
- the length of new vector- Returns:
- the copy of this vector with new length
-
toArray
public double[] toArray()Description copied from class:DenseVector
Converts this dense vector to a double array.- Specified by:
toArray
in classDenseVector
- Returns:
- an array representation of this vector
-
to
Description copied from class:Vector
Converts this vector using the givenfactory
. -
blankOfLength
Description copied from class:Vector
Creates a blank (an empty vector) copy of this vector with the givenlength
.- Specified by:
blankOfLength
in classVector
- Parameters:
length
- the length of the blank vector- Returns:
- blank vector
-
toBinary
public byte[] toBinary()Description copied from class:Vector
Encodes this vector into a byte array.
-