http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/jmlc/reuse-glm-predict.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/jmlc/reuse-glm-predict.dml b/src/test/scripts/functions/jmlc/reuse-glm-predict.dml index 540971a..9a29d67 100644 --- a/src/test/scripts/functions/jmlc/reuse-glm-predict.dml +++ b/src/test/scripts/functions/jmlc/reuse-glm-predict.dml @@ -1,383 +1,383 @@ -#------------------------------------------------------------- -# -# 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. -# -#------------------------------------------------------------- - -# Default values for input parameters: -fileX = $X; -fileB = $B; -fileM = ifdef ($M, " "); -fileY = ifdef ($Y, " "); -fileO = ifdef ($O, " "); -fmtM = ifdef ($fmt, "text"); - -dist_type = ifdef ($dfam, 1); # $dfam = 1; -var_power = ifdef ($vpow, 0.0); # $vpow = 0.0; -link_type = ifdef ($link, 0); # $link = 0; -link_power = ifdef ($lpow, 1.0); # $lpow = 1.0; -dispersion = ifdef ($disp, 1.0); # $disp = 1.0; - -var_power = as.double (var_power); -link_power = as.double (link_power); -dispersion = as.double (dispersion); - -if (dist_type == 3) { - link_type = 2; -} else { if (link_type == 0) { # Canonical Link - if (dist_type == 1) { - link_type = 1; - link_power = 1.0 - var_power; - } else { if (dist_type == 2) { - link_type = 2; -}}} } - -X = read(fileX); -#X = table(X[,1], X[,2], X[,3]) - -num_records = nrow (X); -num_features = ncol (X); - -W = read (fileB); -if (dist_type == 3) { - beta = W [1 : ncol (X), ]; - intercept = W [nrow(W), ]; -} else { - beta = W [1 : ncol (X), 1]; - intercept = W [nrow(W), 1]; -} -if (nrow (W) == ncol (X)) { - intercept = 0.0 * intercept; - is_intercept = FALSE; -} else { - num_features = num_features + 1; - is_intercept = TRUE; -} - -ones_rec = matrix (1, rows = num_records, cols = 1); -linear_terms = X %*% beta + ones_rec %*% intercept; -[means, vars] = - glm_means_and_vars (linear_terms, dist_type, var_power, link_type, link_power); - -if (fileM != " ") { - write (means, fileM, format=fmtM); -} - -predicted_y = rowIndexMax(means) -write(predicted_y, $P, format=fmtM) - -if (fileY != " ") -{ - Y = read (fileY); - ones_ctg = matrix (1, rows = ncol(Y), cols = 1); - - # Statistics To Compute: - - Z_logl = 0.0 / 0.0; - Z_logl_pValue = 0.0 / 0.0; - X2_pearson = 0.0 / 0.0; - df_pearson = -1; - G2_deviance = 0.0 / 0.0; - df_deviance = -1; - X2_pearson_pValue = 0.0 / 0.0; - G2_deviance_pValue = 0.0 / 0.0; - Z_logl_scaled = 0.0 / 0.0; - Z_logl_scaled_pValue = 0.0 / 0.0; - X2_scaled = 0.0 / 0.0; - X2_scaled_pValue = 0.0 / 0.0; - G2_scaled = 0.0 / 0.0; - G2_scaled_pValue = 0.0 / 0.0; - - if (dist_type == 1 & link_type == 1) { - # - # POWER DISTRIBUTIONS (GAUSSIAN, POISSON, GAMMA, ETC.) - # - if (link_power == 0.0) { - is_zero_Y = ppred (Y, 0.0, "=="); - lt_saturated = log (Y + is_zero_Y) - is_zero_Y / (1.0 - is_zero_Y); - } else { - lt_saturated = Y ^ link_power; - } - Y_counts = ones_rec; - - X2_pearson = sum ((Y - means) ^ 2 / vars); - df_pearson = num_records - num_features; - - log_l_part = - glm_partial_loglikelihood_for_power_dist_and_link (linear_terms, Y, var_power, link_power); - log_l_part_saturated = - glm_partial_loglikelihood_for_power_dist_and_link (lt_saturated, Y, var_power, link_power); - - G2_deviance = 2 * sum (log_l_part_saturated) - 2 * sum (log_l_part); - df_deviance = num_records - num_features; - - } else { if (dist_type >= 2) { - # - # BINOMIAL AND MULTINOMIAL DISTRIBUTIONS - # - if (ncol (Y) == 1) { - num_categories = ncol (beta) + 1; - if (min (Y) <= 0) { - # Category labels "0", "-1" etc. are converted into the baseline label - Y = Y + (- Y + num_categories) * ppred (Y, 0, "<="); - } - Y_size = min (num_categories, max(Y)); - Y_unsized = table (seq (1, num_records, 1), Y); - Y = matrix (0, rows = num_records, cols = num_categories); - Y [, 1 : Y_size] = Y_unsized [, 1 : Y_size]; - Y_counts = ones_rec; - } else { - Y_counts = rowSums (Y); - } - - P = means; - zero_Y = ppred (Y, 0.0, "=="); - zero_P = ppred (P, 0.0, "=="); - ones_ctg = matrix (1, rows = ncol(Y), cols = 1); - - logl_vec = rowSums (Y * log (P + zero_Y) ); - ent1_vec = rowSums (P * log (P + zero_P) ); - ent2_vec = rowSums (P * (log (P + zero_P))^2); - E_logl = sum (Y_counts * ent1_vec); - V_logl = sum (Y_counts * (ent2_vec - ent1_vec ^ 2)); - Z_logl = (sum (logl_vec) - E_logl) / sqrt (V_logl); - - means = means * (Y_counts %*% t(ones_ctg)); - vars = vars * (Y_counts %*% t(ones_ctg)); - - frac_below_5 = sum (ppred (means, 5, "<")) / (nrow (means) * ncol (means)); - frac_below_1 = sum (ppred (means, 1, "<")) / (nrow (means) * ncol (means)); - - if (frac_below_5 > 0.2 | frac_below_1 > 0.0) { - print ("WARNING: residual statistics are inaccurate here due to low cell means."); - } - - X2_pearson = sum ((Y - means) ^ 2 / means); - df_pearson = (num_records - num_features) * (ncol(Y) - 1); - - G2_deviance = 2 * sum (Y * log ((Y + zero_Y) / (means + zero_Y))); - df_deviance = (num_records - num_features) * (ncol(Y) - 1); - }} - - if (Z_logl == Z_logl) { - Z_logl_absneg = - abs (Z_logl); - Z_logl_pValue = 2.0 * pnorm(target = Z_logl_absneg); - } - if (X2_pearson == X2_pearson & df_pearson > 0) { - X2_pearson_pValue = pchisq(target = X2_pearson, df = df_pearson, lower.tail=FALSE); - } - if (G2_deviance == G2_deviance & df_deviance > 0) { - G2_deviance_pValue = pchisq(target = G2_deviance, df = df_deviance, lower.tail=FALSE); - } - - Z_logl_scaled = Z_logl / sqrt (dispersion); - X2_scaled = X2_pearson / dispersion; - G2_scaled = G2_deviance / dispersion; - - if (Z_logl_scaled == Z_logl_scaled) { - Z_logl_scaled_absneg = - abs (Z_logl_scaled); - Z_logl_scaled_pValue = 2.0 * pnorm(target = Z_logl_scaled_absneg); - } - if (X2_scaled == X2_scaled & df_pearson > 0) { - X2_scaled_pValue = pchisq(target = X2_scaled, df = df_pearson, lower.tail=FALSE); - } - if (G2_scaled == G2_scaled & df_deviance > 0) { - G2_scaled_pValue = pchisq(target = G2_scaled, df = df_deviance, lower.tail=FALSE); - } - - avg_tot_Y = colSums ( Y ) / sum (Y_counts); - avg_res_Y = colSums (Y - means) / sum (Y_counts); - - ss_avg_tot_Y = colSums (( Y - Y_counts %*% avg_tot_Y) ^ 2); - ss_res_Y = colSums ((Y - means) ^ 2); - ss_avg_res_Y = colSums ((Y - means - Y_counts %*% avg_res_Y) ^ 2); - - df_ss_res_Y = sum (Y_counts) - num_features; - if (is_intercept) { - df_ss_avg_res_Y = df_ss_res_Y; - } else { - df_ss_avg_res_Y = df_ss_res_Y - 1; - } - - var_tot_Y = ss_avg_tot_Y / (sum (Y_counts) - 1); - if (df_ss_avg_res_Y > 0) { - var_res_Y = ss_avg_res_Y / df_ss_avg_res_Y; - } else { - var_res_Y = matrix (0.0, rows = 1, cols = ncol (Y)) / 0.0; - } - plain_R2_nobias = 1 - ss_avg_res_Y / ss_avg_tot_Y; - adjust_R2_nobias = 1 - var_res_Y / var_tot_Y; - plain_R2 = 1 - ss_res_Y / ss_avg_tot_Y; - if (df_ss_res_Y > 0) { - adjust_R2 = 1 - (ss_res_Y / df_ss_res_Y) / var_tot_Y; - } else { - adjust_R2 = matrix (0.0, rows = 1, cols = ncol (Y)) / 0.0; - } - - predicted_avg_var_res_Y = dispersion * colSums (vars) / sum (Y_counts); - - # PREPARING THE OUTPUT CSV STATISTICS FILE - - str = "LOGLHOOD_Z,,FALSE," + Z_logl; - str = append (str, "LOGLHOOD_Z_PVAL,,FALSE," + Z_logl_pValue); - str = append (str, "PEARSON_X2,,FALSE," + X2_pearson); - str = append (str, "PEARSON_X2_BY_DF,,FALSE," + (X2_pearson / df_pearson)); - str = append (str, "PEARSON_X2_PVAL,,FALSE," + X2_pearson_pValue); - str = append (str, "DEVIANCE_G2,,FALSE," + G2_deviance); - str = append (str, "DEVIANCE_G2_BY_DF,,FALSE," + (G2_deviance / df_deviance)); - str = append (str, "DEVIANCE_G2_PVAL,,FALSE," + G2_deviance_pValue); - str = append (str, "LOGLHOOD_Z,,TRUE," + Z_logl_scaled); - str = append (str, "LOGLHOOD_Z_PVAL,,TRUE," + Z_logl_scaled_pValue); - str = append (str, "PEARSON_X2,,TRUE," + X2_scaled); - str = append (str, "PEARSON_X2_BY_DF,,TRUE," + (X2_scaled / df_pearson)); - str = append (str, "PEARSON_X2_PVAL,,TRUE," + X2_scaled_pValue); - str = append (str, "DEVIANCE_G2,,TRUE," + G2_scaled); - str = append (str, "DEVIANCE_G2_BY_DF,,TRUE," + (G2_scaled / df_deviance)); - str = append (str, "DEVIANCE_G2_PVAL,,TRUE," + G2_scaled_pValue); - - for (i in 1:ncol(Y)) { - str = append (str, "AVG_TOT_Y," + i + ",," + castAsScalar (avg_tot_Y [1, i])); - str = append (str, "STDEV_TOT_Y," + i + ",," + castAsScalar (sqrt (var_tot_Y [1, i]))); - str = append (str, "AVG_RES_Y," + i + ",," + castAsScalar (avg_res_Y [1, i])); - str = append (str, "STDEV_RES_Y," + i + ",," + castAsScalar (sqrt (var_res_Y [1, i]))); - str = append (str, "PRED_STDEV_RES," + i + ",TRUE," + castAsScalar (sqrt (predicted_avg_var_res_Y [1, i]))); - str = append (str, "PLAIN_R2," + i + ",," + castAsScalar (plain_R2 [1, i])); - str = append (str, "ADJUSTED_R2," + i + ",," + castAsScalar (adjust_R2 [1, i])); - str = append (str, "PLAIN_R2_NOBIAS," + i + ",," + castAsScalar (plain_R2_nobias [1, i])); - str = append (str, "ADJUSTED_R2_NOBIAS," + i + ",," + castAsScalar (adjust_R2_nobias [1, i])); - } - - if (fileO != " ") { - write (str, fileO); - } else { - print (str); - } -} - -glm_means_and_vars = - function (Matrix[double] linear_terms, int dist_type, double var_power, int link_type, double link_power) - return (Matrix[double] means, Matrix[double] vars) - # NOTE: "vars" represents the variance without dispersion, i.e. the V(mu) function. -{ - num_points = nrow (linear_terms); - if (dist_type == 1 & link_type == 1) { - # POWER DISTRIBUTION - if (link_power == 0.0) { - y_mean = exp (linear_terms); - } else { if (link_power == 1.0) { - y_mean = linear_terms; - } else { if (link_power == -1.0) { - y_mean = 1.0 / linear_terms; - } else { - y_mean = linear_terms ^ (1.0 / link_power); - }}} - if (var_power == 0.0) { - var_function = matrix (1.0, rows = num_points, cols = 1); - } else { if (var_power == 1.0) { - var_function = y_mean; - } else { - var_function = y_mean ^ var_power; - }} - means = y_mean; - vars = var_function; - } else { if (dist_type == 2 & link_type >= 1 & link_type <= 5) { - # BINOMIAL/BERNOULLI DISTRIBUTION - y_prob = matrix (0.0, rows = num_points, cols = 2); - if (link_type == 1 & link_power == 0.0) { # Binomial.log - y_prob [, 1] = exp (linear_terms); - y_prob [, 2] = 1.0 - y_prob [, 1]; - } else { if (link_type == 1 & link_power != 0.0) { # Binomial.power_nonlog - y_prob [, 1] = linear_terms ^ (1.0 / link_power); - y_prob [, 2] = 1.0 - y_prob [, 1]; - } else { if (link_type == 2) { # Binomial.logit - elt = exp (linear_terms); - y_prob [, 1] = elt / (1.0 + elt); - y_prob [, 2] = 1.0 / (1.0 + elt); - } else { if (link_type == 3) { # Binomial.probit - sign_lt = 2 * ppred (linear_terms, 0.0, ">=") - 1; - t_gp = 1.0 / (1.0 + abs (linear_terms) * 0.231641888); # 0.231641888 = 0.3275911 / sqrt (2.0) - erf_corr = - t_gp * ( 0.254829592 - + t_gp * (-0.284496736 # "Handbook of Mathematical Functions", ed. by M. Abramowitz and I.A. Stegun, - + t_gp * ( 1.421413741 # U.S. Nat-l Bureau of Standards, 10th print (Dec 1972), Sec. 7.1.26, p. 299 - + t_gp * (-1.453152027 - + t_gp * 1.061405429)))) * sign_lt * exp (- (linear_terms ^ 2) / 2.0); - y_prob [, 1] = (1 + sign_lt) - erf_corr; - y_prob [, 2] = (1 - sign_lt) + erf_corr; - y_prob = y_prob / 2; - } else { if (link_type == 4) { # Binomial.cloglog - elt = exp (linear_terms); - is_too_small = ppred (10000000 + elt, 10000000, "=="); - y_prob [, 2] = exp (- elt); - y_prob [, 1] = (1 - is_too_small) * (1.0 - y_prob [, 2]) + is_too_small * elt * (1.0 - elt / 2); - } else { if (link_type == 5) { # Binomial.cauchit - atan_linear_terms = atan (linear_terms); - y_prob [, 1] = 0.5 + atan_linear_terms / 3.1415926535897932384626433832795; - y_prob [, 2] = 0.5 - atan_linear_terms / 3.1415926535897932384626433832795; - }}}}}} - means = y_prob; - ones_ctg = matrix (1, rows = 2, cols = 1); - vars = means * (means %*% (1 - diag (ones_ctg))); - } else { if (dist_type == 3) { - # MULTINOMIAL LOGIT DISTRIBUTION - elt = exp (linear_terms); - ones_pts = matrix (1, rows = num_points, cols = 1); - elt = append (elt, ones_pts); - ones_ctg = matrix (1, rows = ncol (elt), cols = 1); - means = elt / (rowSums (elt) %*% t(ones_ctg)); - vars = means * (means %*% (1 - diag (ones_ctg))); - } else { - means = matrix (0.0, rows = num_points, cols = 1); - vars = matrix (0.0, rows = num_points, cols = 1); -} }}} - -glm_partial_loglikelihood_for_power_dist_and_link = # Assumes: dist_type == 1 & link_type == 1 - function (Matrix[double] linear_terms, Matrix[double] Y, double var_power, double link_power) - return (Matrix[double] log_l_part) -{ - num_records = nrow (Y); - if (var_power == 1.0) { # Poisson - if (link_power == 0.0) { # Poisson.log - is_natural_parameter_log_zero = ppred (linear_terms, -1.0/0.0, "=="); - natural_parameters = replace (target = linear_terms, pattern = -1.0/0.0, replacement = 0); - b_cumulant = exp (linear_terms); - } else { # Poisson.power_nonlog - is_natural_parameter_log_zero = ppred (linear_terms, 0.0, "=="); - natural_parameters = log (linear_terms + is_natural_parameter_log_zero) / link_power; - b_cumulant = (linear_terms + is_natural_parameter_log_zero) ^ (1.0 / link_power) - is_natural_parameter_log_zero; - } - is_minus_infinity = ppred (Y, 0, ">") * is_natural_parameter_log_zero; - log_l_part = Y * natural_parameters - b_cumulant - is_minus_infinity / (1 - is_minus_infinity); - } else { - if (var_power == 2.0 & link_power == 0.0) { # Gamma.log - natural_parameters = - exp (- linear_terms); - b_cumulant = linear_terms; - } else { if (var_power == 2.0) { # Gamma.power_nonlog - natural_parameters = - linear_terms ^ (- 1.0 / link_power); - b_cumulant = log (linear_terms) / link_power; - } else { if (link_power == 0.0) { # PowerDist.log - natural_parameters = exp (linear_terms * (1.0 - var_power)) / (1.0 - var_power); - b_cumulant = exp (linear_terms * (2.0 - var_power)) / (2.0 - var_power); - } else { # PowerDist.power_nonlog - power_np = (1.0 - var_power) / link_power; - natural_parameters = (linear_terms ^ power_np) / (1.0 - var_power); - power_cu = (2.0 - var_power) / link_power; - b_cumulant = (linear_terms ^ power_cu) / (2.0 - var_power); - }}} - log_l_part = Y * natural_parameters - b_cumulant; -} } +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +# Default values for input parameters: +fileX = $X; +fileB = $B; +fileM = ifdef ($M, " "); +fileY = ifdef ($Y, " "); +fileO = ifdef ($O, " "); +fmtM = ifdef ($fmt, "text"); + +dist_type = ifdef ($dfam, 1); # $dfam = 1; +var_power = ifdef ($vpow, 0.0); # $vpow = 0.0; +link_type = ifdef ($link, 0); # $link = 0; +link_power = ifdef ($lpow, 1.0); # $lpow = 1.0; +dispersion = ifdef ($disp, 1.0); # $disp = 1.0; + +var_power = as.double (var_power); +link_power = as.double (link_power); +dispersion = as.double (dispersion); + +if (dist_type == 3) { + link_type = 2; +} else { if (link_type == 0) { # Canonical Link + if (dist_type == 1) { + link_type = 1; + link_power = 1.0 - var_power; + } else { if (dist_type == 2) { + link_type = 2; +}}} } + +X = read(fileX); +#X = table(X[,1], X[,2], X[,3]) + +num_records = nrow (X); +num_features = ncol (X); + +W = read (fileB); +if (dist_type == 3) { + beta = W [1 : ncol (X), ]; + intercept = W [nrow(W), ]; +} else { + beta = W [1 : ncol (X), 1]; + intercept = W [nrow(W), 1]; +} +if (nrow (W) == ncol (X)) { + intercept = 0.0 * intercept; + is_intercept = FALSE; +} else { + num_features = num_features + 1; + is_intercept = TRUE; +} + +ones_rec = matrix (1, rows = num_records, cols = 1); +linear_terms = X %*% beta + ones_rec %*% intercept; +[means, vars] = + glm_means_and_vars (linear_terms, dist_type, var_power, link_type, link_power); + +if (fileM != " ") { + write (means, fileM, format=fmtM); +} + +predicted_y = rowIndexMax(means) +write(predicted_y, $P, format=fmtM) + +if (fileY != " ") +{ + Y = read (fileY); + ones_ctg = matrix (1, rows = ncol(Y), cols = 1); + + # Statistics To Compute: + + Z_logl = 0.0 / 0.0; + Z_logl_pValue = 0.0 / 0.0; + X2_pearson = 0.0 / 0.0; + df_pearson = -1; + G2_deviance = 0.0 / 0.0; + df_deviance = -1; + X2_pearson_pValue = 0.0 / 0.0; + G2_deviance_pValue = 0.0 / 0.0; + Z_logl_scaled = 0.0 / 0.0; + Z_logl_scaled_pValue = 0.0 / 0.0; + X2_scaled = 0.0 / 0.0; + X2_scaled_pValue = 0.0 / 0.0; + G2_scaled = 0.0 / 0.0; + G2_scaled_pValue = 0.0 / 0.0; + + if (dist_type == 1 & link_type == 1) { + # + # POWER DISTRIBUTIONS (GAUSSIAN, POISSON, GAMMA, ETC.) + # + if (link_power == 0.0) { + is_zero_Y = ppred (Y, 0.0, "=="); + lt_saturated = log (Y + is_zero_Y) - is_zero_Y / (1.0 - is_zero_Y); + } else { + lt_saturated = Y ^ link_power; + } + Y_counts = ones_rec; + + X2_pearson = sum ((Y - means) ^ 2 / vars); + df_pearson = num_records - num_features; + + log_l_part = + glm_partial_loglikelihood_for_power_dist_and_link (linear_terms, Y, var_power, link_power); + log_l_part_saturated = + glm_partial_loglikelihood_for_power_dist_and_link (lt_saturated, Y, var_power, link_power); + + G2_deviance = 2 * sum (log_l_part_saturated) - 2 * sum (log_l_part); + df_deviance = num_records - num_features; + + } else { if (dist_type >= 2) { + # + # BINOMIAL AND MULTINOMIAL DISTRIBUTIONS + # + if (ncol (Y) == 1) { + num_categories = ncol (beta) + 1; + if (min (Y) <= 0) { + # Category labels "0", "-1" etc. are converted into the baseline label + Y = Y + (- Y + num_categories) * ppred (Y, 0, "<="); + } + Y_size = min (num_categories, max(Y)); + Y_unsized = table (seq (1, num_records, 1), Y); + Y = matrix (0, rows = num_records, cols = num_categories); + Y [, 1 : Y_size] = Y_unsized [, 1 : Y_size]; + Y_counts = ones_rec; + } else { + Y_counts = rowSums (Y); + } + + P = means; + zero_Y = ppred (Y, 0.0, "=="); + zero_P = ppred (P, 0.0, "=="); + ones_ctg = matrix (1, rows = ncol(Y), cols = 1); + + logl_vec = rowSums (Y * log (P + zero_Y) ); + ent1_vec = rowSums (P * log (P + zero_P) ); + ent2_vec = rowSums (P * (log (P + zero_P))^2); + E_logl = sum (Y_counts * ent1_vec); + V_logl = sum (Y_counts * (ent2_vec - ent1_vec ^ 2)); + Z_logl = (sum (logl_vec) - E_logl) / sqrt (V_logl); + + means = means * (Y_counts %*% t(ones_ctg)); + vars = vars * (Y_counts %*% t(ones_ctg)); + + frac_below_5 = sum (ppred (means, 5, "<")) / (nrow (means) * ncol (means)); + frac_below_1 = sum (ppred (means, 1, "<")) / (nrow (means) * ncol (means)); + + if (frac_below_5 > 0.2 | frac_below_1 > 0.0) { + print ("WARNING: residual statistics are inaccurate here due to low cell means."); + } + + X2_pearson = sum ((Y - means) ^ 2 / means); + df_pearson = (num_records - num_features) * (ncol(Y) - 1); + + G2_deviance = 2 * sum (Y * log ((Y + zero_Y) / (means + zero_Y))); + df_deviance = (num_records - num_features) * (ncol(Y) - 1); + }} + + if (Z_logl == Z_logl) { + Z_logl_absneg = - abs (Z_logl); + Z_logl_pValue = 2.0 * pnorm(target = Z_logl_absneg); + } + if (X2_pearson == X2_pearson & df_pearson > 0) { + X2_pearson_pValue = pchisq(target = X2_pearson, df = df_pearson, lower.tail=FALSE); + } + if (G2_deviance == G2_deviance & df_deviance > 0) { + G2_deviance_pValue = pchisq(target = G2_deviance, df = df_deviance, lower.tail=FALSE); + } + + Z_logl_scaled = Z_logl / sqrt (dispersion); + X2_scaled = X2_pearson / dispersion; + G2_scaled = G2_deviance / dispersion; + + if (Z_logl_scaled == Z_logl_scaled) { + Z_logl_scaled_absneg = - abs (Z_logl_scaled); + Z_logl_scaled_pValue = 2.0 * pnorm(target = Z_logl_scaled_absneg); + } + if (X2_scaled == X2_scaled & df_pearson > 0) { + X2_scaled_pValue = pchisq(target = X2_scaled, df = df_pearson, lower.tail=FALSE); + } + if (G2_scaled == G2_scaled & df_deviance > 0) { + G2_scaled_pValue = pchisq(target = G2_scaled, df = df_deviance, lower.tail=FALSE); + } + + avg_tot_Y = colSums ( Y ) / sum (Y_counts); + avg_res_Y = colSums (Y - means) / sum (Y_counts); + + ss_avg_tot_Y = colSums (( Y - Y_counts %*% avg_tot_Y) ^ 2); + ss_res_Y = colSums ((Y - means) ^ 2); + ss_avg_res_Y = colSums ((Y - means - Y_counts %*% avg_res_Y) ^ 2); + + df_ss_res_Y = sum (Y_counts) - num_features; + if (is_intercept) { + df_ss_avg_res_Y = df_ss_res_Y; + } else { + df_ss_avg_res_Y = df_ss_res_Y - 1; + } + + var_tot_Y = ss_avg_tot_Y / (sum (Y_counts) - 1); + if (df_ss_avg_res_Y > 0) { + var_res_Y = ss_avg_res_Y / df_ss_avg_res_Y; + } else { + var_res_Y = matrix (0.0, rows = 1, cols = ncol (Y)) / 0.0; + } + plain_R2_nobias = 1 - ss_avg_res_Y / ss_avg_tot_Y; + adjust_R2_nobias = 1 - var_res_Y / var_tot_Y; + plain_R2 = 1 - ss_res_Y / ss_avg_tot_Y; + if (df_ss_res_Y > 0) { + adjust_R2 = 1 - (ss_res_Y / df_ss_res_Y) / var_tot_Y; + } else { + adjust_R2 = matrix (0.0, rows = 1, cols = ncol (Y)) / 0.0; + } + + predicted_avg_var_res_Y = dispersion * colSums (vars) / sum (Y_counts); + + # PREPARING THE OUTPUT CSV STATISTICS FILE + + str = "LOGLHOOD_Z,,FALSE," + Z_logl; + str = append (str, "LOGLHOOD_Z_PVAL,,FALSE," + Z_logl_pValue); + str = append (str, "PEARSON_X2,,FALSE," + X2_pearson); + str = append (str, "PEARSON_X2_BY_DF,,FALSE," + (X2_pearson / df_pearson)); + str = append (str, "PEARSON_X2_PVAL,,FALSE," + X2_pearson_pValue); + str = append (str, "DEVIANCE_G2,,FALSE," + G2_deviance); + str = append (str, "DEVIANCE_G2_BY_DF,,FALSE," + (G2_deviance / df_deviance)); + str = append (str, "DEVIANCE_G2_PVAL,,FALSE," + G2_deviance_pValue); + str = append (str, "LOGLHOOD_Z,,TRUE," + Z_logl_scaled); + str = append (str, "LOGLHOOD_Z_PVAL,,TRUE," + Z_logl_scaled_pValue); + str = append (str, "PEARSON_X2,,TRUE," + X2_scaled); + str = append (str, "PEARSON_X2_BY_DF,,TRUE," + (X2_scaled / df_pearson)); + str = append (str, "PEARSON_X2_PVAL,,TRUE," + X2_scaled_pValue); + str = append (str, "DEVIANCE_G2,,TRUE," + G2_scaled); + str = append (str, "DEVIANCE_G2_BY_DF,,TRUE," + (G2_scaled / df_deviance)); + str = append (str, "DEVIANCE_G2_PVAL,,TRUE," + G2_scaled_pValue); + + for (i in 1:ncol(Y)) { + str = append (str, "AVG_TOT_Y," + i + ",," + castAsScalar (avg_tot_Y [1, i])); + str = append (str, "STDEV_TOT_Y," + i + ",," + castAsScalar (sqrt (var_tot_Y [1, i]))); + str = append (str, "AVG_RES_Y," + i + ",," + castAsScalar (avg_res_Y [1, i])); + str = append (str, "STDEV_RES_Y," + i + ",," + castAsScalar (sqrt (var_res_Y [1, i]))); + str = append (str, "PRED_STDEV_RES," + i + ",TRUE," + castAsScalar (sqrt (predicted_avg_var_res_Y [1, i]))); + str = append (str, "PLAIN_R2," + i + ",," + castAsScalar (plain_R2 [1, i])); + str = append (str, "ADJUSTED_R2," + i + ",," + castAsScalar (adjust_R2 [1, i])); + str = append (str, "PLAIN_R2_NOBIAS," + i + ",," + castAsScalar (plain_R2_nobias [1, i])); + str = append (str, "ADJUSTED_R2_NOBIAS," + i + ",," + castAsScalar (adjust_R2_nobias [1, i])); + } + + if (fileO != " ") { + write (str, fileO); + } else { + print (str); + } +} + +glm_means_and_vars = + function (Matrix[double] linear_terms, int dist_type, double var_power, int link_type, double link_power) + return (Matrix[double] means, Matrix[double] vars) + # NOTE: "vars" represents the variance without dispersion, i.e. the V(mu) function. +{ + num_points = nrow (linear_terms); + if (dist_type == 1 & link_type == 1) { + # POWER DISTRIBUTION + if (link_power == 0.0) { + y_mean = exp (linear_terms); + } else { if (link_power == 1.0) { + y_mean = linear_terms; + } else { if (link_power == -1.0) { + y_mean = 1.0 / linear_terms; + } else { + y_mean = linear_terms ^ (1.0 / link_power); + }}} + if (var_power == 0.0) { + var_function = matrix (1.0, rows = num_points, cols = 1); + } else { if (var_power == 1.0) { + var_function = y_mean; + } else { + var_function = y_mean ^ var_power; + }} + means = y_mean; + vars = var_function; + } else { if (dist_type == 2 & link_type >= 1 & link_type <= 5) { + # BINOMIAL/BERNOULLI DISTRIBUTION + y_prob = matrix (0.0, rows = num_points, cols = 2); + if (link_type == 1 & link_power == 0.0) { # Binomial.log + y_prob [, 1] = exp (linear_terms); + y_prob [, 2] = 1.0 - y_prob [, 1]; + } else { if (link_type == 1 & link_power != 0.0) { # Binomial.power_nonlog + y_prob [, 1] = linear_terms ^ (1.0 / link_power); + y_prob [, 2] = 1.0 - y_prob [, 1]; + } else { if (link_type == 2) { # Binomial.logit + elt = exp (linear_terms); + y_prob [, 1] = elt / (1.0 + elt); + y_prob [, 2] = 1.0 / (1.0 + elt); + } else { if (link_type == 3) { # Binomial.probit + sign_lt = 2 * ppred (linear_terms, 0.0, ">=") - 1; + t_gp = 1.0 / (1.0 + abs (linear_terms) * 0.231641888); # 0.231641888 = 0.3275911 / sqrt (2.0) + erf_corr = + t_gp * ( 0.254829592 + + t_gp * (-0.284496736 # "Handbook of Mathematical Functions", ed. by M. Abramowitz and I.A. Stegun, + + t_gp * ( 1.421413741 # U.S. Nat-l Bureau of Standards, 10th print (Dec 1972), Sec. 7.1.26, p. 299 + + t_gp * (-1.453152027 + + t_gp * 1.061405429)))) * sign_lt * exp (- (linear_terms ^ 2) / 2.0); + y_prob [, 1] = (1 + sign_lt) - erf_corr; + y_prob [, 2] = (1 - sign_lt) + erf_corr; + y_prob = y_prob / 2; + } else { if (link_type == 4) { # Binomial.cloglog + elt = exp (linear_terms); + is_too_small = ppred (10000000 + elt, 10000000, "=="); + y_prob [, 2] = exp (- elt); + y_prob [, 1] = (1 - is_too_small) * (1.0 - y_prob [, 2]) + is_too_small * elt * (1.0 - elt / 2); + } else { if (link_type == 5) { # Binomial.cauchit + atan_linear_terms = atan (linear_terms); + y_prob [, 1] = 0.5 + atan_linear_terms / 3.1415926535897932384626433832795; + y_prob [, 2] = 0.5 - atan_linear_terms / 3.1415926535897932384626433832795; + }}}}}} + means = y_prob; + ones_ctg = matrix (1, rows = 2, cols = 1); + vars = means * (means %*% (1 - diag (ones_ctg))); + } else { if (dist_type == 3) { + # MULTINOMIAL LOGIT DISTRIBUTION + elt = exp (linear_terms); + ones_pts = matrix (1, rows = num_points, cols = 1); + elt = append (elt, ones_pts); + ones_ctg = matrix (1, rows = ncol (elt), cols = 1); + means = elt / (rowSums (elt) %*% t(ones_ctg)); + vars = means * (means %*% (1 - diag (ones_ctg))); + } else { + means = matrix (0.0, rows = num_points, cols = 1); + vars = matrix (0.0, rows = num_points, cols = 1); +} }}} + +glm_partial_loglikelihood_for_power_dist_and_link = # Assumes: dist_type == 1 & link_type == 1 + function (Matrix[double] linear_terms, Matrix[double] Y, double var_power, double link_power) + return (Matrix[double] log_l_part) +{ + num_records = nrow (Y); + if (var_power == 1.0) { # Poisson + if (link_power == 0.0) { # Poisson.log + is_natural_parameter_log_zero = ppred (linear_terms, -1.0/0.0, "=="); + natural_parameters = replace (target = linear_terms, pattern = -1.0/0.0, replacement = 0); + b_cumulant = exp (linear_terms); + } else { # Poisson.power_nonlog + is_natural_parameter_log_zero = ppred (linear_terms, 0.0, "=="); + natural_parameters = log (linear_terms + is_natural_parameter_log_zero) / link_power; + b_cumulant = (linear_terms + is_natural_parameter_log_zero) ^ (1.0 / link_power) - is_natural_parameter_log_zero; + } + is_minus_infinity = ppred (Y, 0, ">") * is_natural_parameter_log_zero; + log_l_part = Y * natural_parameters - b_cumulant - is_minus_infinity / (1 - is_minus_infinity); + } else { + if (var_power == 2.0 & link_power == 0.0) { # Gamma.log + natural_parameters = - exp (- linear_terms); + b_cumulant = linear_terms; + } else { if (var_power == 2.0) { # Gamma.power_nonlog + natural_parameters = - linear_terms ^ (- 1.0 / link_power); + b_cumulant = log (linear_terms) / link_power; + } else { if (link_power == 0.0) { # PowerDist.log + natural_parameters = exp (linear_terms * (1.0 - var_power)) / (1.0 - var_power); + b_cumulant = exp (linear_terms * (2.0 - var_power)) / (2.0 - var_power); + } else { # PowerDist.power_nonlog + power_np = (1.0 - var_power) / link_power; + natural_parameters = (linear_terms ^ power_np) / (1.0 - var_power); + power_cu = (2.0 - var_power) / link_power; + b_cumulant = (linear_terms ^ power_cu) / (2.0 - var_power); + }}} + log_l_part = Y * natural_parameters - b_cumulant; +} }
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/jmlc/reuse-msvm-predict.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/jmlc/reuse-msvm-predict.dml b/src/test/scripts/functions/jmlc/reuse-msvm-predict.dml index 8bd41e1..026b88b 100644 --- a/src/test/scripts/functions/jmlc/reuse-msvm-predict.dml +++ b/src/test/scripts/functions/jmlc/reuse-msvm-predict.dml @@ -1,74 +1,74 @@ -#------------------------------------------------------------- -# -# 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. -# -#------------------------------------------------------------- - -cmdLine_Y = ifdef($Y, " ") -cmdLine_confusion = ifdef($confusion, " ") -cmdLine_accuracy = ifdef($accuracy, " ") -cmdLine_scores = ifdef($scores, " ") -cmdLine_fmt = ifdef($fmt, "text") - -X = read ($X); -N = max(X[,1]); - -W = read($W); -dimensions = as.scalar(W[nrow(W),1]) -intercept = as.scalar(W[nrow(W)-1,1]) -W = W[1:(nrow(W)-2),] - -#X = table(X[,1], X[,2], X[,3], N, dimensions) -#print(nrow(X) + " " + ncol(X) + " " + dimensions) - -num_classes = ncol(W) -m=ncol(X); - -b = matrix(0, rows=1, cols=num_classes) -if (intercept == 1) - b = W[m+1,] - -ones = matrix(1, rows=N, cols=1) -scores = X %*% W[1:m,] + ones %*% b; -predicted_y = rowIndexMax(scores); - -if(sum(predicted_y) != 0) - write(predicted_y, cmdLine_scores, format=cmdLine_fmt); - -if(cmdLine_Y != " "){ - y = read(cmdLine_Y); - - if(min(y) < 1) - stop("Stopping due to invalid argument: Label vector (Y) must be recoded") - - correct_percentage = sum(ppred(predicted_y - y, 0, "==")) / N * 100; - - acc_str = "Accuracy (%): " + correct_percentage - print(acc_str) - if(cmdLine_accuracy != " ") - write(acc_str, cmdLine_accuracy) - - num_classes_ground_truth = max(y) - if(num_classes < num_classes_ground_truth) - num_classes = num_classes_ground_truth - - if(cmdLine_confusion != " "){ - confusion_mat = table(predicted_y, y, num_classes, num_classes) - write(confusion_mat, cmdLine_confusion, format="csv") - } -} +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +cmdLine_Y = ifdef($Y, " ") +cmdLine_confusion = ifdef($confusion, " ") +cmdLine_accuracy = ifdef($accuracy, " ") +cmdLine_scores = ifdef($scores, " ") +cmdLine_fmt = ifdef($fmt, "text") + +X = read ($X); +N = max(X[,1]); + +W = read($W); +dimensions = as.scalar(W[nrow(W),1]) +intercept = as.scalar(W[nrow(W)-1,1]) +W = W[1:(nrow(W)-2),] + +#X = table(X[,1], X[,2], X[,3], N, dimensions) +#print(nrow(X) + " " + ncol(X) + " " + dimensions) + +num_classes = ncol(W) +m=ncol(X); + +b = matrix(0, rows=1, cols=num_classes) +if (intercept == 1) + b = W[m+1,] + +ones = matrix(1, rows=N, cols=1) +scores = X %*% W[1:m,] + ones %*% b; +predicted_y = rowIndexMax(scores); + +if(sum(predicted_y) != 0) + write(predicted_y, cmdLine_scores, format=cmdLine_fmt); + +if(cmdLine_Y != " "){ + y = read(cmdLine_Y); + + if(min(y) < 1) + stop("Stopping due to invalid argument: Label vector (Y) must be recoded") + + correct_percentage = sum(ppred(predicted_y - y, 0, "==")) / N * 100; + + acc_str = "Accuracy (%): " + correct_percentage + print(acc_str) + if(cmdLine_accuracy != " ") + write(acc_str, cmdLine_accuracy) + + num_classes_ground_truth = max(y) + if(num_classes < num_classes_ground_truth) + num_classes = num_classes_ground_truth + + if(cmdLine_confusion != " "){ + confusion_mat = table(predicted_y, y, num_classes, num_classes) + write(confusion_mat, cmdLine_confusion, format="csv") + } +} http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/ForScalarAssignmentTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/ForScalarAssignmentTest.dml b/src/test/scripts/functions/misc/ForScalarAssignmentTest.dml index d5d7ecb..818f3ba 100644 --- a/src/test/scripts/functions/misc/ForScalarAssignmentTest.dml +++ b/src/test/scripts/functions/misc/ForScalarAssignmentTest.dml @@ -19,10 +19,10 @@ # #------------------------------------------------------------- - -val = $1; -for( i in 1:10 ){ - val = $1; -} - + +val = $1; +for( i in 1:10 ){ + val = $1; +} + print(val); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/IPALiteralReplacement_ForIf.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/IPALiteralReplacement_ForIf.R b/src/test/scripts/functions/misc/IPALiteralReplacement_ForIf.R index 20b2c47..ce3b35b 100644 --- a/src/test/scripts/functions/misc/IPALiteralReplacement_ForIf.R +++ b/src/test/scripts/functions/misc/IPALiteralReplacement_ForIf.R @@ -19,29 +19,29 @@ # #------------------------------------------------------------- - -args <- commandArgs(TRUE) -options(digits=22) -library("Matrix") - -foo <- function(A) -{ - for( i in 1:1 ) { - continue = TRUE; - if( sum(A)<0 ) { - continue = FALSE; - } - iter = 0; - if( continue ) { - iter = iter+1; - } - B = A+iter; - } - - return(B); -} - -A = matrix(1, 10, 10) -R = foo(A) - -writeMM(as(R, "CsparseMatrix"), paste(args[1], "R", sep="")); + +args <- commandArgs(TRUE) +options(digits=22) +library("Matrix") + +foo <- function(A) +{ + for( i in 1:1 ) { + continue = TRUE; + if( sum(A)<0 ) { + continue = FALSE; + } + iter = 0; + if( continue ) { + iter = iter+1; + } + B = A+iter; + } + + return(B); +} + +A = matrix(1, 10, 10) +R = foo(A) + +writeMM(as(R, "CsparseMatrix"), paste(args[1], "R", sep="")); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/IPALiteralReplacement_ForIf.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/IPALiteralReplacement_ForIf.dml b/src/test/scripts/functions/misc/IPALiteralReplacement_ForIf.dml index 0b82fab..6c221bb 100644 --- a/src/test/scripts/functions/misc/IPALiteralReplacement_ForIf.dml +++ b/src/test/scripts/functions/misc/IPALiteralReplacement_ForIf.dml @@ -19,24 +19,24 @@ # #------------------------------------------------------------- - -foo = function( Matrix[Double] A ) return( Matrix[Double] B ) -{ - for( i in 1:1 ) { - continue = TRUE; - if( sum(A)<0 ) { - continue = FALSE; - } - iter = 0; - if( continue ) { - iter = iter+1; - } - B = A+iter; - } -} - - -A = matrix(1, rows=10, cols=10); -R = foo(A); - + +foo = function( Matrix[Double] A ) return( Matrix[Double] B ) +{ + for( i in 1:1 ) { + continue = TRUE; + if( sum(A)<0 ) { + continue = FALSE; + } + iter = 0; + if( continue ) { + iter = iter+1; + } + B = A+iter; + } +} + + +A = matrix(1, rows=10, cols=10); +R = foo(A); + write(R, $1); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/IPALiteralReplacement_While.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/IPALiteralReplacement_While.R b/src/test/scripts/functions/misc/IPALiteralReplacement_While.R index 0f8fda4..afcdeb6 100644 --- a/src/test/scripts/functions/misc/IPALiteralReplacement_While.R +++ b/src/test/scripts/functions/misc/IPALiteralReplacement_While.R @@ -19,28 +19,28 @@ # #------------------------------------------------------------- - -args <- commandArgs(TRUE) -options(digits=22) -library("Matrix") - -foo <- function(A) -{ - continue = TRUE; - iter = 0; - while( continue ) - { - iter = iter+1; - if( iter<10 ){ - continue = TRUE; - } else { - continue = FALSE; - } - } - B = A+iter; -} - -A = matrix(1, 10, 10) -R = foo(A) - -writeMM(as(R, "CsparseMatrix"), paste(args[1], "R", sep="")); + +args <- commandArgs(TRUE) +options(digits=22) +library("Matrix") + +foo <- function(A) +{ + continue = TRUE; + iter = 0; + while( continue ) + { + iter = iter+1; + if( iter<10 ){ + continue = TRUE; + } else { + continue = FALSE; + } + } + B = A+iter; +} + +A = matrix(1, 10, 10) +R = foo(A) + +writeMM(as(R, "CsparseMatrix"), paste(args[1], "R", sep="")); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/IPALiteralReplacement_While.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/IPALiteralReplacement_While.dml b/src/test/scripts/functions/misc/IPALiteralReplacement_While.dml index 4977607..08ec41d 100644 --- a/src/test/scripts/functions/misc/IPALiteralReplacement_While.dml +++ b/src/test/scripts/functions/misc/IPALiteralReplacement_While.dml @@ -19,24 +19,24 @@ # #------------------------------------------------------------- - -foo = function( Matrix[Double] A ) return( Matrix[Double] B ) -{ - continue = TRUE; - iter = 0; - while( continue ) - { - iter = iter+1; - if( iter<10 ) - continue = TRUE; - else - continue = FALSE; - } - B = A+iter; -} - - -A = matrix(1, rows=10, cols=10); -R = foo(A); - + +foo = function( Matrix[Double] A ) return( Matrix[Double] B ) +{ + continue = TRUE; + iter = 0; + while( continue ) + { + iter = iter+1; + if( iter<10 ) + continue = TRUE; + else + continue = FALSE; + } + B = A+iter; +} + + +A = matrix(1, rows=10, cols=10); +R = foo(A); + write(R, $1); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/IPAScalarRecursion.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/IPAScalarRecursion.dml b/src/test/scripts/functions/misc/IPAScalarRecursion.dml index b9ce1f3..115f6dd 100644 --- a/src/test/scripts/functions/misc/IPAScalarRecursion.dml +++ b/src/test/scripts/functions/misc/IPAScalarRecursion.dml @@ -19,20 +19,20 @@ # #------------------------------------------------------------- - - -powering = function (int index) - return (int value) -{ - if(index == 1) { - value = 2; - } - else { - ret = powering(index-1); - value = 2 * ret; - } -} - -n = $1; -v = powering(n); -print("Result is " + v); + + +powering = function (int index) + return (int value) +{ + if(index == 1) { + value = 2; + } + else { + ret = powering(index-1); + value = 2 * ret; + } +} + +n = $1; +v = powering(n); +print("Result is " + v); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/IPAUnknownRecursion.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/IPAUnknownRecursion.R b/src/test/scripts/functions/misc/IPAUnknownRecursion.R index 1b61f79..edc3314 100644 --- a/src/test/scripts/functions/misc/IPAUnknownRecursion.R +++ b/src/test/scripts/functions/misc/IPAUnknownRecursion.R @@ -19,33 +19,33 @@ # #------------------------------------------------------------- - -args <- commandArgs(TRUE) -options(digits=22) - -library("Matrix") - -factorial <- function(arr, pos){ - if(pos == 1){ - arr[1, pos] = 1 - } else { - arr = factorial(arr, pos-1) - arr[1, pos] = pos * arr[1, pos-1] - } - - return(arr); -} - -n = as.integer(args[1]) -arr = matrix(0, 1, n) -arr = factorial(arr, n) - -R = matrix(0, 1, n); -for(i in 1:n) -{ - R[1,i] = arr[1, i]; -} - -writeMM(as(R, "CsparseMatrix"), paste(args[2], "R", sep="")); - - + +args <- commandArgs(TRUE) +options(digits=22) + +library("Matrix") + +factorial <- function(arr, pos){ + if(pos == 1){ + arr[1, pos] = 1 + } else { + arr = factorial(arr, pos-1) + arr[1, pos] = pos * arr[1, pos-1] + } + + return(arr); +} + +n = as.integer(args[1]) +arr = matrix(0, 1, n) +arr = factorial(arr, n) + +R = matrix(0, 1, n); +for(i in 1:n) +{ + R[1,i] = arr[1, i]; +} + +writeMM(as(R, "CsparseMatrix"), paste(args[2], "R", sep="")); + + http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/IPAUnknownRecursion.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/IPAUnknownRecursion.dml b/src/test/scripts/functions/misc/IPAUnknownRecursion.dml index 1a852ab..22570b8 100644 --- a/src/test/scripts/functions/misc/IPAUnknownRecursion.dml +++ b/src/test/scripts/functions/misc/IPAUnknownRecursion.dml @@ -19,27 +19,27 @@ # #------------------------------------------------------------- - -factorial = function(Matrix[Double] arr, Integer pos) return (Matrix[Double] arr){ - if(pos == 1) arr[1, pos] = 1 - else{ - arr = factorial(arr, pos-1) - arr[1, pos] = pos * arr[1, pos-1] - } - - for(i in 1:ncol(arr)) - print("inside factorial (" + pos + ") " + i + ": " + castAsScalar(arr[1, i])) -} - -n = $1 -arr = matrix(0, rows=1, cols=n) -arr = factorial(arr, n) - -R = matrix(0, rows=1, cols=n); -for(i in 1:n) #copy important to test dynamic rewrites -{ - print("main factorial " + i + ": " + castAsScalar(arr[1, i])) - R[1,i] = as.scalar(arr[1, i]); -} - + +factorial = function(Matrix[Double] arr, Integer pos) return (Matrix[Double] arr){ + if(pos == 1) arr[1, pos] = 1 + else{ + arr = factorial(arr, pos-1) + arr[1, pos] = pos * arr[1, pos-1] + } + + for(i in 1:ncol(arr)) + print("inside factorial (" + pos + ") " + i + ": " + castAsScalar(arr[1, i])) +} + +n = $1 +arr = matrix(0, rows=1, cols=n) +arr = factorial(arr, n) + +R = matrix(0, rows=1, cols=n); +for(i in 1:n) #copy important to test dynamic rewrites +{ + print("main factorial " + i + ": " + castAsScalar(arr[1, i])) + R[1,i] = as.scalar(arr[1, i]); +} + write(R, $2); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/IfScalarAssignmentTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/IfScalarAssignmentTest.dml b/src/test/scripts/functions/misc/IfScalarAssignmentTest.dml index 2fc4365..460bf21 100644 --- a/src/test/scripts/functions/misc/IfScalarAssignmentTest.dml +++ b/src/test/scripts/functions/misc/IfScalarAssignmentTest.dml @@ -19,13 +19,13 @@ # #------------------------------------------------------------- - -val = $1; -if( 1==1){ - val = $1; -} -else{ - val = $1; -} - + +val = $1; +if( 1==1){ + val = $1; +} +else{ + val = $1; +} + print(val); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/InvalidFunctionSignatureTest1.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/InvalidFunctionSignatureTest1.dml b/src/test/scripts/functions/misc/InvalidFunctionSignatureTest1.dml index dcdb2da..fdce520 100644 --- a/src/test/scripts/functions/misc/InvalidFunctionSignatureTest1.dml +++ b/src/test/scripts/functions/misc/InvalidFunctionSignatureTest1.dml @@ -1,30 +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. -# -#------------------------------------------------------------- - -printFirst = function(matrix[double] mat) { - print(as.integer(as.scalar(mat[1,1]))); - for (i in 1:2){ - print("i="+i); - } -} - -A = matrix("1 2 3 4", rows=2, cols=2); -z = printFirst(A); +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +printFirst = function(matrix[double] mat) { + print(as.integer(as.scalar(mat[1,1]))); + for (i in 1:2){ + print("i="+i); + } +} + +A = matrix("1 2 3 4", rows=2, cols=2); +z = printFirst(A); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/InvalidFunctionSignatureTest2.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/InvalidFunctionSignatureTest2.dml b/src/test/scripts/functions/misc/InvalidFunctionSignatureTest2.dml index e003e80..2a95a50 100644 --- a/src/test/scripts/functions/misc/InvalidFunctionSignatureTest2.dml +++ b/src/test/scripts/functions/misc/InvalidFunctionSignatureTest2.dml @@ -1,30 +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. -# -#------------------------------------------------------------- - -printFirst = function(matrix[integer] mat) { - print(as.integer(as.scalar(mat[1,1]))); - for (i in 1:2){ - print("i="+i); - } -} - -A = matrix("1 2 3 4", rows=2, cols=2); -z = printFirst(A); +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +printFirst = function(matrix[integer] mat) { + print(as.integer(as.scalar(mat[1,1]))); + for (i in 1:2){ + print("i="+i); + } +} + +A = matrix("1 2 3 4", rows=2, cols=2); +z = printFirst(A); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/LengthStringTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/LengthStringTest.dml b/src/test/scripts/functions/misc/LengthStringTest.dml index 25b0ff1..06b3b05 100644 --- a/src/test/scripts/functions/misc/LengthStringTest.dml +++ b/src/test/scripts/functions/misc/LengthStringTest.dml @@ -19,8 +19,8 @@ # #------------------------------------------------------------- - -X = rand(rows=$1,cols=$2,sparsity=0.01); -Y = removeEmpty(target=X,margin="rows"); - + +X = rand(rows=$1,cols=$2,sparsity=0.01); +Y = removeEmpty(target=X,margin="rows"); + print(length(Y)); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/LengthUnknownCSVTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/LengthUnknownCSVTest.dml b/src/test/scripts/functions/misc/LengthUnknownCSVTest.dml index 64cc46c..84a2a31 100644 --- a/src/test/scripts/functions/misc/LengthUnknownCSVTest.dml +++ b/src/test/scripts/functions/misc/LengthUnknownCSVTest.dml @@ -19,6 +19,6 @@ # #------------------------------------------------------------- - -A = read($1, format="csv"); + +A = read($1, format="csv"); print(sum(A[sqrt(length(A))-1,])); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/LongOverflowForLoop.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/LongOverflowForLoop.dml b/src/test/scripts/functions/misc/LongOverflowForLoop.dml index 20c8d01..e3440fc 100644 --- a/src/test/scripts/functions/misc/LongOverflowForLoop.dml +++ b/src/test/scripts/functions/misc/LongOverflowForLoop.dml @@ -19,14 +19,14 @@ # #------------------------------------------------------------- - -val1 = $1; -val2 = $2; -val3 = -1; - -for( i in val1:val2 ) -{ - val3 = i; -} - -print("Result="+val3); + +val1 = $1; +val2 = $2; +val3 = -1; + +for( i in val1:val2 ) +{ + val3 = i; +} + +print("Result="+val3); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/LongOverflowMult.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/LongOverflowMult.dml b/src/test/scripts/functions/misc/LongOverflowMult.dml index f660a34..502e22f 100644 --- a/src/test/scripts/functions/misc/LongOverflowMult.dml +++ b/src/test/scripts/functions/misc/LongOverflowMult.dml @@ -19,10 +19,10 @@ # #------------------------------------------------------------- - -val1 = $1; -val2 = $2; - -val3 = val1*val2; - -print("Result="+val3); + +val1 = $1; +val2 = $2; + +val3 = val1*val2; + +print("Result="+val3); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/LongOverflowPlus.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/LongOverflowPlus.dml b/src/test/scripts/functions/misc/LongOverflowPlus.dml index d082ed0..8f69f09 100644 --- a/src/test/scripts/functions/misc/LongOverflowPlus.dml +++ b/src/test/scripts/functions/misc/LongOverflowPlus.dml @@ -19,10 +19,10 @@ # #------------------------------------------------------------- - -val1 = $1; -val2 = $2; - -val3 = val1+val2; - -print("Result="+val3); + +val1 = $1; +val2 = $2; + +val3 = val1+val2; + +print("Result="+val3); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/NcolStringTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/NcolStringTest.dml b/src/test/scripts/functions/misc/NcolStringTest.dml index f9fb1cb..2bc624e 100644 --- a/src/test/scripts/functions/misc/NcolStringTest.dml +++ b/src/test/scripts/functions/misc/NcolStringTest.dml @@ -19,8 +19,8 @@ # #------------------------------------------------------------- - -X = rand(rows=$1,cols=$2,sparsity=0.01); -Y = removeEmpty(target=X,margin="rows"); - + +X = rand(rows=$1,cols=$2,sparsity=0.01); +Y = removeEmpty(target=X,margin="rows"); + print(nrow(Y)); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/NcolUnknownCSVTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/NcolUnknownCSVTest.dml b/src/test/scripts/functions/misc/NcolUnknownCSVTest.dml index 5434fdb..fdaf16c 100644 --- a/src/test/scripts/functions/misc/NcolUnknownCSVTest.dml +++ b/src/test/scripts/functions/misc/NcolUnknownCSVTest.dml @@ -19,6 +19,6 @@ # #------------------------------------------------------------- - -A = read($1, format="csv"); + +A = read($1, format="csv"); print(sum(A[,ncol(A)-3])); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/NrowStringTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/NrowStringTest.dml b/src/test/scripts/functions/misc/NrowStringTest.dml index f9fb1cb..2bc624e 100644 --- a/src/test/scripts/functions/misc/NrowStringTest.dml +++ b/src/test/scripts/functions/misc/NrowStringTest.dml @@ -19,8 +19,8 @@ # #------------------------------------------------------------- - -X = rand(rows=$1,cols=$2,sparsity=0.01); -Y = removeEmpty(target=X,margin="rows"); - + +X = rand(rows=$1,cols=$2,sparsity=0.01); +Y = removeEmpty(target=X,margin="rows"); + print(nrow(Y)); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/NrowUnknownCSVTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/NrowUnknownCSVTest.dml b/src/test/scripts/functions/misc/NrowUnknownCSVTest.dml index 9ad3cac..0afd68b 100644 --- a/src/test/scripts/functions/misc/NrowUnknownCSVTest.dml +++ b/src/test/scripts/functions/misc/NrowUnknownCSVTest.dml @@ -19,6 +19,6 @@ # #------------------------------------------------------------- - -A = read($1, format="csv"); + +A = read($1, format="csv"); print(sum(A[nrow(A)-3,])); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/OuterExpandTest.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/OuterExpandTest.R b/src/test/scripts/functions/misc/OuterExpandTest.R index 81a1f24..b581a4a 100644 --- a/src/test/scripts/functions/misc/OuterExpandTest.R +++ b/src/test/scripts/functions/misc/OuterExpandTest.R @@ -1,38 +1,38 @@ -#------------------------------------------------------------- -# -# 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") - -A = as.matrix(readMM(paste(args[1], "A.mtx", sep=""))) -m = as.integer(args[2]); -left = as.logical(args[3]); - -if( left ){ - C = outer(as.vector(A), seq(1,m), "=="); -} else { - C = outer(seq(1,m), as.vector(A), "=="); -} - - -writeMM(as(as.matrix(C), "CsparseMatrix"), paste(args[4], "C", sep="")); +#------------------------------------------------------------- +# +# 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") + +A = as.matrix(readMM(paste(args[1], "A.mtx", sep=""))) +m = as.integer(args[2]); +left = as.logical(args[3]); + +if( left ){ + C = outer(as.vector(A), seq(1,m), "=="); +} else { + C = outer(seq(1,m), as.vector(A), "=="); +} + + +writeMM(as(as.matrix(C), "CsparseMatrix"), paste(args[4], "C", sep="")); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/OuterExpandTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/OuterExpandTest.dml b/src/test/scripts/functions/misc/OuterExpandTest.dml index b0b931e..b312677 100644 --- a/src/test/scripts/functions/misc/OuterExpandTest.dml +++ b/src/test/scripts/functions/misc/OuterExpandTest.dml @@ -1,34 +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. -# -#------------------------------------------------------------- - - -A = read($1); -m = $2; -left = $3; - -if( left ){ - C = outer(A, t(seq(1,m)), "=="); -} -else{ - C = outer(seq(1,m), t(A), "=="); -} - +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + + +A = read($1); +m = $2; +left = $3; + +if( left ){ + C = outer(A, t(seq(1,m)), "=="); +} +else{ + C = outer(seq(1,m), t(A), "=="); +} + write(C, $4); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/PackageFunCall1.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/PackageFunCall1.dml b/src/test/scripts/functions/misc/PackageFunCall1.dml index 6644006..3ea17cc 100644 --- a/src/test/scripts/functions/misc/PackageFunCall1.dml +++ b/src/test/scripts/functions/misc/PackageFunCall1.dml @@ -1,25 +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. -# -#------------------------------------------------------------- - - -source("PackageFunLib.dml") as Other -dummy = Other::hello() - +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + + +source("PackageFunLib.dml") as Other +dummy = Other::hello() + http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/PackageFunCall2.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/PackageFunCall2.dml b/src/test/scripts/functions/misc/PackageFunCall2.dml index b9b35b2..9453349 100644 --- a/src/test/scripts/functions/misc/PackageFunCall2.dml +++ b/src/test/scripts/functions/misc/PackageFunCall2.dml @@ -1,26 +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. -# -#------------------------------------------------------------- - - -setwd(".") -source("PackageFunLib.dml") as Other -dummy = Other::hello() - +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + + +setwd(".") +source("PackageFunLib.dml") as Other +dummy = Other::hello() + http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/PackageFunLib.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/PackageFunLib.dml b/src/test/scripts/functions/misc/PackageFunLib.dml index 2ed4325..e97b679 100644 --- a/src/test/scripts/functions/misc/PackageFunLib.dml +++ b/src/test/scripts/functions/misc/PackageFunLib.dml @@ -1,26 +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. -# -#------------------------------------------------------------- - - -hello = function() { - print("Hi!") -} - +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + + +hello = function() { + print("Hi!") +} + http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/ParForScalarAssignmentTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/ParForScalarAssignmentTest.dml b/src/test/scripts/functions/misc/ParForScalarAssignmentTest.dml index cc42f08..20ff692 100644 --- a/src/test/scripts/functions/misc/ParForScalarAssignmentTest.dml +++ b/src/test/scripts/functions/misc/ParForScalarAssignmentTest.dml @@ -19,10 +19,10 @@ # #------------------------------------------------------------- - -val = $1; -parfor( i in 1:10 ){ - val = $1; -} - + +val = $1; +parfor( i in 1:10 ){ + val = $1; +} + print(val); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/PrintExpressionTest1.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/PrintExpressionTest1.dml b/src/test/scripts/functions/misc/PrintExpressionTest1.dml index 0c7a475..b10bcfd 100644 --- a/src/test/scripts/functions/misc/PrintExpressionTest1.dml +++ b/src/test/scripts/functions/misc/PrintExpressionTest1.dml @@ -1,23 +1,23 @@ -#------------------------------------------------------------- -# -# 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 = TRUE; -print(!x); +#------------------------------------------------------------- +# +# 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 = TRUE; +print(!x); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/PrintExpressionTest2.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/PrintExpressionTest2.dml b/src/test/scripts/functions/misc/PrintExpressionTest2.dml index 251ce3a..36b9a41 100644 --- a/src/test/scripts/functions/misc/PrintExpressionTest2.dml +++ b/src/test/scripts/functions/misc/PrintExpressionTest2.dml @@ -1,23 +1,23 @@ -#------------------------------------------------------------- -# -# 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 = 7; -print(-x); +#------------------------------------------------------------- +# +# 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 = 7; +print(-x); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/PrintMatrixTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/PrintMatrixTest.dml b/src/test/scripts/functions/misc/PrintMatrixTest.dml index e380c0a..6f889e5 100644 --- a/src/test/scripts/functions/misc/PrintMatrixTest.dml +++ b/src/test/scripts/functions/misc/PrintMatrixTest.dml @@ -1,37 +1,37 @@ -#------------------------------------------------------------- -# -# 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. -# -#------------------------------------------------------------- - -printm = function(string name, matrix[double] M) return (matrix[double] M) { - print("printing matrix = " + name) - for (i in 1:nrow(M)) { - for (j in 1:ncol(M)) { - e = as.scalar(M[i,j]) - print(" " + i + " " + j + " " + e) - } - } - print("done printing matrix = " + name) - M = M -} - -MM1 = matrix(7, rows=2, cols=2) -str_name = "MM1" - +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +printm = function(string name, matrix[double] M) return (matrix[double] M) { + print("printing matrix = " + name) + for (i in 1:nrow(M)) { + for (j in 1:ncol(M)) { + e = as.scalar(M[i,j]) + print(" " + i + " " + j + " " + e) + } + } + print("done printing matrix = " + name) + M = M +} + +MM1 = matrix(7, rows=2, cols=2) +str_name = "MM1" + ignore = printm(str_name, MM1) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/ReadAfterWriteMatrix1.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/ReadAfterWriteMatrix1.dml b/src/test/scripts/functions/misc/ReadAfterWriteMatrix1.dml index 6c83c2e..7e9bc6e 100644 --- a/src/test/scripts/functions/misc/ReadAfterWriteMatrix1.dml +++ b/src/test/scripts/functions/misc/ReadAfterWriteMatrix1.dml @@ -19,10 +19,10 @@ # #------------------------------------------------------------- - -A = rand(rows=10, cols=10); -write(A, $1); - -B = read($2); -print(sum(B)); - + +A = rand(rows=10, cols=10); +write(A, $1); + +B = read($2); +print(sum(B)); + http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/ReadAfterWriteMatrix2.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/ReadAfterWriteMatrix2.dml b/src/test/scripts/functions/misc/ReadAfterWriteMatrix2.dml index 4a43aff..bfbb81d 100644 --- a/src/test/scripts/functions/misc/ReadAfterWriteMatrix2.dml +++ b/src/test/scripts/functions/misc/ReadAfterWriteMatrix2.dml @@ -19,12 +19,12 @@ # #------------------------------------------------------------- - -A = rand(rows=10, cols=10); -write(A, $1); - -if(1==1){} - -B = read($2); -print(sum(B)); - + +A = rand(rows=10, cols=10); +write(A, $1); + +if(1==1){} + +B = read($2); +print(sum(B)); + http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/ReadAfterWriteScalar1.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/ReadAfterWriteScalar1.dml b/src/test/scripts/functions/misc/ReadAfterWriteScalar1.dml index 689bf05..d089f4d 100644 --- a/src/test/scripts/functions/misc/ReadAfterWriteScalar1.dml +++ b/src/test/scripts/functions/misc/ReadAfterWriteScalar1.dml @@ -19,10 +19,10 @@ # #------------------------------------------------------------- - -A = 7; -write(A, $1); - -B = read($2); -print(B); - + +A = 7; +write(A, $1); + +B = read($2); +print(B); + http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/ReadAfterWriteScalar2.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/ReadAfterWriteScalar2.dml b/src/test/scripts/functions/misc/ReadAfterWriteScalar2.dml index 980cd67..43ff306 100644 --- a/src/test/scripts/functions/misc/ReadAfterWriteScalar2.dml +++ b/src/test/scripts/functions/misc/ReadAfterWriteScalar2.dml @@ -19,12 +19,12 @@ # #------------------------------------------------------------- - -A = 7; -write(A, $1); - -if(1==1){} - -B = read($2); -print(B); - + +A = 7; +write(A, $1); + +if(1==1){} + +B = read($2); +print(B); + http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/05d2c0a8/src/test/scripts/functions/misc/RewriteColSumsMVMult.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/RewriteColSumsMVMult.R b/src/test/scripts/functions/misc/RewriteColSumsMVMult.R index e83c3d0..15893ad 100644 --- a/src/test/scripts/functions/misc/RewriteColSumsMVMult.R +++ b/src/test/scripts/functions/misc/RewriteColSumsMVMult.R @@ -19,12 +19,12 @@ # #------------------------------------------------------------- - -args <- commandArgs(TRUE) -options(digits=22) -library("Matrix") - -X = as.matrix(readMM(paste(args[1], "X.mtx", sep=""))) -R = colSums( X * seq(1,nrow(X))%*%matrix(1,1,ncol(X)) ); - -writeMM(as(R, "CsparseMatrix"), paste(args[2], "R", sep="")); + +args <- commandArgs(TRUE) +options(digits=22) +library("Matrix") + +X = as.matrix(readMM(paste(args[1], "X.mtx", sep=""))) +R = colSums( X * seq(1,nrow(X))%*%matrix(1,1,ncol(X)) ); + +writeMM(as(R, "CsparseMatrix"), paste(args[2], "R", sep=""));
