Example usage for org.apache.mahout.math Varint writeUnsignedVarInt

List of usage examples for org.apache.mahout.math Varint writeUnsignedVarInt

Introduction

In this page you can find the example usage for org.apache.mahout.math Varint writeUnsignedVarInt.

Prototype

public static void writeUnsignedVarInt(int value, DataOutput out) throws IOException 

Source Link

Usage

From source file:de.tudarmstadt.ukp.dkpro.bigdata.collocations.Gram.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    Varint.writeUnsignedVarInt(length, out);
    out.write(bytes, 0, length);//w  w w  .  j  av  a 2 s .c o m
    Varint.writeUnsignedVarInt(frequency, out);
}

From source file:de.tudarmstadt.ukp.dkpro.bigdata.collocations.GramKey.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    Varint.writeUnsignedVarInt(length, out);
    Varint.writeUnsignedVarInt(primaryLength, out);
    out.write(bytes, 0, length);//from ww  w.  j a  v  a  2  s .c om
}

From source file:edu.rosehulman.mahout.math.VectorWritable.java

License:Apache License

public static void writeVector(DataOutput out, Vector vector, boolean laxPrecision) throws IOException {
    boolean dense = vector.isDense();
    boolean sequential = vector.isSequentialAccess();
    boolean named = vector instanceof NamedVector;

    out.writeByte((dense ? FLAG_DENSE : 0) | (sequential ? FLAG_SEQUENTIAL : 0) | (named ? FLAG_NAMED : 0)
            | (laxPrecision ? FLAG_LAX_PRECISION : 0));

    Varint.writeUnsignedVarInt(vector.size(), out);
    if (dense) {//from  w  w w .j  a v a2 s. c o  m
        for (Vector.Element element : vector.all()) {
            if (laxPrecision) {
                out.writeFloat((float) element.get());
            } else {
                out.writeDouble(element.get());
            }
        }
    } else {
        Varint.writeUnsignedVarInt(vector.getNumNonZeroElements(), out);
        Iterator<Element> iter = vector.nonZeroes().iterator();
        if (sequential) {
            int lastIndex = 0;
            while (iter.hasNext()) {
                Vector.Element element = iter.next();
                if (element.get() == 0) {
                    continue;
                }
                int thisIndex = element.index();
                // Delta-code indices:
                Varint.writeUnsignedVarInt(thisIndex - lastIndex, out);
                lastIndex = thisIndex;
                if (laxPrecision) {
                    out.writeFloat((float) element.get());
                } else {
                    out.writeDouble(element.get());
                }
            }
        } else {
            while (iter.hasNext()) {
                Vector.Element element = iter.next();
                if (element.get() == 0) {
                    // TODO(robinanil): Fix the damn iterator for the zero element.
                    continue;
                }
                Varint.writeUnsignedVarInt(element.index(), out);
                if (laxPrecision) {
                    out.writeFloat((float) element.get());
                } else {
                    out.writeDouble(element.get());
                }
            }
        }
    }
    if (named) {
        String name = ((NamedVector) vector).getName();
        out.writeUTF(name == null ? "" : name);
    }
}

From source file:net.jselby.pc.network.StandardOutput.java

License:Open Source License

public void writeVarInt(int number) throws IOException {
    Varint.writeUnsignedVarInt(number, (DataOutput) out);
}

From source file:org.gpfvic.mahout.cf.taste.hadoop.item.VectorAndPrefsWritable.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    VectorWritable vw = new VectorWritable(vector);
    vw.setWritesLaxPrecision(true);//from w w w.java  2  s  .c  om
    vw.write(out);
    Varint.writeUnsignedVarInt(userIDs.size(), out);
    for (int i = 0; i < userIDs.size(); i++) {
        Varint.writeSignedVarLong(userIDs.get(i), out);
        out.writeFloat(values.get(i));
    }
}