summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/data/SparseFloatVector.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/data/SparseFloatVector.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/SparseFloatVector.java35
1 files changed, 13 insertions, 22 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/data/SparseFloatVector.java b/src/de/lmu/ifi/dbs/elki/data/SparseFloatVector.java
index 5148920e..b9b2a9e4 100644
--- a/src/de/lmu/ifi/dbs/elki/data/SparseFloatVector.java
+++ b/src/de/lmu/ifi/dbs/elki/data/SparseFloatVector.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -33,23 +33,20 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import de.lmu.ifi.dbs.elki.math.linearalgebra.Vector;
-import de.lmu.ifi.dbs.elki.persistent.ByteArrayUtil;
-import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.ArrayAdapter;
import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.NumberArrayAdapter;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteArrayUtil;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteBufferSerializer;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer;
/**
- * <p>
- * A SparseFloatVector is to store real values approximately as float values.
- * </p>
- *
- * A SparseFloatVector only requires storage for those attribute values that are
- * non-zero.
+ * Sparse vector type, using {@code float[]} for storing the values, and
+ * {@code int[]} for storing the indexes, approximately 8 bytes per non-zero
+ * value.
*
* @author Arthur Zimek
*/
-public class SparseFloatVector extends AbstractNumberVector<Float> implements SparseNumberVector<Float> {
+public class SparseFloatVector extends AbstractNumberVector implements SparseNumberVector {
/**
* Static instance.
*/
@@ -90,7 +87,7 @@ public class SparseFloatVector extends AbstractNumberVector<Float> implements Sp
}
/**
- * Provides a SparseFloatVector consisting of double values according to the
+ * Create a SparseFloatVector consisting of double values according to the
* specified mapping of indices and values.
*
* @param values the values to be set as values of the real vector
@@ -143,7 +140,7 @@ public class SparseFloatVector extends AbstractNumberVector<Float> implements Sp
}
/**
- * Provides a SparseFloatVector consisting of double values according to the
+ * Create a SparseFloatVector consisting of double values according to the
* specified mapping of indices and values.
*
* @param values the values to be set as values of the real vector
@@ -245,24 +242,18 @@ public class SparseFloatVector extends AbstractNumberVector<Float> implements Sp
}
/**
- * <p>
- * Provides a String representation of this SparseFloatVector as suitable for
+ * Create a String representation of this SparseFloatVector as suitable for
* {@link de.lmu.ifi.dbs.elki.datasource.parser.SparseNumberVectorLabelParser}
* .
- * </p>
*
- * <p>
* The returned String is a single line with entries separated by
* {@link AbstractNumberVector#ATTRIBUTE_SEPARATOR}. The first entry gives the
* number of values actually not zero. Following entries are pairs of Integer
* and Float where the Integer gives the index of the dimensionality and the
* Float gives the corresponding value.
- * </p>
*
- * <p>
* Example: a vector (0,1.2,1.3,0)<sup>T</sup> would result in the String<br>
* <code>2 2 1.2 3 1.3</code><br>
- * </p>
*
* @return a String representation of this SparseFloatVector
*/
@@ -350,13 +341,13 @@ public class SparseFloatVector extends AbstractNumberVector<Float> implements Sp
*
* @apiviz.has SparseFloatVector
*/
- public static class Factory extends AbstractNumberVector.Factory<SparseFloatVector, Float> implements SparseNumberVector.Factory<SparseFloatVector, Float> {
+ public static class Factory extends AbstractNumberVector.Factory<SparseFloatVector> implements SparseNumberVector.Factory<SparseFloatVector> {
@Override
- public <A> SparseFloatVector newFeatureVector(A array, ArrayAdapter<Float, A> adapter) {
+ public <A> SparseFloatVector newFeatureVector(A array, ArrayAdapter<? extends Number, A> adapter) {
int dim = adapter.size(array);
float[] values = new float[dim];
for(int i = 0; i < dim; i++) {
- values[i] = adapter.get(array, i);
+ values[i] = adapter.get(array, i).floatValue();
}
// TODO: inefficient
return new SparseFloatVector(values);