You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by mb...@apache.org on 2017/02/27 18:36:08 UTC

[6/9] incubator-systemml git commit: [SYSTEMML-1286] Code generator compiler integration, incl tests

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/Algorithm_MLogreg.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/Algorithm_MLogreg.dml b/src/test/scripts/functions/codegen/Algorithm_MLogreg.dml
new file mode 100644
index 0000000..88c05d9
--- /dev/null
+++ b/src/test/scripts/functions/codegen/Algorithm_MLogreg.dml
@@ -0,0 +1,274 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X = read($1)
+Y_vec = read($2)
+intercept = $3;
+tol = $4;
+maxiter = $5;
+
+intercept_status = intercept;
+regularization = 0.001;
+maxinneriter = 0;
+
+print ("BEGIN MULTINOMIAL LOGISTIC REGRESSION SCRIPT");
+
+eta0 = 0.0001;
+eta1 = 0.25;
+eta2 = 0.75;
+sigma1 = 0.25;
+sigma2 = 0.5;
+sigma3 = 4.0;
+psi = 0.1;
+
+N = nrow (X);
+D = ncol (X);
+
+# Introduce the intercept, shift and rescale the columns of X if needed
+if (intercept_status == 1 | intercept_status == 2)  # add the intercept column
+{
+    X = append (X, matrix (1, rows = N, cols = 1));
+    D = ncol (X);
+}
+
+scale_lambda = matrix (1, rows = D, cols = 1);
+if (intercept_status == 1 | intercept_status == 2)
+{
+    scale_lambda [D, 1] = 0;
+}
+
+if (intercept_status == 2)  # scale-&-shift X columns to mean 0, variance 1
+{                           # Important assumption: X [, D] = matrix (1, rows = N, cols = 1)
+    avg_X_cols = t(colSums(X)) / N;
+    var_X_cols = (t(colSums (X ^ 2)) - N * (avg_X_cols ^ 2)) / (N - 1);
+    is_unsafe = ppred (var_X_cols, 0.0, "<=");
+    scale_X = 1.0 / sqrt (var_X_cols * (1 - is_unsafe) + is_unsafe);
+    scale_X [D, 1] = 1;
+    shift_X = - avg_X_cols * scale_X;
+    shift_X [D, 1] = 0;
+    rowSums_X_sq = (X ^ 2) %*% (scale_X ^ 2) + X %*% (2 * scale_X * shift_X) + sum (shift_X ^ 2);
+} else {
+    scale_X = matrix (1, rows = D, cols = 1);
+    shift_X = matrix (0, rows = D, cols = 1);
+    rowSums_X_sq = rowSums (X ^ 2);
+}
+
+# Henceforth we replace "X" with "X %*% (SHIFT/SCALE TRANSFORM)" and rowSums(X ^ 2)
+# with "rowSums_X_sq" in order to preserve the sparsity of X under shift and scale.
+# The transform is then associatively applied to the other side of the expression,
+# and is rewritten via "scale_X" and "shift_X" as follows:
+#
+# ssX_A  = (SHIFT/SCALE TRANSFORM) %*% A    --- is rewritten as:
+# ssX_A  = diag (scale_X) %*% A;
+# ssX_A [D, ] = ssX_A [D, ] + t(shift_X) %*% A;
+#
+# tssX_A = t(SHIFT/SCALE TRANSFORM) %*% A   --- is rewritten as:
+# tssX_A = diag (scale_X) %*% A + shift_X %*% A [D, ];
+
+# Convert "Y_vec" into indicator matrice:
+max_y = max (Y_vec);
+if (min (Y_vec) <= 0) { 
+    # Category labels "0", "-1" etc. are converted into the largest label
+    Y_vec  = Y_vec  + (- Y_vec  + max_y + 1) * (Y_vec <= 0);
+    max_y = max_y + 1;
+}
+Y = table (seq (1, N, 1), Y_vec, N, max_y);
+K = ncol (Y) - 1;   # The number of  non-baseline categories
+
+
+lambda = (scale_lambda %*% matrix (1, rows = 1, cols = K)) * regularization;
+delta = 0.5 * sqrt (D) / max (sqrt (rowSums_X_sq));
+
+B = matrix (0, rows = D, cols = K);     ### LT = X %*% (SHIFT/SCALE TRANSFORM) %*% B;
+                                        ### LT = append (LT, matrix (0, rows = N, cols = 1));
+                                        ### LT = LT - rowMaxs (LT) %*% matrix (1, rows = 1, cols = K+1);
+P = matrix (1, rows = N, cols = K+1);   ### exp_LT = exp (LT);
+P = P / (K + 1);                        ### P =  exp_LT / (rowSums (exp_LT) %*% matrix (1, rows = 1, cols = K+1));
+obj = N * log (K + 1);                  ### obj = - sum (Y * LT) + sum (log (rowSums (exp_LT))) + 0.5 * sum (lambda * (B_new ^ 2));
+
+Grad = t(X) %*% (P [, 1:K] - Y [, 1:K]);
+if (intercept_status == 2) {
+    Grad = diag (scale_X) %*% Grad + shift_X %*% Grad [D, ];
+}
+Grad = Grad + lambda * B;
+norm_Grad = sqrt (sum (Grad ^ 2));
+norm_Grad_initial = norm_Grad;
+
+if (maxinneriter == 0) {
+    maxinneriter = D * K;
+}
+iter = 1;
+
+# boolean for convergence check
+converge = (norm_Grad < tol) | (iter > maxiter);
+
+print ("-- Initially:  Objective = " + obj + ",  Gradient Norm = " + norm_Grad + ",  Trust Delta = " + delta);
+
+while (! converge)
+{
+	# SOLVE TRUST REGION SUB-PROBLEM
+	S = matrix (0, rows = D, cols = K);
+	R = - Grad;
+	V = R;
+	delta2 = delta ^ 2;
+	inneriter = 1;
+	norm_R2 = sum (R ^ 2);
+	innerconverge = (sqrt (norm_R2) <= psi * norm_Grad);
+	is_trust_boundary_reached = 0;
+
+	while (! innerconverge)
+	{
+	    if (intercept_status == 2) {
+	        ssX_V = diag (scale_X) %*% V;
+	        ssX_V [D, ] = ssX_V [D, ] + t(shift_X) %*% V;
+	    } else {
+	        ssX_V = V;
+	    }
+        Q = P [, 1:K] * (X %*% ssX_V);
+        HV = t(X) %*% (Q - P [, 1:K] * (rowSums (Q) %*% matrix (1, rows = 1, cols = K)));
+        if (intercept_status == 2) {
+            HV = diag (scale_X) %*% HV + shift_X %*% HV [D, ];
+        }
+        HV = HV + lambda * V;
+		alpha = norm_R2 / sum (V * HV);
+		Snew = S + alpha * V;
+		norm_Snew2 = sum (Snew ^ 2);
+		if (norm_Snew2 <= delta2)
+		{
+			S = Snew;
+			R = R - alpha * HV;
+			old_norm_R2 = norm_R2 
+			norm_R2 = sum (R ^ 2);
+			V = R + (norm_R2 / old_norm_R2) * V;
+			innerconverge = (sqrt (norm_R2) <= psi * norm_Grad);
+		} else {
+	        is_trust_boundary_reached = 1;
+			sv = sum (S * V);
+			v2 = sum (V ^ 2);
+			s2 = sum (S ^ 2);
+			rad = sqrt (sv ^ 2 + v2 * (delta2 - s2));
+			if (sv >= 0) {
+				alpha = (delta2 - s2) / (sv + rad);
+			} else {
+				alpha = (rad - sv) / v2;
+			}
+			S = S + alpha * V;
+			R = R - alpha * HV;
+			innerconverge = TRUE;
+		}
+	    inneriter = inneriter + 1;
+	    innerconverge = innerconverge | (inneriter > maxinneriter);
+	}  
+	
+	# END TRUST REGION SUB-PROBLEM
+	
+	# compute rho, update B, obtain delta
+	gs = sum (S * Grad);
+	qk = - 0.5 * (gs - sum (S * R));
+	B_new = B + S;
+	if (intercept_status == 2) {
+	    ssX_B_new = diag (scale_X) %*% B_new;
+	    ssX_B_new [D, ] = ssX_B_new [D, ] + t(shift_X) %*% B_new;
+    } else {
+        ssX_B_new = B_new;
+    }
+    
+    LT = append ((X %*% ssX_B_new), matrix (0, rows = N, cols = 1));
+    LT = LT - rowMaxs (LT) %*% matrix (1, rows = 1, cols = K+1);
+    exp_LT = exp (LT);
+    P_new  = exp_LT / (rowSums (exp_LT) %*% matrix (1, rows = 1, cols = K+1));
+    obj_new = - sum (Y * LT) + sum (log (rowSums (exp_LT))) + 0.5 * sum (lambda * (B_new ^ 2));
+    	
+	# Consider updating LT in the inner loop
+	# Consider the big "obj" and "obj_new" rounding-off their small difference below:
+
+	actred = (obj - obj_new);
+	
+	rho = actred / qk;
+	is_rho_accepted = (rho > eta0);
+	snorm = sqrt (sum (S ^ 2));
+
+	if (iter == 1) {
+	   delta = min (delta, snorm);
+	}
+
+	alpha2 = obj_new - obj - gs;
+	if (alpha2 <= 0) {
+	   alpha = sigma3;
+	} 
+	else {
+	   alpha = max (sigma1, -0.5 * gs / alpha2);
+	}
+	
+	if (rho < eta0) {
+		delta = min (max (alpha, sigma1) * snorm, sigma2 * delta);
+	}
+	else {
+		if (rho < eta1) {
+			delta = max (sigma1 * delta, min (alpha * snorm, sigma2 * delta));
+		}
+		else { 
+			if (rho < eta2) {
+				delta = max (sigma1 * delta, min (alpha * snorm, sigma3 * delta));
+			}
+			else {
+				delta = max (delta, min (alpha * snorm, sigma3 * delta));
+			}
+		}
+	} 
+	
+	if (is_trust_boundary_reached == 1)
+	{
+	    print ("-- Outer Iteration " + iter + ": Had " + (inneriter - 1) + " CG iterations, trust bound REACHED");
+	} else {
+	    print ("-- Outer Iteration " + iter + ": Had " + (inneriter - 1) + " CG iterations");
+	}
+	print ("   -- Obj.Reduction:  Actual = " + actred + ",  Predicted = " + qk + 
+	       "  (A/P: " + (round (10000.0 * rho) / 10000.0) + "),  Trust Delta = " + delta);
+	       
+	if (is_rho_accepted)
+	{
+		B = B_new;
+		P = P_new;
+		Grad = t(X) %*% (P [, 1:K] - Y [, 1:K]);
+		if (intercept_status == 2) {
+		    Grad = diag (scale_X) %*% Grad + shift_X %*% Grad [D, ];
+		}
+		Grad = Grad + lambda * B;
+		norm_Grad = sqrt (sum (Grad ^ 2));
+		obj = obj_new;
+	    print ("   -- New Objective = " + obj + ",  Beta Change Norm = " + snorm + ",  Gradient Norm = " + norm_Grad);
+	} 
+	
+	iter = iter + 1;
+	converge = ((norm_Grad < (tol * norm_Grad_initial)) | (iter > maxiter) |
+	    ((is_trust_boundary_reached == 0) & (abs (actred) < (abs (obj) + abs (obj_new)) * 0.00000000000001)));
+    if (converge) { print ("Termination / Convergence condition satisfied."); } else { print (" "); }
+} 
+
+if (intercept_status == 2) {
+    B_out = diag (scale_X) %*% B;
+    B_out [D, ] = B_out [D, ] + t(shift_X) %*% B;
+} else {
+    B_out = B;
+}
+write (B_out, $6);
+

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/Algorithm_MSVM.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/Algorithm_MSVM.R b/src/test/scripts/functions/codegen/Algorithm_MSVM.R
new file mode 100644
index 0000000..52a898b
--- /dev/null
+++ b/src/test/scripts/functions/codegen/Algorithm_MSVM.R
@@ -0,0 +1,133 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args <- commandArgs(TRUE)
+library("Matrix")
+
+X = readMM(paste(args[1], "X.mtx", sep=""));
+Y = readMM(paste(args[1], "Y.mtx", sep=""));
+intercept = as.integer(args[2]);
+epsilon = as.double(args[3]);
+lambda = 0.001;
+max_iterations = as.integer(args[4]);
+
+
+if(nrow(X) < 2)
+	stop("Stopping due to invalid inputs: Not possible to learn a classifier without at least 2 rows")
+
+lambda = 0.001
+num_samples = nrow(X)
+dimensions = nrow(X)
+num_features = ncol(X)
+
+min_y = min(Y)
+num_classes = max(Y)
+mod1 = Y %% 1
+mod1_should_be_nrow = sum(abs(mod1==0))
+	
+
+if (intercept == 1) {
+	ones  = matrix(1, num_samples, 1);
+	X = append(X, ones);
+}
+
+num_rows_in_w = num_features
+if(intercept == 1){
+	num_rows_in_w = num_rows_in_w + 1
+}
+w = matrix(0, num_rows_in_w, num_classes)
+
+debug_mat = matrix(-1, max_iterations, num_classes)
+for(iter_class in 1:num_classes){		  
+	Y_local = 2 * (Y == iter_class) - 1
+	w_class = matrix(0, num_features, 1)
+	if (intercept == 1) {
+		zero_matrix = matrix(0, 1, 1);
+		w_class = t(append(t(w_class), zero_matrix));
+	}
+ 
+	g_old = t(X) %*% Y_local
+	s = g_old
+
+	Xw = matrix(0, nrow(X), 1)
+	iter = 0
+	continue = 1
+	while(continue == 1)  {
+		# minimizing primal obj along direction s
+ 		step_sz = 0
+ 		Xd = X %*% s
+ 		wd = lambda * sum(w_class * s)
+		dd = lambda * sum(s * s)
+		continue1 = 1
+		while(continue1 == 1){
+ 			tmp_Xw = Xw + step_sz*Xd
+ 			out = 1 - Y_local * (tmp_Xw)
+ 			sv = (out > 0)
+ 			out = out * sv
+ 			g = wd + step_sz*dd - sum(out * Y_local * Xd)
+ 			h = dd + sum(Xd * sv * Xd)
+ 			step_sz = step_sz - g/h
+ 			if (g*g/h < 0.0000000001){
+			continue1 = 0
+		}
+	}
+ 
+		#update weights
+		w_class = w_class + step_sz*s
+		Xw = Xw + step_sz*Xd
+ 
+		out = 1 - Y_local * Xw
+		sv = (out > 0)
+		out = sv * out
+		obj = 0.5 * sum(out * out) + lambda/2 * sum(w_class * w_class)
+  		g_new = t(X) %*% (out * Y_local) - lambda * w_class
+
+  		tmp = sum(s * g_old)
+  
+  		train_acc = sum( (Y_local*(X%*%w_class))>= 0)/num_samples*100
+  		print(paste("For class " , iter_class , " iteration " , iter , " training accuracy: " , train_acc))
+  		debug_mat[iter+1,iter_class] = obj	   
+   
+  		if((step_sz*tmp < epsilon*obj) | (iter >= max_iterations-1)){
+   			continue = 0
+  		}
+ 
+  		#non-linear CG step
+  		be = sum(g_new * g_new)/sum(g_old * g_old)
+  		s = be * s + g_new
+  		g_old = g_new
+
+		if(sum(s^2) == 0){
+	    	continue = 0
+		}
+
+  		iter = iter + 1
+ 	}
+
+  w[,iter_class] = as.matrix(w_class)
+}
+
+extra_model_params = matrix(0, 2, ncol(w))
+extra_model_params[1, 1] = intercept
+extra_model_params[2, 1] = dimensions
+w = t(cbind(t(w), t(extra_model_params)))
+
+writeMM(as(w,"CsparseMatrix"), paste(args[5], "w", sep=""));

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/Algorithm_MSVM.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/Algorithm_MSVM.dml b/src/test/scripts/functions/codegen/Algorithm_MSVM.dml
new file mode 100644
index 0000000..0ab739f
--- /dev/null
+++ b/src/test/scripts/functions/codegen/Algorithm_MSVM.dml
@@ -0,0 +1,150 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X = read($1)
+Y = read($2)
+intercept = $3;
+eps = $4;
+maxiter = $5;
+
+if(nrow(X) < 2)
+	stop("Stopping due to invalid inputs: Not possible to learn a classifier without at least 2 rows")
+
+epsilon = eps
+lambda = 0.001
+max_iterations = maxiter
+num_samples = nrow(X)
+dimensions = nrow(X)
+num_features = ncol(X)
+
+
+if(nrow(X) != nrow(Y))
+	stop("Stopping due to invalid argument: Numbers of rows in X and Y must match")
+
+if(intercept != 0 & intercept != 1)
+	stop("Stopping due to invalid argument: Currently supported intercept options are 0 and 1")
+
+min_y = min(Y)
+if(min_y < 1)
+	stop("Stopping due to invalid argument: Label vector (Y) must be recoded")
+num_classes = max(Y)
+if(num_classes == 1)
+	stop("Stopping due to invalid argument: Maximum label value is 1, need more than one class to learn a multi-class classifier")	
+mod1 = Y %% 1
+mod1_should_be_nrow = sum(abs(ppred(mod1, 0, "==")))
+if(mod1_should_be_nrow != nrow(Y))
+	stop("Stopping due to invalid argument: Please ensure that Y contains (positive) integral labels")
+	
+if(epsilon < 0)
+	stop("Stopping due to invalid argument: Tolerance (tol) must be non-negative")
+
+if(lambda < 0)
+	stop("Stopping due to invalid argument: Regularization constant (reg) must be non-negative")
+
+if(max_iterations < 1)
+	stop("Stopping due to invalid argument: Maximum iterations should be a positive integer")
+
+if (intercept == 1) {
+	ones  = matrix(1, rows=num_samples, cols=1);
+	X = append(X, ones);
+}
+
+num_rows_in_w = num_features
+if(intercept == 1){
+	num_rows_in_w = num_rows_in_w + 1
+}
+w = matrix(0, rows=num_rows_in_w, cols=num_classes)
+
+debug_mat = matrix(-1, rows=max_iterations, cols=num_classes)
+parfor(iter_class in 1:num_classes){		  
+	Y_local = 2 * ppred(Y, iter_class, "==") - 1
+	w_class = matrix(0, rows=num_features, cols=1)
+	if (intercept == 1) {
+		zero_matrix = matrix(0, rows=1, cols=1);
+		w_class = t(append(t(w_class), zero_matrix));
+	}
+ 
+	g_old = t(X) %*% Y_local
+	s = g_old
+
+	Xw = matrix(0, rows=nrow(X), cols=1)
+	iter = 0
+	continue = 1
+	while(continue == 1)  {
+		# minimizing primal obj along direction s
+ 		step_sz = 0
+ 		Xd = X %*% s
+ 		wd = lambda * sum(w_class * s)
+		dd = lambda * sum(s * s)
+		continue1 = 1
+		while(continue1 == 1){
+ 			tmp_Xw = Xw + step_sz*Xd
+ 			out = 1 - Y_local * (tmp_Xw)
+ 			sv = ppred(out, 0, ">")
+ 			out = out * sv
+ 			g = wd + step_sz*dd - sum(out * Y_local * Xd)
+ 			h = dd + sum(Xd * sv * Xd)
+ 			step_sz = step_sz - g/h
+ 			if (g*g/h < 0.0000000001){
+			continue1 = 0
+		}
+	}
+ 
+		#update weights
+		w_class = w_class + step_sz*s
+		Xw = Xw + step_sz*Xd
+ 
+		out = 1 - Y_local * Xw
+		sv = ppred(out, 0, ">")
+		out = sv * out
+		obj = 0.5 * sum(out * out) + lambda/2 * sum(w_class * w_class)
+  		g_new = t(X) %*% (out * Y_local) - lambda * w_class
+
+  		tmp = sum(s * g_old)
+  
+  		train_acc = sum(ppred(Y_local*(X%*%w_class), 0, ">="))/num_samples*100
+  		print("For class " + iter_class + " iteration " + iter + " training accuracy: " + train_acc)
+  		debug_mat[iter+1,iter_class] = obj	   
+   
+  		if((step_sz*tmp < epsilon*obj) | (iter >= max_iterations-1)){
+   			continue = 0
+  		}
+ 
+  		#non-linear CG step
+  		be = sum(g_new * g_new)/sum(g_old * g_old)
+  		s = be * s + g_new
+  		g_old = g_new
+
+		if(sum(s^2) == 0){
+	    	continue = 0
+		}
+
+  		iter = iter + 1
+ 	}
+
+	w[,iter_class] = w_class
+}
+
+extra_model_params = matrix(0, rows=2, cols=ncol(w))
+extra_model_params[1, 1] = intercept
+extra_model_params[2, 1] = dimensions
+w = t(append(t(w), t(extra_model_params)))
+write(w, $6, format="text")

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/Algorithm_PNMF.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/Algorithm_PNMF.R b/src/test/scripts/functions/codegen/Algorithm_PNMF.R
new file mode 100644
index 0000000..a2fbb57
--- /dev/null
+++ b/src/test/scripts/functions/codegen/Algorithm_PNMF.R
@@ -0,0 +1,43 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args <- commandArgs(TRUE)
+library("Matrix")
+
+X = readMM(paste(args[1], "X.mtx", sep=""));
+W = readMM(paste(args[1], "W.mtx", sep=""));
+H = readMM(paste(args[1], "H.mtx", sep=""));
+
+k = as.integer(args[2]);
+eps = as.double(args[3]);
+max_iter = as.integer(args[4]);
+iter = 1;
+
+while( iter < max_iter ) {
+   H = (H*(t(W)%*%(X/(W%*%H+eps)))) / (colSums(W)%*%matrix(1,1,ncol(H)));
+   W = (W*((X/(W%*%H+eps))%*%t(H))) / (matrix(1,nrow(W),1)%*%t(rowSums(H)));
+   obj = sum(W%*%H) - sum(X*log(W%*%H+eps));
+   print(paste("obj=", obj))
+   iter = iter + 1;
+}
+
+writeMM(as(W,"CsparseMatrix"), paste(args[5], "W", sep=""));
+writeMM(as(H,"CsparseMatrix"), paste(args[5], "H", sep=""));

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/Algorithm_PNMF.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/Algorithm_PNMF.dml b/src/test/scripts/functions/codegen/Algorithm_PNMF.dml
new file mode 100644
index 0000000..641cc09
--- /dev/null
+++ b/src/test/scripts/functions/codegen/Algorithm_PNMF.dml
@@ -0,0 +1,40 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X = read($1);
+W = read($2);
+H = read($3);
+
+k = $4; 
+eps = $5; 
+max_iter = $6;
+iter = 1;
+
+while( iter < max_iter ) {
+   H = (H*(t(W)%*%(X/(W%*%H+eps)))) / t(colSums(W));
+   W = (W*((X/(W%*%H+eps))%*%t(H))) / t(rowSums(H));
+   obj = sum(W%*%H) - sum(X*log(W%*%H+eps));
+   print("iter=" + iter + " obj=" + obj);
+   iter = iter + 1;
+}
+
+write(W, $7);
+write(H, $8);

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/DAGcellwisetmpl1.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/DAGcellwisetmpl1.R b/src/test/scripts/functions/codegen/DAGcellwisetmpl1.R
new file mode 100644
index 0000000..21c70b5
--- /dev/null
+++ b/src/test/scripts/functions/codegen/DAGcellwisetmpl1.R
@@ -0,0 +1,36 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+
+N = 2000;
+M = as.integer(args[1]);
+X = matrix( seq(1,N*M), N, M, byrow=TRUE)
+
+A = (X * 7 + 6) * 5 + 4;
+B = A + 1;
+C = A + 2;
+S = B + C;
+
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+ 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/DAGcellwisetmpl1.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/DAGcellwisetmpl1.dml b/src/test/scripts/functions/codegen/DAGcellwisetmpl1.dml
new file mode 100644
index 0000000..0a9062e
--- /dev/null
+++ b/src/test/scripts/functions/codegen/DAGcellwisetmpl1.dml
@@ -0,0 +1,31 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+N = 2000;
+M = $1;
+X = matrix( seq(1,N*M), rows=N, cols=M)
+
+A = (X * 7 + 6) * 5 + 4;
+B = A + 1;
+C = A + 2;
+S = B + C;
+
+write(S, $2)

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/DAGcellwisetmpl2.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/DAGcellwisetmpl2.R b/src/test/scripts/functions/codegen/DAGcellwisetmpl2.R
new file mode 100644
index 0000000..90d4d96
--- /dev/null
+++ b/src/test/scripts/functions/codegen/DAGcellwisetmpl2.R
@@ -0,0 +1,36 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+
+N = 2000;
+M = as.integer(args[1]);
+X = matrix( seq(1,N*M), N, M, byrow=TRUE)
+
+A = (X * 7 + 6) * 5 + 4;
+B = A + 1;
+C = A + 2;
+S = as.matrix(sum(B * C));
+
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+ 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/DAGcellwisetmpl2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/DAGcellwisetmpl2.dml b/src/test/scripts/functions/codegen/DAGcellwisetmpl2.dml
new file mode 100644
index 0000000..8bcc462
--- /dev/null
+++ b/src/test/scripts/functions/codegen/DAGcellwisetmpl2.dml
@@ -0,0 +1,31 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+N = 2000;
+M = $1;
+X = matrix( seq(1,N*M), rows=N, cols=M)
+
+A = (X * 7 + 6) * 5 + 4;
+B = A + 1;
+C = A + 2;
+S = as.matrix(sum(B * C));
+
+write(S, $2)

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/DAGcellwisetmpl3.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/DAGcellwisetmpl3.R b/src/test/scripts/functions/codegen/DAGcellwisetmpl3.R
new file mode 100644
index 0000000..d052e3e
--- /dev/null
+++ b/src/test/scripts/functions/codegen/DAGcellwisetmpl3.R
@@ -0,0 +1,36 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+
+N = 2000;
+M = as.integer(args[1]);
+X = matrix( seq(1,N*M), N, M, byrow=TRUE)
+
+A = (X * 7 + 6) * 5 + 4;
+B = A + 1;
+C = A + 2;
+S = rowSums(B * C);
+
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+ 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/DAGcellwisetmpl3.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/DAGcellwisetmpl3.dml b/src/test/scripts/functions/codegen/DAGcellwisetmpl3.dml
new file mode 100644
index 0000000..287abe7
--- /dev/null
+++ b/src/test/scripts/functions/codegen/DAGcellwisetmpl3.dml
@@ -0,0 +1,31 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+N = 2000;
+M = $1;
+X = matrix( seq(1,N*M), rows=N, cols=M)
+
+A = (X * 7 + 6) * 5 + 4;
+B = A + 1;
+C = A + 2;
+S = rowSums(B * C);
+
+write(S, $2)

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/SystemML-config-codegen.xml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/SystemML-config-codegen.xml b/src/test/scripts/functions/codegen/SystemML-config-codegen.xml
new file mode 100644
index 0000000..5d623ae
--- /dev/null
+++ b/src/test/scripts/functions/codegen/SystemML-config-codegen.xml
@@ -0,0 +1,61 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+
+<root>
+   <!-- local fs tmp working directory-->
+   <localtmpdir>/tmp/systemml</localtmpdir>
+
+   <!-- hdfs tmp working directory--> 
+   <scratch>scratch_space</scratch> 
+
+   <!-- compiler optimization level, valid values: 0 | 1 | 2 | 3 | 4, default: 2 -->
+   <optlevel>7</optlevel>  
+
+   <!-- default number of reduce tasks per MR job, default: 2 x number of nodes -->
+   <numreducers>10</numreducers> 
+   
+   <!-- override jvm reuse flag for specific MR jobs, valid values: true | false  -->
+   <jvmreuse>false</jvmreuse> 
+
+   <!-- default block dim for binary block files -->
+   <defaultblocksize>1000</defaultblocksize> 
+
+   <!-- run systemml control program as yarn appmaster, in case of MR1 always falls back to client, please disable for debug mode -->
+   <dml.yarn.appmaster>false</dml.yarn.appmaster>
+
+   <!-- maximum jvm heap size of the dml yarn appmaster in MB, the requested memory is 1.5x this parameter -->
+   <dml.yarn.appmaster.mem>2048</dml.yarn.appmaster.mem>
+
+   <!-- maximum jvm heap size of the map/reduce tasks in MB, the requested memory is 1.5x this parameter, negative values ignored  -->
+   <dml.yarn.mapreduce.mem>2048</dml.yarn.mapreduce.mem>
+
+   <!-- yarn application submission queue, relevant for default capacity scheduler -->
+   <dml.yarn.app.queue>default</dml.yarn.app.queue>
+   
+   <!-- enables multi-threaded matrix multiplications in singlenode control program -->
+   <cp.parallel.matrixmult>true</cp.parallel.matrixmult>
+   
+   <!-- enables multi-threaded read/write of text formats in singlenode control program -->
+   <cp.parallel.textio>true</cp.parallel.textio>
+   
+   <!-- enables automatic code generation -->
+   <codegen.enabled>true</codegen.enabled>
+   <codegen.plancache>true</codegen.plancache>
+   <codegen.literals>1</codegen.literals>
+</root>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/cellwisetmpl1.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl1.R b/src/test/scripts/functions/codegen/cellwisetmpl1.R
new file mode 100644
index 0000000..1c306b0
--- /dev/null
+++ b/src/test/scripts/functions/codegen/cellwisetmpl1.R
@@ -0,0 +1,43 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+#X= matrix( 1, 100, 100)
+#X = matrix(  c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3, byrow = TRUE)
+#X= matrix(  c(0,0,3,4,0,0,0,8,0),  nrow=3, ncol=3, byrow = TRUE)
+#Y= matrix( c(2,2,2,3,3,3,1,1,1), nrow=3, ncol=3, byrow = TRUE)
+#X= matrix(1, 1001, 1001)
+
+X= matrix( seq(1,4000000), 2000,2000, byrow=TRUE)
+#X= matrix(1, 2000,2000, byrow=TRUE)
+
+Y= matrix( 2, 2000, 2000)
+#S= X*(1-X)
+lamda = 4000
+
+S=round(abs(X+lamda))+5
+#S=sum(X+Y+5)
+#S=round(X+(X+9.5))
+#print(S)
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+ 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/cellwisetmpl1.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl1.dml b/src/test/scripts/functions/codegen/cellwisetmpl1.dml
new file mode 100644
index 0000000..f646c15
--- /dev/null
+++ b/src/test/scripts/functions/codegen/cellwisetmpl1.dml
@@ -0,0 +1,27 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( seq(1,4000000), rows=2000, cols=2000)
+Y= matrix( 2, rows=2000, cols=1)
+
+lamda = sum(Y)
+S=round(abs(X+lamda))+5
+write(S,$1)

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/cellwisetmpl2.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl2.R b/src/test/scripts/functions/codegen/cellwisetmpl2.R
new file mode 100644
index 0000000..f48d9e6
--- /dev/null
+++ b/src/test/scripts/functions/codegen/cellwisetmpl2.R
@@ -0,0 +1,31 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+#X= matrix( 1,100, 100)
+#X = matrix(  c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3, byrow = TRUE)
+#X= matrix( "0 0 3 4 0 0 0 8 0", 3, 3)
+X= matrix( 1, 10, 10)
+S= 1/(1+exp(-X))
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/cellwisetmpl2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl2.dml b/src/test/scripts/functions/codegen/cellwisetmpl2.dml
new file mode 100644
index 0000000..c84a987
--- /dev/null
+++ b/src/test/scripts/functions/codegen/cellwisetmpl2.dml
@@ -0,0 +1,28 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( 1, rows=10, cols=10)
+S= 1/(1+exp(-X))
+write(S,$1)
+
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/cellwisetmpl3.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl3.R b/src/test/scripts/functions/codegen/cellwisetmpl3.R
new file mode 100644
index 0000000..43253aa
--- /dev/null
+++ b/src/test/scripts/functions/codegen/cellwisetmpl3.R
@@ -0,0 +1,31 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+#X= matrix( seq(1,25), 5, 5, byrow = TRUE)
+X = matrix(  c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3, byrow = TRUE)
+
+#S= X*as.matrix(X>0)
+#S=7 + (1 / exp(X) )
+S = 10 + floor(round(abs(7 + (1 / exp(X) ))))
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/cellwisetmpl3.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl3.dml b/src/test/scripts/functions/codegen/cellwisetmpl3.dml
new file mode 100644
index 0000000..4aa30eb
--- /dev/null
+++ b/src/test/scripts/functions/codegen/cellwisetmpl3.dml
@@ -0,0 +1,24 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( "1 2 3 4 5 6 7 8 9", rows=3, cols=3)
+S=10 + floor(round(abs(7 + (1 / exp(X) ))))
+write(S,$1)

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/cellwisetmpl4.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl4.R b/src/test/scripts/functions/codegen/cellwisetmpl4.R
new file mode 100644
index 0000000..803904c
--- /dev/null
+++ b/src/test/scripts/functions/codegen/cellwisetmpl4.R
@@ -0,0 +1,32 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+#X= matrix( seq(1,25), 5, 5, byrow = TRUE)
+X = matrix(  c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3, byrow = TRUE)
+w=matrix(  c(3,3,3,3,3,3,3,3,3), nrow=3, ncol=3, byrow = TRUE)
+z=matrix(  c(5,5,5,5,5,5,5,5,5), nrow=3, ncol=3, byrow = TRUE)
+#S= X*as.matrix(X>0)
+#S=7 + (1 / exp(X) )
+S = 10 + floor(round(abs((X+w)*z)))
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/cellwisetmpl4.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl4.dml b/src/test/scripts/functions/codegen/cellwisetmpl4.dml
new file mode 100644
index 0000000..58b0b58
--- /dev/null
+++ b/src/test/scripts/functions/codegen/cellwisetmpl4.dml
@@ -0,0 +1,26 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( "1 2 3 4 5 6 7 8 9", rows=3, cols=3)
+w=matrix( "3 3 3", rows=3, cols=1)
+z=matrix( "5 5 5", rows=3, cols=1)
+S=10 + floor(round(abs((X+w)*z)))
+write(S,$1)

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/cellwisetmpl5.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl5.R b/src/test/scripts/functions/codegen/cellwisetmpl5.R
new file mode 100644
index 0000000..ae95111
--- /dev/null
+++ b/src/test/scripts/functions/codegen/cellwisetmpl5.R
@@ -0,0 +1,34 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+#X= matrix( seq(1,25), 5, 5, byrow = TRUE)
+X = matrix(  c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3, byrow = TRUE)
+w=matrix(  c(1,1,1,2,2,2,3,3,3), nrow=3, ncol=3, byrow = TRUE)
+z=matrix(  c(3,3,3,3,3,3,3,3,3), nrow=3, ncol=3, byrow = TRUE)
+#S= X*as.matrix(X>0)
+#S=7 + (1 / exp(X) )
+G = abs(exp(X))
+Y=10 + floor(round(abs((X/w)+z)))
+S = G + Y
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/cellwisetmpl5.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl5.dml b/src/test/scripts/functions/codegen/cellwisetmpl5.dml
new file mode 100644
index 0000000..c9f30ef
--- /dev/null
+++ b/src/test/scripts/functions/codegen/cellwisetmpl5.dml
@@ -0,0 +1,29 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( "1 2 3 4 5 6 7 8 9", rows=3, cols=3)
+w=matrix( "1 2 3", rows=3, cols=1)
+z=matrix( "3 3 3", rows=3, cols=1)
+
+G = abs(exp(X))
+Y=10 + floor(round(abs((X/w)+z)))
+S = G + Y
+write(S,$1)

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/cellwisetmpl6.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl6.R b/src/test/scripts/functions/codegen/cellwisetmpl6.R
new file mode 100644
index 0000000..669e76f
--- /dev/null
+++ b/src/test/scripts/functions/codegen/cellwisetmpl6.R
@@ -0,0 +1,33 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+#X= matrix( seq(1,25), 5, 5, byrow = TRUE)
+X = matrix(  c(1,2,3), nrow=3, ncol=1, byrow = TRUE)
+y=matrix(  c(1,1,1), nrow=3, ncol=1, byrow = TRUE)
+z=matrix(  c(3,3,3), nrow=3, ncol=1, byrow = TRUE)
+#S= X*as.matrix(X>0)
+#S=7 + (1 / exp(X) )
+S=sum(X*y*z)
+print(S)
+write(S,paste(args[2],"S",sep=""))

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/cellwisetmpl6.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl6.dml b/src/test/scripts/functions/codegen/cellwisetmpl6.dml
new file mode 100644
index 0000000..7ff5124
--- /dev/null
+++ b/src/test/scripts/functions/codegen/cellwisetmpl6.dml
@@ -0,0 +1,54 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( "1 2 3", rows=3, cols=1)
+y=matrix( "1 1 1", rows=3, cols=1)
+z=matrix( "3 3 3", rows=3, cols=1)
+
+
+S = sum(X*y*z)
+print(S)
+write(S,$1)
+#S=10 + floor(round(abs((X+w)+z)))
+#G = abs(exp(X))
+
+#print(sum(G))

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/codegenIntegration.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/codegenIntegration.R b/src/test/scripts/functions/codegen/codegenIntegration.R
new file mode 100644
index 0000000..7456c87
--- /dev/null
+++ b/src/test/scripts/functions/codegen/codegenIntegration.R
@@ -0,0 +1,45 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+X = matrix(  c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15), nrow=5, ncol=3, byrow = TRUE)
+v=matrix(1,3,1)
+
+###############Test0
+#lamda = sum(X)
+#S=t(X)%*%X%*%(lamda*v)
+#writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+
+###############Test1
+#lamda=sum(X)
+#S=t(X)%*%(lamda*(X%*%v))
+#writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+
+###############Test2
+#w=matrix(  c(1,2,3,4,5), nrow=5, ncol=1, byrow = TRUE)
+#S=t(X)%*%(w*(X%*%v))
+#writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+
+###############Test3
+S=colSums(X/rowSums(X))
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/codegenIntegration.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/codegenIntegration.dml b/src/test/scripts/functions/codegen/codegenIntegration.dml
new file mode 100644
index 0000000..e312fe0
--- /dev/null
+++ b/src/test/scripts/functions/codegen/codegenIntegration.dml
@@ -0,0 +1,67 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", rows=5, cols=3)
+v=matrix(1,rows=3,cols=1)
+###############Test 0
+
+#lamda = sum(X)
+#S=t(X)%*%(X%*%(lamda*v))
+#write(S,$1)
+
+###############Test 1
+#Y= matrix( "1 1 1 4 5 6 7 8 9 10 11 12 13 14 15", rows=5, cols=3)
+#lamda=sum(Y)
+#S=t(X)%*%(lamda*(X%*%v))
+#write(S,$1)
+
+###############Test 2 (need to update the current template)
+#w=matrix( "1 2 3 4 5", rows=5, cols=1)
+#z=matrix( "3 3 3 3 3", rows=5, cols=1)
+#S=t(X)%*%(w*(X%*%v))
+#write(S,$1)
+
+###############Test 3
+X= matrix( "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", rows=5, cols=3)
+S=colSums(X/rowSums(X))
+write(S,$1)
+

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/rowAggPattern1.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern1.R b/src/test/scripts/functions/codegen/rowAggPattern1.R
new file mode 100644
index 0000000..3657e4a
--- /dev/null
+++ b/src/test/scripts/functions/codegen/rowAggPattern1.R
@@ -0,0 +1,29 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+X = matrix(  c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15), nrow=5, ncol=3, byrow = TRUE)
+v=matrix(1,3,1)
+lamda = sum(X)
+S=t(X)%*%X%*%(lamda*v)
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/rowAggPattern1.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern1.dml b/src/test/scripts/functions/codegen/rowAggPattern1.dml
new file mode 100644
index 0000000..1d43211
--- /dev/null
+++ b/src/test/scripts/functions/codegen/rowAggPattern1.dml
@@ -0,0 +1,26 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", rows=5, cols=3)
+v=matrix(1,rows=3,cols=1)
+lamda = sum(X)
+S=t(X)%*%(X%*%(lamda*v))
+write(S,$1)

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/rowAggPattern2.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern2.R b/src/test/scripts/functions/codegen/rowAggPattern2.R
new file mode 100644
index 0000000..1689593
--- /dev/null
+++ b/src/test/scripts/functions/codegen/rowAggPattern2.R
@@ -0,0 +1,31 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+X = matrix(  c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15), nrow=5, ncol=3, byrow = TRUE)
+v=matrix(1,3,1)
+Y= matrix( c(1,1,1,4,5,6,7,8,9,10,11,12,13,14,15), nrow=5, ncol=3, byrow = TRUE)
+lamda=sum(Y)
+S=t(X)%*%(lamda*(X%*%v))
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/rowAggPattern2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern2.dml b/src/test/scripts/functions/codegen/rowAggPattern2.dml
new file mode 100644
index 0000000..4007ae9
--- /dev/null
+++ b/src/test/scripts/functions/codegen/rowAggPattern2.dml
@@ -0,0 +1,30 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", rows=5, cols=3)
+v=matrix(1,rows=3,cols=1)
+Y= matrix( "1 1 1 4 5 6 7 8 9 10 11 12 13 14 15", rows=5, cols=3)
+lamda=sum(Y)
+#lamda=2
+S=t(X)%*%(lamda*(X%*%v))
+write(S,$1)
+
+

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/rowAggPattern3.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern3.R b/src/test/scripts/functions/codegen/rowAggPattern3.R
new file mode 100644
index 0000000..760620a
--- /dev/null
+++ b/src/test/scripts/functions/codegen/rowAggPattern3.R
@@ -0,0 +1,31 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+X = matrix(  c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15), nrow=5, ncol=3, byrow = TRUE)
+v=matrix(1,3,1)
+w=matrix(  c(1,2,3,4,5), nrow=5, ncol=1, byrow = TRUE)
+z=matrix(  c(3,3,3,3,3), nrow=5, ncol=1, byrow = TRUE)
+
+S=t(X)%*%(z+(2-(w*(X%*%v))))
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/rowAggPattern3.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern3.dml b/src/test/scripts/functions/codegen/rowAggPattern3.dml
new file mode 100644
index 0000000..7fbfb87
--- /dev/null
+++ b/src/test/scripts/functions/codegen/rowAggPattern3.dml
@@ -0,0 +1,30 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", rows=5, cols=3)
+v=matrix(1,rows=3,cols=1)
+w=matrix( "1 2 3 4 5", rows=5, cols=1)
+z=matrix( "3 3 3 3 3", rows=5, cols=1)
+
+S=t(X)%*%(z+(2-(w*(X%*%v))))
+write(S,$1)
+
+

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/rowAggPattern4.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern4.R b/src/test/scripts/functions/codegen/rowAggPattern4.R
new file mode 100644
index 0000000..65774b4
--- /dev/null
+++ b/src/test/scripts/functions/codegen/rowAggPattern4.R
@@ -0,0 +1,27 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+X = matrix( c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15), nrow=5, ncol=3, byrow = TRUE)
+S=t(colSums(X/rowSums(X)))
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/rowAggPattern4.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern4.dml b/src/test/scripts/functions/codegen/rowAggPattern4.dml
new file mode 100644
index 0000000..4c65efd
--- /dev/null
+++ b/src/test/scripts/functions/codegen/rowAggPattern4.dml
@@ -0,0 +1,25 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", rows=5, cols=3)
+S=colSums(X/rowSums(X))
+write(S,$1)
+

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/wcemm.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wcemm.R b/src/test/scripts/functions/codegen/wcemm.R
new file mode 100644
index 0000000..f228db3
--- /dev/null
+++ b/src/test/scripts/functions/codegen/wcemm.R
@@ -0,0 +1,35 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+
+X = as.matrix(readMM(paste(args[1], "A.mtx", sep="")))
+
+U= matrix( 1, 2000, 10)
+V= matrix( 2, 2000, 10)
+
+eps = 0.1
+S= sum(X*log(U%*%t(V)+eps))
+print(S)
+write(S, paste(args[2], "S", sep="")); 
+ 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/wcemm.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wcemm.dml b/src/test/scripts/functions/codegen/wcemm.dml
new file mode 100644
index 0000000..32ff880
--- /dev/null
+++ b/src/test/scripts/functions/codegen/wcemm.dml
@@ -0,0 +1,30 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= read($2)
+U= matrix( 1, rows=2000, cols=10)
+V= matrix( 2, rows=2000, cols=10)
+if(1==1){}
+
+eps = 0.1
+S= sum(X*log(U%*%t(V)+eps))
+write(S,$1)
+print(S)

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/wdivmm.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wdivmm.R b/src/test/scripts/functions/codegen/wdivmm.R
new file mode 100644
index 0000000..37e2d44
--- /dev/null
+++ b/src/test/scripts/functions/codegen/wdivmm.R
@@ -0,0 +1,32 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+
+X= matrix( 3, 20000,2000)
+U= matrix( 4, 20000,10)
+V= matrix( 5, 2000,10)
+eps = 0.1
+S= t(t(U) %*% (X/(U%*%t(V)+eps)));
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+ 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/wdivmm.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wdivmm.dml b/src/test/scripts/functions/codegen/wdivmm.dml
new file mode 100644
index 0000000..dc030f4
--- /dev/null
+++ b/src/test/scripts/functions/codegen/wdivmm.dml
@@ -0,0 +1,29 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( 3, rows=20000, cols=2000)
+U= matrix( 4, rows=20000, cols=10)
+V= matrix( 5, rows=2000, cols=10)
+if(1==1){}
+eps = 0.1
+S= t(t(U) %*% (X/(U%*%t(V)+eps)))
+
+write(S,$1)

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/wdivmmRight.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wdivmmRight.R b/src/test/scripts/functions/codegen/wdivmmRight.R
new file mode 100644
index 0000000..cc3159a
--- /dev/null
+++ b/src/test/scripts/functions/codegen/wdivmmRight.R
@@ -0,0 +1,32 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+
+X= matrix( 3, 2000,2000)
+U= matrix( 4, 2000,10)
+V= matrix( 5, 2000,10)
+eps = 0.1
+S= (X/(U%*%t(V)))%*%V
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+ 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/wdivmmRight.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wdivmmRight.dml b/src/test/scripts/functions/codegen/wdivmmRight.dml
new file mode 100644
index 0000000..488d744
--- /dev/null
+++ b/src/test/scripts/functions/codegen/wdivmmRight.dml
@@ -0,0 +1,32 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( 3, rows=2000, cols=2000)
+U= matrix( 4, rows=2000, cols=10)
+V= matrix( 5, rows=2000, cols=10)
+
+if(1==1){}
+
+eps = 0.1
+S= (X/(U%*%t(V)))%*%V
+print(sum(S))
+write(S,$1)
+

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/wdivmmRightNotranspose.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wdivmmRightNotranspose.R b/src/test/scripts/functions/codegen/wdivmmRightNotranspose.R
new file mode 100644
index 0000000..e541154
--- /dev/null
+++ b/src/test/scripts/functions/codegen/wdivmmRightNotranspose.R
@@ -0,0 +1,32 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+
+X= matrix( c(1,0,1,2,2,0,0,3,3,0,0,4), nrow=4, ncol=3, byrow = TRUE)
+U= matrix( c(1,2,3,4,5,6,7,8), nrow=4, ncol=2, byrow = TRUE)
+V= matrix( c(9,12,10,13,11,14), nrow=2, ncol=3, byrow = TRUE)
+eps = 0.1
+S= (X/((U%*%V)+eps))%*%t(V)
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+ 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/wdivmmRightNotranspose.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wdivmmRightNotranspose.dml b/src/test/scripts/functions/codegen/wdivmmRightNotranspose.dml
new file mode 100644
index 0000000..1938832
--- /dev/null
+++ b/src/test/scripts/functions/codegen/wdivmmRightNotranspose.dml
@@ -0,0 +1,31 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+X= matrix( "1 0 1 2 2 0 0 3 3 0 0 4", rows=4, cols=3)
+U= matrix( "1 2 3 4 5 6 7 8", rows=4, cols=2)
+V= matrix( "9 12 10 13 11 14", rows=2, cols=3)
+
+if(1==1){}
+
+eps = 0.1
+S= (X/((U%*%V)+eps))%*%t(V)
+write(S,$1)
+

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/bbefe96b/src/test/scripts/functions/codegen/wdivmmTransposeOut.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wdivmmTransposeOut.R b/src/test/scripts/functions/codegen/wdivmmTransposeOut.R
new file mode 100644
index 0000000..ba1da27
--- /dev/null
+++ b/src/test/scripts/functions/codegen/wdivmmTransposeOut.R
@@ -0,0 +1,32 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+args<-commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+
+X= matrix( c(1,0,1,2,2,0,0,3,3,0,0,4), nrow=4, ncol=3, byrow = TRUE)
+U= matrix( c(1,2,3,4,5,6,7,8), nrow=4, ncol=2, byrow = TRUE)
+V= matrix( c(9,12,10,13,11,14), nrow=2, ncol=3, byrow = TRUE)
+eps = 0.1
+S= (t(U) %*% (X/((U%*%V)+eps)));
+writeMM(as(S, "CsparseMatrix"), paste(args[2], "S", sep="")); 
+ 
\ No newline at end of file