Package org.la4j.vector.dense
Class BasicVector
- java.lang.Object
-
- org.la4j.Vector
-
- org.la4j.vector.DenseVector
-
- org.la4j.vector.dense.BasicVector
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.Double>
public class BasicVector extends DenseVector
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.BasicVectorstores the underlying data in a standard array.
-
-
Field Summary
Fields Modifier and Type Field Description private double[]selfprivate static byteVECTOR_TAG
-
Constructor Summary
Constructors Constructor Description BasicVector()BasicVector(double[] array)BasicVector(int length)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description VectorblankOfLength(int length)Creates a blank (an empty vector) copy of this vector with the givenlength.static BasicVectorconstant(int length, double value)VectorcopyOfLength(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(java.util.Collection<? extends java.lang.Number> list)Creates newBasicVectorfromstatic BasicVectorfromCSV(java.lang.String csv)ParsesBasicVectorfrom the given CSV string.static BasicVectorfromMap(java.util.Map<java.lang.Integer,? extends java.lang.Number> map, int length)Creates newBasicVectorfrom index-value mapstatic BasicVectorfromMatrixMarket(java.lang.String mm)ParsesBasicVectorfrom the given Matrix Market string.doubleget(int i)Gets the specified element of this vector.static BasicVectorrandom(int length, java.util.Random random)voidset(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 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
-
-
-
-
Field Detail
-
VECTOR_TAG
private static final byte VECTOR_TAG
- See Also:
- Constant Field Values
-
self
private double[] self
-
-
Method Detail
-
zero
public static BasicVector zero(int length)
Creates a zeroBasicVectorof the givenlength.
-
constant
public static BasicVector constant(int length, double value)
-
unit
public static BasicVector unit(int length)
Creates an unitBasicVectorof the givenlength.
-
random
public static BasicVector random(int length, java.util.Random random)
-
fromArray
public static BasicVector fromArray(double[] array)
Creates a newBasicVectorfrom the givenarrayw/o copying the underlying array.
-
fromBinary
public static BasicVector fromBinary(byte[] array)
DecodesBasicVectorfrom the given bytearray.- Parameters:
array- the byte array representing a vector- Returns:
- a decoded vector
-
fromCSV
public static BasicVector fromCSV(java.lang.String csv)
ParsesBasicVectorfrom the given CSV string.- Parameters:
csv- the CSV string representing a vector- Returns:
- a parsed vector
-
fromMatrixMarket
public static BasicVector fromMatrixMarket(java.lang.String mm)
ParsesBasicVectorfrom the given Matrix Market string.- Parameters:
mm- the string in Matrix Market format- Returns:
- a parsed vector
-
fromCollection
public static BasicVector fromCollection(java.util.Collection<? extends java.lang.Number> list)
Creates newBasicVectorfrom- Parameters:
list- list containing doubles- Returns:
- new vector from given double list
-
fromMap
public static BasicVector fromMap(java.util.Map<java.lang.Integer,? extends java.lang.Number> map, int length)
Creates newBasicVectorfrom index-value map- Parameters:
map- index-value maplength- vector length- Returns:
- created vector
-
get
public double get(int i)
Description copied from class:VectorGets the specified element of this vector.
-
set
public void set(int i, double value)Description copied from class:VectorSets the specified element of this matrix to givenvalue.
-
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
public Vector copyOfLength(int length)
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
public <T extends Vector> T to(VectorFactory<T> factory)
Description copied from class:VectorConverts this vector using the givenfactory.
-
blankOfLength
public Vector blankOfLength(int length)
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
-
-