Package elki.data
Class DoubleVector
- java.lang.Object
-
- elki.data.DoubleVector
-
- All Implemented Interfaces:
FeatureVector<java.lang.Number>
,NumberVector
,SpatialComparable
public class DoubleVector extends java.lang.Object implements NumberVector
Vector type usingdouble[]
storage for real numbers.- Since:
- 0.1
- Author:
- Arthur Zimek
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DoubleVector.Factory
Factory for Double vectors.static class
DoubleVector.ShortSerializer
Serialization class for dense double vectors with up toShort.MAX_VALUE
dimensions, by using a short for storing the dimensionality.static class
DoubleVector.SmallSerializer
Serialization class for dense double vectors with up to 127 dimensions, by using a byte for storing the dimensionality.static class
DoubleVector.VariableSerializer
Serialization class for variable dimensionality by using VarInt encoding.
-
Field Summary
Fields Modifier and Type Field Description static ByteBufferSerializer<DoubleVector>
BYTE_SERIALIZER
Serializer for up to 127 dimensions.static DoubleVector.Factory
FACTORY
Static factory instance.static ByteBufferSerializer<DoubleVector>
SHORT_SERIALIZER
Serializer for up to 2^15-1 dimensions.private double[]
values
Stores the values of the real vector.static ByteBufferSerializer<DoubleVector>
VARIABLE_SERIALIZER
Serializer using varint encoding.-
Fields inherited from interface elki.data.FeatureVector
TYPE
-
Fields inherited from interface elki.data.NumberVector
ATTRIBUTE_SEPARATOR, FIELD, FIELD_1D, FIELD_2D, VARIABLE_LENGTH
-
-
Constructor Summary
Constructors Modifier Constructor Description DoubleVector(double[] values)
Create a DoubleVector consisting of the given double values.private
DoubleVector(double[] values, boolean nocopy)
Private constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DoubleVector
copy(double[] vals)
Copy a double array into a new vector.double
doubleValue(int dimension)
Returns the value in the specified dimension as double.int
getDimensionality()
The dimensionality of the vector space where of this FeatureVector of V is an element.long
longValue(int dimension)
Returns the value in the specified dimension as long.double[]
toArray()
Returns a double array copy of this vector.java.lang.String
toString()
Returns a String representation of the FeatureVector of V as a line that is suitable to be printed in a sequential file.static DoubleVector
wrap(double[] vals)
Wrap a double array as vector (without copying).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface elki.data.NumberVector
byteValue, floatValue, getMax, getMin, getValue, intValue, shortValue
-
-
-
-
Field Detail
-
FACTORY
public static final DoubleVector.Factory FACTORY
Static factory instance.
-
BYTE_SERIALIZER
public static final ByteBufferSerializer<DoubleVector> BYTE_SERIALIZER
Serializer for up to 127 dimensions.
-
SHORT_SERIALIZER
public static final ByteBufferSerializer<DoubleVector> SHORT_SERIALIZER
Serializer for up to 2^15-1 dimensions.
-
VARIABLE_SERIALIZER
public static final ByteBufferSerializer<DoubleVector> VARIABLE_SERIALIZER
Serializer using varint encoding.
-
values
private final double[] values
Stores the values of the real vector.
-
-
Constructor Detail
-
DoubleVector
private DoubleVector(double[] values, boolean nocopy)
Private constructor. NOT for public use.- Parameters:
values
- Values to usenocopy
- Flag to not copy the array
-
DoubleVector
public DoubleVector(double[] values)
Create a DoubleVector consisting of the given double values.- Parameters:
values
- the values to be set as values of the DoubleVector
-
-
Method Detail
-
getDimensionality
public int getDimensionality()
Description copied from interface:FeatureVector
The dimensionality of the vector space where of this FeatureVector of V is an element.- Specified by:
getDimensionality
in interfaceFeatureVector<java.lang.Number>
- Specified by:
getDimensionality
in interfaceSpatialComparable
- Returns:
- the number of dimensions of this FeatureVector of V
-
doubleValue
public double doubleValue(int dimension)
Description copied from interface:NumberVector
Returns the value in the specified dimension as double.Note: this might seem redundant with respect to
getValue(dim).doubleValue()
, but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
doubleValue
in interfaceNumberVector
- Parameters:
dimension
- the desired dimension, where 0 ≤ dimension <this.getDimensionality()
- Returns:
- the value in the specified dimension
-
longValue
public long longValue(int dimension)
Description copied from interface:NumberVector
Returns the value in the specified dimension as long.Note: this might seem redundant with respect to
getValue(dim).longValue()
, but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
longValue
in interfaceNumberVector
- Parameters:
dimension
- the desired dimension, where 0 ≤ dimension <this.getDimensionality()
- Returns:
- the value in the specified dimension
-
toArray
public double[] toArray()
Description copied from interface:NumberVector
Returns a double array copy of this vector.- Specified by:
toArray
in interfaceNumberVector
- Returns:
- Copy as
double[]
-
toString
public java.lang.String toString()
Description copied from interface:FeatureVector
Returns a String representation of the FeatureVector of V as a line that is suitable to be printed in a sequential file.- Specified by:
toString
in interfaceFeatureVector<java.lang.Number>
- Overrides:
toString
in classjava.lang.Object
- Returns:
- a String representation of the FeatureVector of V
-
copy
public static DoubleVector copy(double[] vals)
Copy a double array into a new vector.- Parameters:
vals
- Values- Returns:
- Wrapped vector
-
wrap
public static DoubleVector wrap(double[] vals)
Wrap a double array as vector (without copying).Note: modifying the array afterwards can lead to problems if the data has, e.g., been added to an index, which relies on them being immutable!
- Parameters:
vals
- Values- Returns:
- Wrapped vector
-
-