/** * Add the vector specified. This is a vector addition that does an element-by-element addition. * * @param other the vector to add. */ public void add(FloatDenseVector other) { if (isSingleton) { throw new RuntimeException("Cannot add to singleton vector"); } if (other.isSingleton) { ensureCapacity(other.singletonIndex + 1); entries.set( other.singletonIndex, entries.getFloat(other.singletonIndex) + other.singletonValue); } else { ensureCapacity(other.entries.size()); for (int i = 0; i < other.entries.size(); ++i) { entries.set(i, entries.getFloat(i) + other.entries.getFloat(i)); } } }
/** * Get a particular entry of the vector. * * @param i the entry * @return the value of the entry. */ public float get(int i) { // The default value is 0.0 if (i >= entries.size()) { return 0.0f; } return entries.getFloat(i); }
@Override public void write(DataOutput out) throws IOException { out.writeBoolean(isSingleton); if (isSingleton) { out.writeInt(singletonIndex); out.writeFloat(singletonValue); } else { out.writeInt(entries.size()); for (int i = 0; i < entries.size(); ++i) { out.writeFloat(entries.getFloat(i)); } } }