diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/data/SparseShortVector.java')
-rw-r--r-- | src/de/lmu/ifi/dbs/elki/data/SparseShortVector.java | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/data/SparseShortVector.java b/src/de/lmu/ifi/dbs/elki/data/SparseShortVector.java index 7e54dd5a..7191333f 100644 --- a/src/de/lmu/ifi/dbs/elki/data/SparseShortVector.java +++ b/src/de/lmu/ifi/dbs/elki/data/SparseShortVector.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 SparseShortVector is to store real values as double values. - * </p> - * - * A SparseShortVector only requires storage for those attribute values that are - * non-zero. + * Sparse vector type, using {@code short[]} for storing the values, and + * {@code int[]} for storing the indexes, approximately 6 bytes per non-zero + * value. * * @author Arthur Zimek */ -public class SparseShortVector extends AbstractNumberVector<Short> implements SparseNumberVector<Short> { +public class SparseShortVector extends AbstractNumberVector implements SparseNumberVector { /** * Static instance. */ @@ -88,7 +85,7 @@ public class SparseShortVector extends AbstractNumberVector<Short> implements Sp } /** - * Provides a SparseShortVector consisting of double values according to the + * Create a SparseShortVector 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 SparseShortVector extends AbstractNumberVector<Short> implements Sp } /** - * Provides a SparseShortVector consisting of double values according to the + * Create a SparseShortVector 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 @@ -255,24 +252,18 @@ public class SparseShortVector extends AbstractNumberVector<Short> implements Sp } /** - * <p> - * Provides a String representation of this SparseShortVector as suitable for + * Create a String representation of this SparseShortVector 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 Short * and Short where the Short gives the index of the dimensionality and the * Short 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 SparseShortVector */ @@ -360,13 +351,13 @@ public class SparseShortVector extends AbstractNumberVector<Short> implements Sp * * @apiviz.has SparseShortVector */ - public static class Factory extends AbstractNumberVector.Factory<SparseShortVector, Short> implements SparseNumberVector.Factory<SparseShortVector, Short> { + public static class Factory extends AbstractNumberVector.Factory<SparseShortVector> implements SparseNumberVector.Factory<SparseShortVector> { @Override - public <A> SparseShortVector newFeatureVector(A array, ArrayAdapter<Short, A> adapter) { + public <A> SparseShortVector newFeatureVector(A array, ArrayAdapter<? extends Number, A> adapter) { int dim = adapter.size(array); short[] values = new short[dim]; for(int i = 0; i < dim; i++) { - values[i] = adapter.get(array, i); + values[i] = adapter.get(array, i).shortValue(); } // TODO: improve efficiency return new SparseShortVector(values); |