List of usage examples for java.io DataOutput writeDouble
void writeDouble(double v) throws IOException;
double
value, which is comprised of eight bytes, to the output stream. From source file:org.apache.pig.data.SchemaTuple.java
protected static void write(DataOutput out, double v) throws IOException { out.writeDouble(v); }
From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java
private void writeDenseBlock(DataOutput out) throws IOException { out.writeByte(BlockType.DENSE_BLOCK.ordinal()); int limit = rlen * clen; if (out instanceof MatrixBlockDataOutput) //fast serialize ((MatrixBlockDataOutput) out).writeDoubleArray(limit, denseBlock); else //general case (if fast serialize not supported) for (int i = 0; i < limit; i++) out.writeDouble(denseBlock[i]); }
From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java
private void writeSparseBlock(DataOutput out) throws IOException { out.writeByte(BlockType.SPARSE_BLOCK.ordinal()); writeNnzInfo(out, false);// w w w . ja va 2 s .c o m if (out instanceof MatrixBlockDataOutput) //fast serialize ((MatrixBlockDataOutput) out).writeSparseRows(rlen, sparseBlock); else //general case (if fast serialize not supported) { int r = 0; for (; r < Math.min(rlen, sparseBlock.numRows()); r++) { if (sparseBlock.isEmpty(r)) out.writeInt(0); else { int pos = sparseBlock.pos(r); int nr = sparseBlock.size(r); int[] cols = sparseBlock.indexes(r); double[] values = sparseBlock.values(r); out.writeInt(nr); for (int j = pos; j < pos + nr; j++) { out.writeInt(cols[j]); out.writeDouble(values[j]); } } } for (; r < rlen; r++) out.writeInt(0); } }
From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java
private void writeSparseToUltraSparse(DataOutput out) throws IOException { out.writeByte(BlockType.ULTRA_SPARSE_BLOCK.ordinal()); writeNnzInfo(out, true);//from www. j a v a2 s .c o m long wnnz = 0; if (clen > 1) //ULTRA-SPARSE BLOCK { //block: write ijv-triples for (int r = 0; r < Math.min(rlen, sparseBlock.numRows()); r++) if (!sparseBlock.isEmpty(r)) { int apos = sparseBlock.pos(r); int alen = sparseBlock.size(r); int[] aix = sparseBlock.indexes(r); double[] avals = sparseBlock.values(r); for (int j = apos; j < apos + alen; j++) { //ultra-sparse block: write ijv-triples out.writeInt(r); out.writeInt(aix[j]); out.writeDouble(avals[j]); wnnz++; } } } else //ULTRA-SPARSE COL { //block: write iv-pairs (should never happen since always dense) for (int r = 0; r < Math.min(rlen, sparseBlock.numRows()); r++) if (!sparseBlock.isEmpty(r)) { int pos = sparseBlock.pos(r); out.writeInt(r); out.writeDouble(sparseBlock.values(r)[pos]); wnnz++; } } //validity check (nnz must exactly match written nnz) if (nonZeros != wnnz) { throw new IOException( "Invalid number of serialized non-zeros: " + wnnz + " (expected: " + nonZeros + ")"); } }
From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java
private void writeSparseToDense(DataOutput out) throws IOException { //write block type 'dense' out.writeByte(BlockType.DENSE_BLOCK.ordinal()); //write data (from sparse to dense) if (sparseBlock == null) //empty block for (int i = 0; i < rlen * clen; i++) out.writeDouble(0); else //existing sparse block {/*from w w w . j a v a2s .c o m*/ SparseBlock a = sparseBlock; for (int i = 0; i < rlen; i++) { if (i < a.numRows() && !a.isEmpty(i)) { int apos = a.pos(i); int alen = a.size(i); int[] aix = a.indexes(i); double[] avals = a.values(i); //foreach non-zero value, fill with 0s if required for (int j = 0, j2 = 0; j2 < alen; j++, j2++) { for (; j < aix[apos + j2]; j++) out.writeDouble(0); out.writeDouble(avals[apos + j2]); } //remaining 0 values in row for (int j = aix[apos + alen - 1] + 1; j < clen; j++) out.writeDouble(0); } else //empty row for (int j = 0; j < clen; j++) out.writeDouble(0); } } }
From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java
private void writeDenseToUltraSparse(DataOutput out) throws IOException { out.writeByte(BlockType.ULTRA_SPARSE_BLOCK.ordinal()); writeNnzInfo(out, true);//from w ww . j a v a 2s .c o m long wnnz = 0; if (clen > 1) //ULTRA-SPARSE BLOCK { //block: write ijv-triples for (int r = 0, ix = 0; r < rlen; r++) for (int c = 0; c < clen; c++, ix++) if (denseBlock[ix] != 0) { out.writeInt(r); out.writeInt(c); out.writeDouble(denseBlock[ix]); wnnz++; } } else //ULTRA-SPARSE COL { //col: write iv-pairs for (int r = 0; r < rlen; r++) if (denseBlock[r] != 0) { out.writeInt(r); out.writeDouble(denseBlock[r]); wnnz++; } } //validity check (nnz must exactly match written nnz) if (nonZeros != wnnz) { throw new IOException( "Invalid number of serialized non-zeros: " + wnnz + " (expected: " + nonZeros + ")"); } }
From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java
private void writeDenseToSparse(DataOutput out) throws IOException { out.writeByte(BlockType.SPARSE_BLOCK.ordinal()); //block type writeNnzInfo(out, false);/*from ww w . j a v a 2 s . co m*/ int start = 0; for (int r = 0; r < rlen; r++) { //count nonzeros int nr = 0; for (int i = start; i < start + clen; i++) if (denseBlock[i] != 0.0) nr++; out.writeInt(nr); for (int c = 0; c < clen; c++) { if (denseBlock[start] != 0.0) { out.writeInt(c); out.writeDouble(denseBlock[start]); } start++; } } }
From source file:org.apache.vxquery.jsonparser.JSONParser.java
public void atomicValues(int tag, JsonParser parser, DataOutput out, StringValueBuilder svb, int levelArray, int levelObject) throws IOException { abvsStack.get(0).reset();//from ww w. j a v a 2 s . c o m out.write(tag); if (tag == ValueTag.XS_DOUBLE_TAG) { out.writeDouble(parser.getDoubleValue()); } else if (tag == ValueTag.XS_STRING_TAG) { svb.write(parser.getText(), out); } else if (tag == ValueTag.XS_INTEGER_TAG) { out.writeLong(parser.getLongValue()); } if (!itemStack.isEmpty()) { if (itemStack.get(itemStack.size() - 1) == itemType.ARRAY) { abStack.get(levelArray - 1).addItem(abvsStack.get(0)); if (valueSeq != null && this.matched && levelArray == this.arrayMatchLevel) { this.literal = true; this.matched = false; writeElement(abvsStack.get(0)); } } else if (itemStack.get(itemStack.size() - 1) == itemType.OBJECT) { obStack.get(levelObject - 1).addItem(spStack.get(levelObject - 1), abvsStack.get(0)); if (valueSeq != null && this.matched && levelObject == this.objectMatchLevel) { this.literal = true; this.matched = false; writeElement(abvsStack.get(0)); } } } }
From source file:org.cloudata.core.common.io.CObjectWritable.java
/** Write a {@link CWritable}, {@link String}, primitive type, or an array of * the preceding. *//*from ww w . j av a 2 s . c o m*/ public static void writeObject(DataOutput out, Object instance, Class declaredClass, CloudataConf conf, boolean arrayComponent) throws IOException { if (instance == null) { // null instance = new NullInstance(declaredClass, conf); declaredClass = CWritable.class; arrayComponent = false; } if (!arrayComponent) { CUTF8.writeString(out, declaredClass.getName()); // always write declared //System.out.println("Write:declaredClass.getName():" + declaredClass.getName()); } if (declaredClass.isArray()) { // array int length = Array.getLength(instance); out.writeInt(length); //System.out.println("Write:length:" + length); if (declaredClass.getComponentType() == Byte.TYPE) { out.write((byte[]) instance); } else if (declaredClass.getComponentType() == ColumnValue.class) { //ColumnValue? Deserialize? ?? ? ?? ? . writeColumnValue(out, instance, declaredClass, conf, length); } else { for (int i = 0; i < length; i++) { writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf, !declaredClass.getComponentType().isArray()); } } } else if (declaredClass == String.class) { // String CUTF8.writeString(out, (String) instance); } else if (declaredClass.isPrimitive()) { // primitive type if (declaredClass == Boolean.TYPE) { // boolean out.writeBoolean(((Boolean) instance).booleanValue()); } else if (declaredClass == Character.TYPE) { // char out.writeChar(((Character) instance).charValue()); } else if (declaredClass == Byte.TYPE) { // byte out.writeByte(((Byte) instance).byteValue()); } else if (declaredClass == Short.TYPE) { // short out.writeShort(((Short) instance).shortValue()); } else if (declaredClass == Integer.TYPE) { // int out.writeInt(((Integer) instance).intValue()); } else if (declaredClass == Long.TYPE) { // long out.writeLong(((Long) instance).longValue()); } else if (declaredClass == Float.TYPE) { // float out.writeFloat(((Float) instance).floatValue()); } else if (declaredClass == Double.TYPE) { // double out.writeDouble(((Double) instance).doubleValue()); } else if (declaredClass == Void.TYPE) { // void } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isEnum()) { // enum CUTF8.writeString(out, ((Enum) instance).name()); } else if (CWritable.class.isAssignableFrom(declaredClass)) { // Writable if (instance.getClass() == declaredClass) { out.writeShort(TYPE_SAME); // ? ?? ? ?? //System.out.println("Write:TYPE_SAME:" + TYPE_SAME); } else { out.writeShort(TYPE_DIFF); //System.out.println("Write:TYPE_DIFF:" + TYPE_DIFF); CUTF8.writeString(out, instance.getClass().getName()); //System.out.println("Write:instance.getClass().getName():" + instance.getClass().getName()); } ((CWritable) instance).write(out); //System.out.println("Write:instance value"); } else { throw new IOException("Can't write: " + instance + " as " + declaredClass); } }
From source file:org.mitre.la.mapred.io.DenseVectorWritable.java
/** * Serialize the fields of this object to <code>out</code>. * * @param out <code>DataOuput</code> to serialize this object into. * @throws IOException//from w ww.j a va 2 s . co m */ @Override public void write(DataOutput out) throws IOException { int length = this.dv.getCardinality(); out.writeByte(0); // Space for versioning out.writeUTF(this.dv.getLabel()); out.writeInt(length); for (int i = 0; i < length; i++) { out.writeDouble(this.dv.get(i)); } }