List of usage examples for org.apache.mahout.math Varint readUnsignedVarInt
public static int readUnsignedVarInt(DataInput in) throws IOException
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); 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); }/*from ww w .j av a 2 s .c o m*/ return values; }
From source file:de.tudarmstadt.ukp.dkpro.bigdata.collocations.Gram.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { int newLength = Varint.readUnsignedVarInt(in); setCapacity(newLength, false);// w w w. ja va 2s .c om in.readFully(bytes, 0, newLength); int newFrequency = Varint.readUnsignedVarInt(in); length = newLength; frequency = newFrequency; }
From source file:de.tudarmstadt.ukp.dkpro.bigdata.collocations.GramKey.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { int newLength = Varint.readUnsignedVarInt(in); int newPrimaryLength = Varint.readUnsignedVarInt(in); setCapacity(newLength, false);/*from w w w . j a v a 2 s. co m*/ in.readFully(bytes, 0, newLength); length = newLength; primaryLength = newPrimaryLength; }
From source file:edu.rosehulman.mahout.math.VectorWritable.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { int flags = in.readByte(); //Preconditions.checkArgument(flags >> NUM_FLAGS == 0, "Unknown flags set: %d", Integer.toString(flags, 2)); boolean dense = (flags & FLAG_DENSE) != 0; boolean sequential = (flags & FLAG_SEQUENTIAL) != 0; boolean named = (flags & FLAG_NAMED) != 0; boolean laxPrecision = (flags & FLAG_LAX_PRECISION) != 0; int size = Varint.readUnsignedVarInt(in); Vector v;// ww w . j av a 2 s .co m if (dense) { double[] values = new double[size]; for (int i = 0; i < size; i++) { values[i] = laxPrecision ? in.readFloat() : in.readDouble(); } v = new DenseVector(values); } else { int numNonDefaultElements = Varint.readUnsignedVarInt(in); v = sequential ? new SequentialAccessSparseVector(size, numNonDefaultElements) : new RandomAccessSparseVector(size, numNonDefaultElements); if (sequential) { int lastIndex = 0; for (int i = 0; i < numNonDefaultElements; i++) { int delta = Varint.readUnsignedVarInt(in); int index = lastIndex + delta; lastIndex = index; double value = laxPrecision ? in.readFloat() : in.readDouble(); v.setQuick(index, value); } } else { for (int i = 0; i < numNonDefaultElements; i++) { int index = Varint.readUnsignedVarInt(in); double value = laxPrecision ? in.readFloat() : in.readDouble(); v.setQuick(index, value); } } } if (named) { String name = in.readUTF(); v = new NamedVector(v, name); } vector = v; }
From source file:org.gpfvic.mahout.cf.taste.hadoop.item.VectorAndPrefsWritable.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { VectorWritable writable = new VectorWritable(); writable.readFields(in);/*from ww w . j a va2s.co m*/ vector = writable.get(); int size = Varint.readUnsignedVarInt(in); userIDs = new ArrayList<>(size); values = new ArrayList<>(size); for (int i = 0; i < size; i++) { userIDs.add(Varint.readSignedVarLong(in)); values.add(in.readFloat()); } }