Example usage for org.apache.hadoop.io DoubleWritable readFields

List of usage examples for org.apache.hadoop.io DoubleWritable readFields

Introduction

In this page you can find the example usage for org.apache.hadoop.io DoubleWritable readFields.

Prototype

@Override
    public void readFields(DataInput in) throws IOException 

Source Link

Usage

From source file:HistogramBucket.java

License:Apache License

@Override
public void readFields(DataInput di) throws IOException {
    attribute.readFields(di);//from w ww.  j a v  a  2 s.  c o m
    LongWritable arraySize = new LongWritable();
    arraySize.readFields(di);
    splits = new ArrayList<DoubleWritable>();
    for (int i = 0; i < Integer.parseInt(arraySize.toString()); i++) {
        DoubleWritable d = new DoubleWritable();
        d.readFields(di);
        splits.add(d);
    }
}

From source file:com.ibm.bi.dml.runtime.matrix.sort.ReadWithZeros.java

License:Open Source License

public void readNextKeyValuePairs(DoubleWritable readKey, IntWritable readValue) throws IOException {
    try {//from   www. ja  v a2s .  c o  m
        if (contain0s && justFound0) {
            readKey.set(keyAfterZero.get());
            readValue.set(valueAfterZero.get());
            contain0s = false;
        } else {
            readKey.readFields(currentStream);
            readValue.readFields(currentStream);
        }
    } catch (EOFException e) {
        // case in which zero is the maximum value in the matrix. 
        // The zero value from the last entry is not present in the input sorted matrix, but needs to be accounted for.
        if (contain0s && !justFound0) {
            justFound0 = true;
            readKey.set(0);
            readValue.set((int) numZeros);
        } else {
            throw e;
        }
    }

    if (contain0s && !justFound0 && readKey.get() >= 0) {
        justFound0 = true;
        keyAfterZero.set(readKey.get());
        valueAfterZero.set(readValue.get());
        readKey.set(0);
        readValue.set((int) numZeros);
    }
}

From source file:com.marcolotz.MRComponents.SerializerConverter.java

License:Creative Commons License

/***
 * Reads a double from the input/*from  w w w  . j  av a2  s  . c  o  m*/
 * @param datainput
 * @return the double readen
 * @throws IOException
 */
public static double readDouble(DataInput datainput) throws IOException {
    DoubleWritable readenDouble = new DoubleWritable();
    readenDouble.readFields(datainput);
    return readenDouble.get();
}

From source file:edu.ub.ahstfg.kmeans.document.DocumentCentroid.java

License:Open Source License

@Override
public void readFields(DataInput in) throws IOException {
    ArrayWritable k = new ArrayWritable(IntWritable.class);
    k.readFields(in);/*from  ww  w . ja  va 2 s .c  o m*/
    keywordVector = WritableConverter.arrayWritable2ShortArray(k);
    ArrayWritable t = new ArrayWritable(IntWritable.class);
    t.readFields(in);
    termVector = WritableConverter.arrayWritable2ShortArray(t);
    DoubleWritable dist = new DoubleWritable();
    dist.readFields(in);
    distance = dist.get();
}

From source file:it.uniroma1.bdc.tesi.piccioli.giraphstandalone.ksimplecycle.TextValueAndSetPerSuperstep.java

@Override
public void readFields(DataInput in) throws IOException {
    int size;/*  w ww .  j a v a2s  .  c  o m*/
    //        value.readFields(in);

    size = in.readInt();//Leggo numero di key da inserire nella MAP
    for (int i = 0; i < size; i++) {

        LongWritable key = new LongWritable();
        key.readFields(in);//Leggo Chiave
        DoubleWritable valueh = new DoubleWritable();
        valueh.readFields(in);//Leggo Chiave
        this.setPerSuperstep.put(key, valueh);
    }

    //      
}

From source file:org.apache.sysml.runtime.matrix.sort.ReadWithZeros.java

License:Apache License

public boolean readNextKeyValuePairs(DoubleWritable readKey, IntWritable readValue) throws IOException {
    boolean ret = true;

    try {//from  w w  w . j  av  a  2 s . c o  m
        if (contain0s && justFound0) {
            readKey.set(keyAfterZero.get());
            readValue.set(valueAfterZero.get());
            contain0s = false;
        } else {
            readKey.readFields(currentStream);
            readValue.readFields(currentStream);
        }
    } catch (EOFException e) {
        // case in which zero is the maximum value in the matrix. 
        // The zero value from the last entry is not present in the input sorted matrix, but needs to be accounted for.
        if (contain0s && !justFound0) {
            justFound0 = true;
            readKey.set(0);
            readValue.set((int) numZeros);
        } else {
            ret = false;
        }
    }

    if (contain0s && !justFound0 && readKey.get() >= 0) {
        justFound0 = true;
        keyAfterZero.set(readKey.get());
        valueAfterZero.set(readValue.get());
        readKey.set(0);
        readValue.set((int) numZeros);
    }

    return ret;
}

From source file:org.shaf.core.util.IOUtilsTest.java

License:Apache License

/**
 * Test writing of {@code double} value.
 *//*from  ww  w.j  a va2s . com*/
@Test
public void testWriteDouble() {
    byte[] buf = null;

    double value = 123.456;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(baos);) {
        IOUtils.writeObject(value, out);
        buf = baos.toByteArray();
    } catch (IOException exc) {
        fail(exc.getMessage());
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
            DataInputStream in = new DataInputStream(bais);) {
        DoubleWritable probe = new DoubleWritable();
        probe.readFields(in);
        assertEquals(value, probe.get(), 0.0001);
    } catch (IOException exc) {
        fail(exc.getMessage());
    }
}