// Path: LUDecomposition/src/lud/Utils.java
// public class Utils {
// 	
// 	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;
//     }
// 	
// 	public static Double[] stringToDoubleArray(String[] a) {
// 		Double[] x = new Double[a.length];
// 		for(int i = 0; i < a.length ; i++)
// 			x[i] = Double.valueOf(a[i]);
// 		return x;
// 	}
// 
// 	public static void storeToHDFS(String data, String output, Configuration conf) throws IOException {
// 		
// 		FileSystem hdfs=FileSystem.get(conf);
// 		Path find_nth_row_output_path = new Path(conf.get("find_nth_row_output"));
// 		try {
// 		    if (hdfs.exists(find_nth_row_output_path)) {
// 		        hdfs.delete(find_nth_row_output_path, true);
// 		    }
// 		    DataOutputStream outStream = hdfs.create(find_nth_row_output_path);
// 		    BufferedWriter bw = new BufferedWriter( new OutputStreamWriter(outStream, "UTF-8" ) );
// 		    bw.write(data);
// 		    bw.close();
// 		    hdfs.close();
// 		    outStream.close();
// 		}
// 		catch (Exception e) {
// 			System.out.println(e.getMessage());
// 		}
// 	}
// 
// 	public static String readFromHDFS(String path, Configuration conf) throws IOException {
// 		
// 		FileSystem hdfs=FileSystem.get(conf);
// 		BufferedReader br = new BufferedReader(new InputStreamReader(hdfs.open(new Path(path))));
// 		String records = br.readLine().trim();
// 		br.close();
// 		hdfs.close();
// 		
// 		return records;
// 	}
// }
// 
// Path: LUDecomposition/src/lud/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 java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import lud.Utils;
import lud.io.TextPair;
			
		}
		catch (Exception e) {
			System.out.println("Can't read nth value! " + e.getMessage());
			return null;
		}
	}
	
	@Override
	public void setup (Context context) throws IOException, InterruptedException {
		Configuration conf = context.getConfiguration();
		this.n = (int) conf.getLong("n", 0);
		// The below code should have worked, but it does not
		//if (n>0)
		//	this.nVal = Utils.arrayToCSV(readNthRow(context.getConfiguration()));
	}
	
	public void map(Text key, Text value, Context context) throws IOException, InterruptedException {
		
		if (counter == 0 && !key.toString().contains(","))
			this.input_range[0] = Long.valueOf(key.toString());

		if (!key.toString().contains(",")) {
			int row = Integer.parseInt(key.toString());
			
			if (row == this.n)
				this.nVal = value.toString();
			
			if (n > 0)
				//context.write(key, new Text(value.toString()+";"+this.nVal));
// Path: LUDecomposition/src/lud/Utils.java
// public class Utils {
// 	
// 	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;
//     }
// 	
// 	public static Double[] stringToDoubleArray(String[] a) {
// 		Double[] x = new Double[a.length];
// 		for(int i = 0; i < a.length ; i++)
// 			x[i] = Double.valueOf(a[i]);
// 		return x;
// 	}
// 
// 	public static void storeToHDFS(String data, String output, Configuration conf) throws IOException {
// 		
// 		FileSystem hdfs=FileSystem.get(conf);
// 		Path find_nth_row_output_path = new Path(conf.get("find_nth_row_output"));
// 		try {
// 		    if (hdfs.exists(find_nth_row_output_path)) {
// 		        hdfs.delete(find_nth_row_output_path, true);
// 		    }
// 		    DataOutputStream outStream = hdfs.create(find_nth_row_output_path);
// 		    BufferedWriter bw = new BufferedWriter( new OutputStreamWriter(outStream, "UTF-8" ) );
// 		    bw.write(data);
// 		    bw.close();
// 		    hdfs.close();
// 		    outStream.close();
// 		}
// 		catch (Exception e) {
// 			System.out.println(e.getMessage());
// 		}
// 	}
// 
// 	public static String readFromHDFS(String path, Configuration conf) throws IOException {
// 		
// 		FileSystem hdfs=FileSystem.get(conf);
// 		BufferedReader br = new BufferedReader(new InputStreamReader(hdfs.open(new Path(path))));
// 		String records = br.readLine().trim();
// 		br.close();
// 		hdfs.close();
// 		
// 		return records;
// 	}
// }
// 
// Path: LUDecomposition/src/lud/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: LUDecomposition/src/lud/naiveGaussian/initial_input_mapper.java
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import lud.Utils;
import lud.io.TextPair;

			
		}
		catch (Exception e) {
			System.out.println("Can't read nth value! " + e.getMessage());
			return null;
		}
	}
	
	@Override
	public void setup (Context context) throws IOException, InterruptedException {
		Configuration conf = context.getConfiguration();
		this.n = (int) conf.getLong("n", 0);
		// The below code should have worked, but it does not
		//if (n>0)
		//	this.nVal = Utils.arrayToCSV(readNthRow(context.getConfiguration()));
	}
	
	public void map(Text key, Text value, Context context) throws IOException, InterruptedException {
		
		if (counter == 0 && !key.toString().contains(","))
			this.input_range[0] = Long.valueOf(key.toString());

		if (!key.toString().contains(",")) {
			int row = Integer.parseInt(key.toString());
			
			if (row == this.n)
				this.nVal = value.toString();
			
			if (n > 0)
				//context.write(key, new Text(value.toString()+";"+this.nVal));
				toBeSent.add(new TextPair(key.toString(), value.toString()));