Example usage for org.apache.mahout.math VectorWritable FLAG_SEQUENTIAL

List of usage examples for org.apache.mahout.math VectorWritable FLAG_SEQUENTIAL

Introduction

In this page you can find the example usage for org.apache.mahout.math VectorWritable FLAG_SEQUENTIAL.

Prototype

int FLAG_SEQUENTIAL

To view the source code for org.apache.mahout.math VectorWritable FLAG_SEQUENTIAL.

Click Source Link

Usage

From source file:Vectors.java

License:Apache License

public static OpenIntIntHashMap readAsIntMap(DataInput in) throws IOException {
    int flags = in.readByte();
    Preconditions.checkArgument(flags >> VectorWritable.NUM_FLAGS == 0, "Unknown flags set: %d",
            Integer.toString(flags, 2));
    boolean dense = (flags & VectorWritable.FLAG_DENSE) != 0;
    boolean sequential = (flags & VectorWritable.FLAG_SEQUENTIAL) != 0;
    boolean laxPrecision = (flags & VectorWritable.FLAG_LAX_PRECISION) != 0;
    Preconditions.checkState(!dense && !sequential, "Only for reading sparse vectors!");

    Varint.readUnsignedVarInt(in);/*w  ww .  j av a 2 s. co m*/

    OpenIntIntHashMap values = new OpenIntIntHashMap();
    int numNonDefaultElements = Varint.readUnsignedVarInt(in);
    for (int i = 0; i < numNonDefaultElements; i++) {
        int index = Varint.readUnsignedVarInt(in);
        double value = laxPrecision ? in.readFloat() : in.readDouble();
        values.put(index, (int) value);
    }
    return values;
}