Example usage for java.io DataInput readDouble

List of usage examples for java.io DataInput readDouble

Introduction

In this page you can find the example usage for java.io DataInput readDouble.

Prototype

double readDouble() throws IOException;

Source Link

Document

Reads eight input bytes and returns a double value.

Usage

From source file:org.apache.pig.data.SchemaTuple.java

protected static double read(DataInput in, double v) throws IOException {
    return in.readDouble();
}

From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java

private void readDenseBlock(DataInput in) throws IOException, DMLRuntimeException {
    allocateDenseBlock(true); //allocate block, clear nnz

    int limit = rlen * clen;

    if (in instanceof MatrixBlockDataInput) //fast deserialize
    {/*from w w w  . ja  v  a 2s .  c  o m*/
        MatrixBlockDataInput mbin = (MatrixBlockDataInput) in;
        nonZeros = mbin.readDoubleArray(limit, denseBlock);
    } else if (in instanceof DataInputBuffer && MRJobConfiguration.USE_BINARYBLOCK_SERIALIZATION) {
        //workaround because sequencefile.reader.next(key, value) does not yet support serialization framework
        DataInputBuffer din = (DataInputBuffer) in;
        MatrixBlockDataInput mbin = new FastBufferedDataInputStream(din);
        nonZeros = mbin.readDoubleArray(limit, denseBlock);
        ((FastBufferedDataInputStream) mbin).close();
    } else //default deserialize
    {
        for (int i = 0; i < limit; i++) {
            denseBlock[i] = in.readDouble();
            if (denseBlock[i] != 0)
                nonZeros++;
        }
    }
}

From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java

private void readSparseBlock(DataInput in) throws IOException {
    allocateSparseRowsBlock(false);/*ww w .  j  a  v a 2s .c o m*/
    resetSparse(); //reset all sparse rows

    if (in instanceof MatrixBlockDataInput) //fast deserialize
    {
        MatrixBlockDataInput mbin = (MatrixBlockDataInput) in;
        nonZeros = mbin.readSparseRows(rlen, sparseBlock);
    } else if (in instanceof DataInputBuffer && MRJobConfiguration.USE_BINARYBLOCK_SERIALIZATION) {
        //workaround because sequencefile.reader.next(key, value) does not yet support serialization framework
        DataInputBuffer din = (DataInputBuffer) in;
        MatrixBlockDataInput mbin = new FastBufferedDataInputStream(din);
        nonZeros = mbin.readSparseRows(rlen, sparseBlock);
        ((FastBufferedDataInputStream) mbin).close();
    } else //default deserialize
    {
        for (int r = 0; r < rlen; r++) {
            int rnnz = in.readInt(); //row nnz
            if (rnnz > 0) {
                sparseBlock.reset(r, rnnz, clen);
                for (int j = 0; j < rnnz; j++) //col index/value pairs
                    sparseBlock.append(r, in.readInt(), in.readDouble());
            }
        }
    }
}

From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java

private void readSparseToDense(DataInput in) throws IOException, DMLRuntimeException {
    allocateDenseBlock(false); //allocate block
    Arrays.fill(denseBlock, 0);/*from   w  ww. j a v  a2 s . c o  m*/

    for (int r = 0; r < rlen; r++) {
        int nr = in.readInt();
        for (int j = 0; j < nr; j++) {
            int c = in.readInt();
            double val = in.readDouble();
            denseBlock[r * clen + c] = val;
        }
    }
}

From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java

private void readUltraSparseBlock(DataInput in) throws IOException {
    allocateSparseRowsBlock(false); //adjust to size
    resetSparse(); //reset all sparse rows

    if (clen > 1) //ULTRA-SPARSE BLOCK
    {//w  w w  .ja  v a  2 s .c o  m
        //block: read ijv-triples
        for (long i = 0; i < nonZeros; i++) {
            int r = in.readInt();
            int c = in.readInt();
            double val = in.readDouble();
            sparseBlock.allocate(r, 1, clen);
            sparseBlock.append(r, c, val);
        }
    } else //ULTRA-SPARSE COL
    {
        //col: read iv-pairs (should never happen since always dense)
        for (long i = 0; i < nonZeros; i++) {
            int r = in.readInt();
            double val = in.readDouble();
            sparseBlock.allocate(r, 1, 1);
            sparseBlock.append(r, 0, val);
        }
    }
}

From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java

private void readUltraSparseToDense(DataInput in) throws IOException, DMLRuntimeException {
    allocateDenseBlock(false); //allocate block
    Arrays.fill(denseBlock, 0);//from w w w  .j  a v  a  2s. c  om

    if (clen > 1) //ULTRA-SPARSE BLOCK
    {
        //block: read ijv-triples
        for (long i = 0; i < nonZeros; i++) {
            int r = in.readInt();
            int c = in.readInt();
            double val = in.readDouble();
            denseBlock[r * clen + c] = val;
        }
    } else //ULTRA-SPARSE COL
    {
        //col: read iv-pairs
        for (long i = 0; i < nonZeros; i++) {
            int r = in.readInt();
            double val = in.readDouble();
            denseBlock[r] = val;
        }
    }
}

From source file:org.cloudata.core.common.io.CObjectWritable.java

/** Read a {@link CWritable}, {@link String}, primitive type, or an array of
 * the preceding. *///from w  w  w.j a va 2s .  co  m
@SuppressWarnings("unchecked")
public static Object readObject(DataInput in, CObjectWritable objectWritable, CloudataConf conf,
        boolean arrayComponent, Class componentClass) throws IOException {
    String className;
    if (arrayComponent) {
        className = componentClass.getName();
    } else {
        className = CUTF8.readString(in);
        //SANGCHUL
        //   System.out.println("SANGCHUL] className:" + className);
    }

    Class<?> declaredClass = PRIMITIVE_NAMES.get(className);
    if (declaredClass == null) {
        try {
            declaredClass = conf.getClassByName(className);
        } catch (ClassNotFoundException e) {
            //SANGCHUL
            e.printStackTrace();
            throw new RuntimeException("readObject can't find class[className=" + className + "]", e);
        }
    }

    Object instance;

    if (declaredClass.isPrimitive()) { // primitive types

        if (declaredClass == Boolean.TYPE) { // boolean
            instance = Boolean.valueOf(in.readBoolean());
        } else if (declaredClass == Character.TYPE) { // char
            instance = Character.valueOf(in.readChar());
        } else if (declaredClass == Byte.TYPE) { // byte
            instance = Byte.valueOf(in.readByte());
        } else if (declaredClass == Short.TYPE) { // short
            instance = Short.valueOf(in.readShort());
        } else if (declaredClass == Integer.TYPE) { // int
            instance = Integer.valueOf(in.readInt());
        } else if (declaredClass == Long.TYPE) { // long
            instance = Long.valueOf(in.readLong());
        } else if (declaredClass == Float.TYPE) { // float
            instance = Float.valueOf(in.readFloat());
        } else if (declaredClass == Double.TYPE) { // double
            instance = Double.valueOf(in.readDouble());
        } else if (declaredClass == Void.TYPE) { // void
            instance = null;
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }

    } else if (declaredClass.isArray()) { // array
        //System.out.println("SANGCHUL] is array");
        int length = in.readInt();
        //System.out.println("SANGCHUL] array length : " + length);
        //System.out.println("Read:in.readInt():" + length);
        if (declaredClass.getComponentType() == Byte.TYPE) {
            byte[] bytes = new byte[length];
            in.readFully(bytes);
            instance = bytes;
        } else if (declaredClass.getComponentType() == ColumnValue.class) {
            instance = readColumnValue(in, conf, declaredClass, length);
        } else {
            Class componentType = declaredClass.getComponentType();

            // SANGCHUL
            //System.out.println("SANGCHUL] componentType : " + componentType.getName());

            instance = Array.newInstance(componentType, length);
            for (int i = 0; i < length; i++) {
                Object arrayComponentInstance = readObject(in, null, conf, !componentType.isArray(),
                        componentType);
                Array.set(instance, i, arrayComponentInstance);
                //Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass == String.class) { // String
        instance = CUTF8.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, CUTF8.readString(in));
    } else if (declaredClass == ColumnValue.class) {
        //ColumnValue?  ?? ?? ?  ? ?.
        //? ?   ? ? ? ? . 
        Class instanceClass = null;
        try {
            short typeDiff = in.readShort();
            if (typeDiff == TYPE_DIFF) {
                instanceClass = conf.getClassByName(CUTF8.readString(in));
            } else {
                instanceClass = declaredClass;
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("readObject can't find class", e);
        }
        ColumnValue columnValue = new ColumnValue();
        columnValue.readFields(in);
        instance = columnValue;
    } else { // Writable

        Class instanceClass = null;
        try {
            short typeDiff = in.readShort();
            // SANGCHUL
            //System.out.println("SANGCHUL] typeDiff : " + typeDiff);
            //System.out.println("Read:in.readShort():" + typeDiff);
            if (typeDiff == TYPE_DIFF) {
                // SANGCHUL
                String classNameTemp = CUTF8.readString(in);
                //System.out.println("SANGCHUL] typeDiff : " + classNameTemp);
                instanceClass = conf.getClassByName(classNameTemp);
                //System.out.println("Read:UTF8.readString(in):" + instanceClass.getClass());
            } else {
                instanceClass = declaredClass;
            }
        } catch (ClassNotFoundException e) {

            // SANGCHUL
            e.printStackTrace();
            throw new RuntimeException("readObject can't find class", e);
        }

        CWritable writable = CWritableFactories.newInstance(instanceClass, conf);
        writable.readFields(in);
        //System.out.println("Read:writable.readFields(in)");
        instance = writable;

        if (instanceClass == NullInstance.class) { // null
            declaredClass = ((NullInstance) instance).declaredClass;
            instance = null;
        }
    }

    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }

    return instance;
}

From source file:org.mitre.la.mapred.io.DenseVectorWritable.java

/**
 * Deserialize the fields of this object from <code>in</code>.
 *
 * @param in <code>DataInput</code> to deseriablize this object from.
 * @throws IOException/* w w w. j a v a2  s  .  c om*/
 */
@Override
public void readFields(DataInput in) throws IOException {
    in.readByte();
    String label = in.readUTF();
    int length = in.readInt();
    double[] v = new double[length];
    for (int i = 0; i < length; i++) {
        v[i] = in.readDouble();
    }
    this.dv = new DenseVector(label, v);
}