// Path: lu_decomposition/src/lu_decomposition/naive_gausssian/lud_mapper.java
// public class lud_mapper extends Mapper<LongWritable, Text, Text, Text> {
// 	
// 	private int n;
// 	private Double[] nVal;
// 	private int total_records;
// 	
// 	public Double[] stringToDoubleArray(String[] a) {
// 		
// 		Double[] x = new Double[a.length];
// 		
// 		for(int i = 0; i < this.total_records; i++) {
// 			x[i] = Double.valueOf(a[i]);
// 		}
// 		
// 		return x;
// 		
// 	}
// 	
// 	public static String arrayToCSV(Double[] nVal2) {
//         String result = "";
// 
//         if (nVal2.length > 0) {
//             StringBuilder sb = new StringBuilder();
// 
//             for (Double s : nVal2) {
//                 sb.append(s).append(",");
//             }
// 
//             result = sb.deleteCharAt(sb.length() - 1).toString();
//         }
//         return result;
//     }
// 	
// 	@Override
// 	public void setup (Context context) throws IOException, InterruptedException {
// 		this.n = (int) context.getConfiguration().getLong("n", 0);
// 		this.total_records = (int) context.getConfiguration().getLong("total_records", 0);
// 		this.nVal =  stringToDoubleArray(context.getConfiguration().get("nVal").split(","));
// 		
// 		context.write(new Text(String.valueOf(this.n)), new Text(arrayToCSV(this.nVal)));
// 	}
// 	
// 	public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
// 		String[] parts = value.toString().split("\\t");
// 		if(!parts[0].contains(",")) {
// 			long row = Long.valueOf(parts[0]);
// 			if (row > this.n) {
// 				Double[] rowElements = stringToDoubleArray(parts[1].split(","));
// 				Double multiplier = (double) (rowElements[this.n]/this.nVal[this.n]);
// 				context.write(new Text(row+","+this.n), new Text(String.valueOf(multiplier)));
// 				Double[] rowElementsModified = new Double[this.total_records];
// 				for (int i = 0; i< this.total_records; i++) {
// 					rowElementsModified[i] = (Double) (rowElements[i] - this.nVal[i]*multiplier);
// 				}
// 				if (row != 0)
// 					context.write(new Text(String.valueOf(row)), new Text(arrayToCSV(rowElementsModified)));
// 			}
// 			else {
// 				if (Long.valueOf(parts[0]) != this.n)
// 					context.write(new Text(parts[0]), new Text(parts[1]));
// 			}
// 		}
// 	}
// 
// }
// 
// Path: lu_decomposition/src/lu_decomposition/naive_gausssian/io/TextPair.java
// public class TextPair implements WritableComparable<TextPair> {
// 	
// 	private String t1;
// 	private String t2;
// 	
// 	public String getFirst() {
// 		return this.t1;
// 	}
// 	
// 	public String getSecond() {
// 		return this.t2;
// 	}
// 
// 	@Override
// 	public void readFields(DataInput in) throws IOException {
// 		this.t1 = in.readUTF();
// 		this.t2 = in.readUTF();
// 	}
// 
// 	@Override
// 	public void write(DataOutput out) throws IOException {
// 		out.writeUTF(this.t1);
// 		out.writeUTF(this.t2);
// 	}
// 	
// 	public TextPair() {
//         this.t1 = new String();
//         this.t2 = new String();
//     }
// 	
// 	public TextPair(String t1, String t2) {
//         this.t1 = new String(t1);
//         this.t2 = new String(t2);
//     }
// 	
// 	public int compareTo(TextPair tp) {
//         int sortKey = this.t1.compareTo(tp.getFirst());
//         if (sortKey == 0) {
//         	sortKey = this.t2.compareTo(tp.getSecond());
//         }
//         return sortKey;
//     }
// 	
// 	public String toString () {
// 		String s = "";
// 		if (this.t2.compareTo("") == 0) {
// 			s += this.t1;
// 		}
// 		else {
// 			s += this.t1 + "," + this.t2;
// 		}
// 		return s;
// 	}
// 	
// }


import java.io.IOException;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import lu_decomposition.naive_gausssian.lud_mapper;
import lu_decomposition.naive_gausssian.io.TextPair;
package lu_decomposition.naive_gausssian.MergeResults;




public class merge_results_reducer extends Reducer<TextPair, Text, TextPair, Text> {
	
	private Boolean upper;
	private int total_records;
	
	@Override
	public void setup (Context context) {
		this.upper = context.getConfiguration().getBoolean("upper", false);
		this.total_records = (int) context.getConfiguration().getLong("total_records", 0);
	}
	
	public static String arrayToCSV(String[] a) {
        String result = "";
        if (a.length > 0) {
            StringBuilder sb = new StringBuilder();
            for (String s : a) {
                sb.append(s).append(",");
            }
// Path: lu_decomposition/src/lu_decomposition/naive_gausssian/lud_mapper.java
// public class lud_mapper extends Mapper<LongWritable, Text, Text, Text> {
// 	
// 	private int n;
// 	private Double[] nVal;
// 	private int total_records;
// 	
// 	public Double[] stringToDoubleArray(String[] a) {
// 		
// 		Double[] x = new Double[a.length];
// 		
// 		for(int i = 0; i < this.total_records; i++) {
// 			x[i] = Double.valueOf(a[i]);
// 		}
// 		
// 		return x;
// 		
// 	}
// 	
// 	public static String arrayToCSV(Double[] nVal2) {
//         String result = "";
// 
//         if (nVal2.length > 0) {
//             StringBuilder sb = new StringBuilder();
// 
//             for (Double s : nVal2) {
//                 sb.append(s).append(",");
//             }
// 
//             result = sb.deleteCharAt(sb.length() - 1).toString();
//         }
//         return result;
//     }
// 	
// 	@Override
// 	public void setup (Context context) throws IOException, InterruptedException {
// 		this.n = (int) context.getConfiguration().getLong("n", 0);
// 		this.total_records = (int) context.getConfiguration().getLong("total_records", 0);
// 		this.nVal =  stringToDoubleArray(context.getConfiguration().get("nVal").split(","));
// 		
// 		context.write(new Text(String.valueOf(this.n)), new Text(arrayToCSV(this.nVal)));
// 	}
// 	
// 	public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
// 		String[] parts = value.toString().split("\\t");
// 		if(!parts[0].contains(",")) {
// 			long row = Long.valueOf(parts[0]);
// 			if (row > this.n) {
// 				Double[] rowElements = stringToDoubleArray(parts[1].split(","));
// 				Double multiplier = (double) (rowElements[this.n]/this.nVal[this.n]);
// 				context.write(new Text(row+","+this.n), new Text(String.valueOf(multiplier)));
// 				Double[] rowElementsModified = new Double[this.total_records];
// 				for (int i = 0; i< this.total_records; i++) {
// 					rowElementsModified[i] = (Double) (rowElements[i] - this.nVal[i]*multiplier);
// 				}
// 				if (row != 0)
// 					context.write(new Text(String.valueOf(row)), new Text(arrayToCSV(rowElementsModified)));
// 			}
// 			else {
// 				if (Long.valueOf(parts[0]) != this.n)
// 					context.write(new Text(parts[0]), new Text(parts[1]));
// 			}
// 		}
// 	}
// 
// }
// 
// Path: lu_decomposition/src/lu_decomposition/naive_gausssian/io/TextPair.java
// public class TextPair implements WritableComparable<TextPair> {
// 	
// 	private String t1;
// 	private String t2;
// 	
// 	public String getFirst() {
// 		return this.t1;
// 	}
// 	
// 	public String getSecond() {
// 		return this.t2;
// 	}
// 
// 	@Override
// 	public void readFields(DataInput in) throws IOException {
// 		this.t1 = in.readUTF();
// 		this.t2 = in.readUTF();
// 	}
// 
// 	@Override
// 	public void write(DataOutput out) throws IOException {
// 		out.writeUTF(this.t1);
// 		out.writeUTF(this.t2);
// 	}
// 	
// 	public TextPair() {
//         this.t1 = new String();
//         this.t2 = new String();
//     }
// 	
// 	public TextPair(String t1, String t2) {
//         this.t1 = new String(t1);
//         this.t2 = new String(t2);
//     }
// 	
// 	public int compareTo(TextPair tp) {
//         int sortKey = this.t1.compareTo(tp.getFirst());
//         if (sortKey == 0) {
//         	sortKey = this.t2.compareTo(tp.getSecond());
//         }
//         return sortKey;
//     }
// 	
// 	public String toString () {
// 		String s = "";
// 		if (this.t2.compareTo("") == 0) {
// 			s += this.t1;
// 		}
// 		else {
// 			s += this.t1 + "," + this.t2;
// 		}
// 		return s;
// 	}
// 	
// }


// Path: lu_decomposition/src/lu_decomposition/naive_gausssian/MergeResults/merge_results_reducer.java
import java.io.IOException;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import lu_decomposition.naive_gausssian.lud_mapper;
import lu_decomposition.naive_gausssian.io.TextPair;

package lu_decomposition.naive_gausssian.MergeResults;




public class merge_results_reducer extends Reducer<TextPair, Text, TextPair, Text> {
	
	private Boolean upper;
	private int total_records;
	
	@Override
	public void setup (Context context) {
		this.upper = context.getConfiguration().getBoolean("upper", false);
		this.total_records = (int) context.getConfiguration().getLong("total_records", 0);
	}
	
	public static String arrayToCSV(String[] a) {
        String result = "";
        if (a.length > 0) {
            StringBuilder sb = new StringBuilder();
            for (String s : a) {
                sb.append(s).append(",");
            }
            result = sb.deleteCharAt(sb.length() - 1).toString();