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 BasicVectorconstant(int length, double value) copyOfLength(int length) Copies this vector into the new vector with specifiedlength.static BasicVectorfromArray(double[] array) Creates a newBasicVectorfrom the givenarrayw/o copying the underlying array.static BasicVectorfromBinary(byte[] array) DecodesBasicVectorfrom the given bytearray.static BasicVectorfromCollection(Collection<? extends Number> list) Creates newBasicVectorfromstatic BasicVectorParsesBasicVectorfrom the given CSV string.static BasicVectorCreates newBasicVectorfrom index-value mapstatic BasicVectorParsesBasicVectorfrom the given Matrix Market string.doubleget(int i) Gets the specified element of this vector.static BasicVectorvoidset(int i, double value) Sets the specified element of this matrix to givenvalue.voidswapElements(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 BasicVectorunit(int length) Creates an unitBasicVectorof the givenlength.static BasicVectorzero(int length) Creates a zeroBasicVectorof the givenlength.Methods inherited from class DenseVector
apply, apply, apply, toColumnMatrix, toDiagonalMatrix, toMatrixMarket, toRowMatrixMethods inherited from class 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, updateAtMethods inherited from interface 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 zeroBasicVectorof the givenlength. -
constant
-
unit
Creates an unitBasicVectorof the givenlength. -
random
-
fromArray
Creates a newBasicVectorfrom the givenarrayw/o copying the underlying array. -
fromBinary
DecodesBasicVectorfrom the given bytearray.- Parameters:
array- the byte array representing a vector- Returns:
- a decoded vector
-
fromCSV
ParsesBasicVectorfrom the given CSV string.- Parameters:
csv- the CSV string representing a vector- Returns:
- a parsed vector
-
fromMatrixMarket
ParsesBasicVectorfrom the given Matrix Market string.- Parameters:
mm- the string in Matrix Market format- Returns:
- a parsed vector
-
fromCollection
Creates newBasicVectorfrom- Parameters:
list- list containing doubles- Returns:
- new vector from given double list
-
fromMap
Creates newBasicVectorfrom index-value map- Parameters:
map- index-value maplength- vector length- Returns:
- created vector
-
get
-
set
-
swapElements
public void swapElements(int i, int j) Description copied from class:VectorSwaps the specified elements of this vector.- Overrides:
swapElementsin classVector- Parameters:
i- element's indexj- element's index
-
copyOfLength
Description copied from class:VectorCopies this vector into the new vector with specifiedlength.- Specified by:
copyOfLengthin 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:DenseVectorConverts this dense vector to a double array.- Specified by:
toArrayin classDenseVector- Returns:
- an array representation of this vector
-
to
Description copied from class:VectorConverts this vector using the givenfactory. -
blankOfLength
Description copied from class:VectorCreates a blank (an empty vector) copy of this vector with the givenlength.- Specified by:
blankOfLengthin classVector- Parameters:
length- the length of the blank vector- Returns:
- blank vector
-
toBinary
-