0

I am emitting two 2D double arrays as key and value. I am constructing WritableComparable class.

public class MF implements WritableComparable<MF>{

/**
 * @param args
 */
private double[][] value;

public MF() {
    // TODO Auto-generated constructor stub
}

public MF(double[][] value) {
    // TODO Auto-generated constructor stub

      this.value = new double[value.length][value[0].length];
    // System.out.println("in matrix");
}

public void set(double[][] value) {
      this.value = value;
}

public double[][] getValue() {
        return value;
}

@Override
public void write(DataOutput out) throws IOException {
    System.out.println("write");
    int row=0;
    int column=0;
    for(int i=0; i<value.length;i++) {
        row = value.length;
        for(int j=0; j<value[i].length; j++) {
            column = value[i].length;
        }
    }
    out.writeInt(row);
    out.writeInt(column);

    for(int i=0;i<row ; i++) {
        for(int j= 0 ; j< col;j++) {
            out.writeDouble(value[i][j]);
        }
    }

    for(int i =0;i< value.length ;i ++) {
        for(int j = 0;j <value[0].length;j++) {
            System.out.print(value[i][j]+ "\t");
        }
        System.out.println("");
    }
}

@Override
public void readFields(DataInput in) throws IOException {
    int row = in.readInt();
    int col = in.readInt();

    double[][] value = new double[row][col];
    for(int i=0;i<row ; i++) {
        for(int j= 0 ; j< col;j++) {
            value[i][j] = in.readDouble();
        }
    }
}

@Override
public int hashCode() {

}

@Override
public boolean equals(Object o) {

}

@Override
public int compareTo(MF o) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public String toString() {
    System.out.println(Arrays.toString(value));
    return Arrays.toString(value);
}
}

And half way through, when I tried to print my matrix within write method, the matrix is not having values

write
    0.0 0.0 0.0 
    0.0 0.0 0.0 
    0.0 0.0 0.0 
write
    0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
    0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
    0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 

I am doing something wrong. I am getting apt no of rows and cols.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • not enough information is provided as the error must be within the code that is calling `set` and passing the array. – John B Oct 30 '13 at 10:57
  • yes we are not getting anytype of errors –  Oct 30 '13 at 11:09
  • it is printing output like this only –  Oct 30 '13 at 11:09
  • duplicate: http://stackoverflow.com/questions/19655071/implementing-a-custom-hadoop-key-and-value/19655726?noredirect=1#comment29230096_19655726 – John B Oct 30 '13 at 11:18
  • the array you are passing in contains only `0.0` values. Debug it. – John B Oct 30 '13 at 11:19
  • You was really right JOHN ..it was the problem within set and public MF(double[][] value) . –  Oct 31 '13 at 04:13

0 Answers0