/** * @return the density of the array (number of used elements divided * by array length) */ public float density() { return (float)used() / (float)length; }
@Override public void writeBinary(DataOutput out) throws IOException { out.writeInt(this.length); out.writeInt(this.used()); for (Entry e : entries()) { out.writeInt(e.index); out.writeLong(e.value); } }
/** * Compute the dot product with another vector * @param vector the other vector * @return the dot product */ public double dotProduct(SparseLongArray vector) { double sum = 0; int tused = this.used(); int vused = vector.used(); SparseLongArray smaller = (tused < vused ? this : vector); SparseLongArray larger = (tused < vused ? vector : this); for (Entry e : smaller.entries()) { sum += e.value * larger.get(e.index); } return sum; }
out = new Feature[((SparseLongFV) feature).values.used() + extra];