summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/data/SparseByteVector.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/data/SparseByteVector.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/SparseByteVector.java40
1 files changed, 16 insertions, 24 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/data/SparseByteVector.java b/src/de/lmu/ifi/dbs/elki/data/SparseByteVector.java
index 06649bb0..6afd9b22 100644
--- a/src/de/lmu/ifi/dbs/elki/data/SparseByteVector.java
+++ b/src/de/lmu/ifi/dbs/elki/data/SparseByteVector.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
@@ -31,23 +31,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 SparseByteVector is to store real values as double values.
- * </p>
- *
- * A SparseByteVector only requires storage for those attribute values that
- * are non-zero.
+ * Sparse vector type, using {@code byte[]} for storing the values, and
+ * {@code int[]} for storing the indexes, approximately 5 bytes per non-zero
+ * value (limited to -128..+127).
*
* @author Arthur Zimek
*/
-public class SparseByteVector extends AbstractNumberVector<Byte> implements SparseNumberVector<Byte> {
+public class SparseByteVector extends AbstractNumberVector implements SparseNumberVector {
/**
* Static instance.
*/
@@ -88,7 +85,7 @@ public class SparseByteVector extends AbstractNumberVector<Byte> implements Spar
}
/**
- * Provides a SparseByteVector consisting of double values according to the
+ * Create a SparseByteVector 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
@@ -141,7 +138,7 @@ public class SparseByteVector extends AbstractNumberVector<Byte> implements Spar
}
/**
- * Provides a SparseByteVector consisting of double values according to the
+ * Create a SparseByteVector 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
@@ -254,20 +251,15 @@ public class SparseByteVector extends AbstractNumberVector<Byte> implements Spar
}
/**
- * <p>
- * Provides a String representation of this SparseByteVector as suitable
- * for
+ * Create a String representation of this SparseByteVector 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 Byte
- * and Byte where the Byte gives the index of the dimensionality and the
- * Byte gives the corresponding value.
- * </p>
+ * number of values actually not zero. Following entries are pairs of Byte and
+ * Byte where the Byte gives the index of the dimensionality and the Byte
+ * gives the corresponding value.
*
* <p>
* Example: a vector (0,1.2,1.3,0)<sup>T</sup> would result in the String<br>
@@ -360,13 +352,13 @@ public class SparseByteVector extends AbstractNumberVector<Byte> implements Spar
*
* @apiviz.has SparseByteVector
*/
- public static class Factory extends AbstractNumberVector.Factory<SparseByteVector, Byte> implements SparseNumberVector.Factory<SparseByteVector, Byte> {
+ public static class Factory extends AbstractNumberVector.Factory<SparseByteVector> implements SparseNumberVector.Factory<SparseByteVector> {
@Override
- public <A> SparseByteVector newFeatureVector(A array, ArrayAdapter<Byte, A> adapter) {
+ public <A> SparseByteVector newFeatureVector(A array, ArrayAdapter<? extends Number, A> adapter) {
int dim = adapter.size(array);
byte[] values = new byte[dim];
for(int i = 0; i < dim; i++) {
- values[i] = adapter.get(array, i);
+ values[i] = adapter.get(array, i).byteValue();
}
// TODO: improve efficiency
return new SparseByteVector(values);