You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@madlib.apache.org by ri...@apache.org on 2015/12/07 19:54:56 UTC

incubator-madlib git commit: Matrix: Fix multiple input/output issues

Repository: incubator-madlib
Updated Branches:
  refs/heads/master cd12983cb -> e2af00331


Matrix: Fix multiple input/output issues

JIRA: MADLIB-932

This commit contains fixes for following issues:
    - 'inf' or 'infinity' was read by Python as a float value. This has
      been fixed by checking for supported strings before checking for
      float.
    - matrix_inverse and matrix_pinv were not using out_args for output
      column names.
    - matrix_eigen did not accept an out_args parameter that determines the
      output column names.
    - Multiple methods did not provide a default value for out_args.
    - All decomposition methods had incorrect usage for in_args and
      out_args. These have been fixed with the output being sparse or
      dense (determined by the fmt specifier in out_args).


Project: http://git-wip-us.apache.org/repos/asf/incubator-madlib/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-madlib/commit/e2af0033
Tree: http://git-wip-us.apache.org/repos/asf/incubator-madlib/tree/e2af0033
Diff: http://git-wip-us.apache.org/repos/asf/incubator-madlib/diff/e2af0033

Branch: refs/heads/master
Commit: e2af00331e502c8a154364d99301db58f4ef7b6e
Parents: cd12983
Author: Rahul Iyer <ra...@gmail.com>
Authored: Wed Dec 2 16:33:10 2015 -0800
Committer: Rahul Iyer <ri...@pivotal.io>
Committed: Fri Dec 4 14:33:31 2015 -0800

----------------------------------------------------------------------
 .../postgres/modules/linalg/matrix_ops.py_in    | 107 ++++++------
 .../postgres/modules/linalg/matrix_ops.sql_in   | 168 +++++++++++--------
 2 files changed, 155 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/e2af0033/src/ports/postgres/modules/linalg/matrix_ops.py_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/linalg/matrix_ops.py_in b/src/ports/postgres/modules/linalg/matrix_ops.py_in
index 92f2f56..1bc4c04 100644
--- a/src/ports/postgres/modules/linalg/matrix_ops.py_in
+++ b/src/ports/postgres/modules/linalg/matrix_ops.py_in
@@ -2305,27 +2305,31 @@ def matrix_norm(schema_madlib, matrix_in, in_args, norm_type):
     _validate_input_table(matrix_in)
     in_args = parse_matrix_args(in_args)
     norm_type = 'fro' if not norm_type else str(norm_type).lower()
-    if 'frobenius'.startswith(norm_type):
-        # frobenius norm is same as element-wise 2-norm
-        norm_type = '2'
+
+    # norm_type can be a prefix of any of the below supported types
+    supported_norm_types = ['one', 'spectral', 'infinity', 'max', 'frobenius']
     try:
-        param = float(norm_type)
-        _assert(param > 0,
-                "Matrix error: Element-wise norm ({0}) should be a positive value."
-                .format(param))
-        return _matrix_elem_norm(schema_madlib, matrix_in, in_args, param)
-    except ValueError:
-        # if norm_type is not float then we interpret it as a string
-        # norm_type can be a prefix of any of the below supported types
-        supported_norm_types = ['one', 'spectral', 'infinity', 'max']
-        try:
-            norm_type_val = next(x for x in supported_norm_types
-                                 if x.startswith(norm_type))
+        norm_type_val = next(x for x in supported_norm_types
+                             if x.startswith(norm_type))
+        if norm_type_val == "frobenius":
+            # frobenius norm is same as element-wise 2-norm
+            return _matrix_elem_norm(schema_madlib, matrix_in, in_args, 2)
+        else:
             return _matrix_induced_norm(schema_madlib, matrix_in, in_args, norm_type_val)
-        except StopIteration:
-            # next() returns a StopIteration if no element found
-            plpy.error("Matrix Error: Invalid norm type: {0}. Supported norm types are ({1})"
-                       .format(norm_type, ','.join(sorted(supported_norm_types))))
+    except StopIteration:
+        # next() returns a StopIteration if no element found
+        # If norm_type is not a supported string then it has be a positive float
+        try:
+            param = float(norm_type)
+            _assert(param > 0,
+                    "Matrix error: Element-wise norm ({0}) should be a positive value."
+                    .format(param))
+            return _matrix_elem_norm(schema_madlib, matrix_in, in_args, param)
+        except ValueError:
+            plpy.error("Matrix Error: Invalid norm type: {0}. "
+                       "It can either be a positive float or (subset string) of "
+                       "one of the supported norm types ({1})"
+                       .format(norm_type, ', '.join(sorted(supported_norm_types))))
 # ------------------------------------------------------------------------------
 
 
@@ -2360,8 +2364,8 @@ def matrix_transform_helper(schema_madlib, matrix_in, in_args, matrix_out,
     matrix_r = "pg_temp." + unique_string() if is_output_sparse else matrix_out
     plpy.execute("""
         CREATE TABLE {matrix_r} AS
-        SELECT row_id,
-               {schema_madlib}.get_row(res, row_id) as row_vec
+        SELECT row_id as {out_args[row]},
+               {schema_madlib}.get_row(res, row_id) as {out_args[val]}
         FROM (
               SELECT {agg_str} as res
               FROM {matrix_in}
@@ -2407,7 +2411,7 @@ def matrix_inverse(schema_madlib, matrix_in, in_args, matrix_out, out_args):
 # ------------------------------------------------------------------------------
 
 
-def matrix_eigen(schema_madlib, matrix_in, in_args, matrix_out):
+def matrix_eigen(schema_madlib, matrix_in, in_args, matrix_out, out_args):
     """ Compute the eigen values of a matrix.
 
     The eigenvalues are repeated according to their algebraic multiplicity, so
@@ -2423,7 +2427,11 @@ def matrix_eigen(schema_madlib, matrix_in, in_args, matrix_out):
             "Matrix error: Invalid dimensions for input matrix")
     _assert(dim[0] == dim[1],
             "Matrix error: Eigen value is only defined for square matrices")
-    # FIXME: currently matrix inverse is computed on a single node after collating
+    out_args = parse_matrix_args(out_args,
+                                 in_default_args={'row': in_args['row'],
+                                                  'col': in_args['col'],
+                                                  'val': 'eigen_values'})
+    # FIXME: currently matrix eigen is computed on a single node after collating
     # a distributed matrix. This places a limit on the maximum size of the matrix
     # GPDB limit = 1GB implying size * size < 10^9 / 8 i.e. size <= 11100
     max_size = 11100
@@ -2454,8 +2462,8 @@ def matrix_eigen(schema_madlib, matrix_in, in_args, matrix_out):
                                  in_args=in_args)
     plpy.execute("""
         CREATE TABLE {matrix_out} AS
-        SELECT row_id,
-               row(value[1], value[2])::{schema_madlib}.complex as eigen
+        SELECT row_id as {out_args[row]},
+               row(value[1], value[2])::{schema_madlib}.complex as {out_args[val]}
         FROM (
             SELECT row_id,
                    {schema_madlib}.get_row(res, row_id) as value
@@ -2532,7 +2540,6 @@ def matrix_cholesky(schema_madlib, matrix_in, in_args,
                 """.format(schema_madlib=schema_madlib, n_rows=dim[0],
                            in_args=in_args)
     matrix_temp = "pg_temp." + unique_string()
-    temp_args = {'row': 'row_id', 'val': 'row_vec'}
     plpy.execute("""
         CREATE TABLE {matrix_temp} AS
         SELECT row_id,
@@ -2546,31 +2553,34 @@ def matrix_cholesky(schema_madlib, matrix_in, in_args,
     matrix_p_temp = "pg_temp." + unique_string() if is_output_sparse else matrix_p
     plpy.execute("""
         CREATE TABLE {matrix_p_temp} AS
-        SELECT row_id, row_vec[1:{dim[0]}] AS row_vec
+        SELECT row_id AS {out_args[row]},
+               row_vec[1:{dim[0]}] AS {out_args[val]}
         FROM {matrix_temp}
         """.format(**locals()))
     if is_output_sparse:
-        matrix_sparsify(schema_madlib, matrix_p_temp, temp_args, matrix_p, out_args)
+        matrix_sparsify(schema_madlib, matrix_p_temp, out_args, matrix_p, out_args)
         plpy.execute('DROP TABLE IF EXISTS %s' % matrix_p_temp)
 
     matrix_l_temp = "pg_temp." + unique_string() if is_output_sparse else matrix_l
     plpy.execute("""
         CREATE TABLE {matrix_l_temp} AS
-        SELECT row_id AS row_id, row_vec[{dim[0]} + 1 : {dim[0]} * 2] AS row_vec
+        SELECT row_id AS {out_args[row]},
+               row_vec[{dim[0]} + 1 : {dim[0]} * 2] AS {out_args[val]}
         FROM {matrix_temp}
         """.format(**locals()))
     if is_output_sparse:
-        matrix_sparsify(schema_madlib, matrix_l_temp, temp_args, matrix_l, out_args)
+        matrix_sparsify(schema_madlib, matrix_l_temp, out_args, matrix_l, out_args)
         plpy.execute('DROP TABLE IF EXISTS %s' % matrix_l_temp)
 
     matrix_d_temp = "pg_temp." + unique_string() if is_output_sparse else matrix_d
     plpy.execute("""
         CREATE TABLE {matrix_d_temp} AS
-        SELECT row_id AS row_id, row_vec[{dim[0]} * 2 + 1: {dim[0]} * 3] AS row_vec
+        SELECT row_id AS {out_args[row]},
+               row_vec[{dim[0]} * 2 + 1: {dim[0]} * 3] AS {out_args[val]}
         FROM {matrix_temp}
         """.format(**locals()))
     if is_output_sparse:
-        matrix_sparsify(schema_madlib, matrix_d_temp, temp_args, matrix_d, out_args)
+        matrix_sparsify(schema_madlib, matrix_d_temp, out_args, matrix_d, out_args)
         plpy.execute('DROP TABLE IF EXISTS %s' % matrix_d_temp)
     plpy.execute('DROP TABLE IF EXISTS %s' % matrix_temp)
 # ------------------------------------------------------------------------------
@@ -2633,7 +2643,6 @@ def matrix_qr(schema_madlib, matrix_in, in_args, matrix_out_prefix, out_args):
                 """.format(schema_madlib=schema_madlib, n_rows=dim[0],
                            in_args=in_args)
     matrix_temp = "pg_temp." + unique_string()
-    temp_args = {'row': 'row_id', 'val': 'row_vec'}
     plpy.execute("""
         CREATE TABLE {matrix_temp} AS
         SELECT row_id,
@@ -2647,21 +2656,23 @@ def matrix_qr(schema_madlib, matrix_in, in_args, matrix_out_prefix, out_args):
     matrix_q_temp = "pg_temp." + unique_string() if is_output_sparse else matrix_q
     plpy.execute("""
         CREATE TABLE {matrix_q_temp} AS
-        SELECT row_id, row_vec[1:{dim[0]}] AS row_vec
+        SELECT row_id as {out_args[row]},
+               row_vec[1:{dim[0]}] AS {out_args[val]}
         FROM {matrix_temp}
         """.format(**locals()))
     if is_output_sparse:
-        matrix_sparsify(schema_madlib, matrix_q_temp, temp_args, matrix_q, out_args)
+        matrix_sparsify(schema_madlib, matrix_q_temp, out_args, matrix_q, out_args)
         plpy.execute('DROP TABLE IF EXISTS %s' % matrix_q_temp)
 
     matrix_r_temp = "pg_temp." + unique_string() if is_output_sparse else matrix_r
     plpy.execute("""
         CREATE TABLE {matrix_r_temp} AS
-        SELECT row_id AS row_id, row_vec[{dim[0]} + 1 : {dim[0]} + {dim[1]}] AS row_vec
+        SELECT row_id as {out_args[row]},
+               row_vec[{dim[0]} + 1 : {dim[0]} + {dim[1]}] AS {out_args[val]}
         FROM {matrix_temp}
         """.format(**locals()))
     if is_output_sparse:
-        matrix_sparsify(schema_madlib, matrix_r_temp, temp_args, matrix_r, out_args)
+        matrix_sparsify(schema_madlib, matrix_r_temp, out_args, matrix_r, out_args)
         plpy.execute('DROP TABLE IF EXISTS %s' % matrix_r_temp)
     plpy.execute('DROP TABLE IF EXISTS %s' % matrix_temp)
 # ------------------------------------------------------------------------------
@@ -2744,8 +2755,8 @@ def matrix_lu(schema_madlib, matrix_in, in_args,
     _validate_input_table(matrix_in)
     _assert(matrix_out_prefix is not None and matrix_out_prefix.replace('"', '').strip() != '',
             "Matrix error: Invalid output prefix ({0})".format(matrix_out_prefix))
-    matrix_p, matrix_l, matrix_u, matrix_q = (
-        add_postfix(matrix_out_prefix, i) for i in ("_p", "_l", "_u", "_q"))
+    matrix_p, matrix_l, matrix_u, matrix_q = (add_postfix(matrix_out_prefix, i)
+                                              for i in ("_p", "_l", "_u", "_q"))
     for each_output in (matrix_p, matrix_l, matrix_u, matrix_q):
         _validate_output_table(each_output)
 
@@ -2802,7 +2813,8 @@ def matrix_lu(schema_madlib, matrix_in, in_args,
     matrix_p_temp = "pg_temp." + unique_string() if is_output_sparse else matrix_p
     plpy.execute("""
         CREATE TABLE {matrix_p_temp} AS
-        SELECT row_id, row_vec[1:{dim[0]}] AS row_vec
+        SELECT row_id AS {out_args[row]},
+               row_vec[1:{dim[0]}] AS {out_args[val]}
         FROM {matrix_temp} WHERE row_id <= {dim[0]}
         """.format(**locals()))
     if is_output_sparse:
@@ -2812,7 +2824,8 @@ def matrix_lu(schema_madlib, matrix_in, in_args,
     matrix_l_temp = "pg_temp." + unique_string() if is_output_sparse else matrix_l
     plpy.execute("""
         CREATE TABLE {matrix_l_temp} AS
-        SELECT row_id, row_vec[{dim[0]} + 1 : 2 * {dim[0]}] AS row_vec
+        SELECT row_id AS {out_args[row]},
+               row_vec[{dim[0]} + 1 : 2 * {dim[0]}] AS {out_args[val]}
         FROM {matrix_temp} WHERE row_id <= {dim[0]}
         """.format(**locals()))
     if is_output_sparse:
@@ -2822,7 +2835,8 @@ def matrix_lu(schema_madlib, matrix_in, in_args,
     matrix_u_temp = "pg_temp." + unique_string() if is_output_sparse else matrix_u
     plpy.execute("""
         CREATE TABLE {matrix_u_temp} AS
-        SELECT row_id, row_vec[2 * {dim[0]} + 1 : 2 * {dim[0]} + {dim[1]}] AS row_vec
+        SELECT row_id AS {out_args[row]},
+               row_vec[2 * {dim[0]} + 1 : 2 * {dim[0]} + {dim[1]}] AS {out_args[val]}
         FROM {matrix_temp} WHERE row_id <= {dim[0]}
         """.format(**locals()))
     if is_output_sparse:
@@ -2832,7 +2846,8 @@ def matrix_lu(schema_madlib, matrix_in, in_args,
     matrix_q_temp = "pg_temp." + unique_string() if is_output_sparse else matrix_q
     plpy.execute("""
         CREATE TABLE {matrix_q_temp} AS
-        SELECT row_id, row_vec[2 * {dim[0]} + {dim[1]} + 1:2 * {dim[0]} + 2 * {dim[1]}] AS row_vec
+        SELECT row_id AS {out_args[row]},
+               row_vec[2 * {dim[0]} + {dim[1]} + 1:2 * {dim[0]} + 2 * {dim[1]}] AS {out_args[val]}
         FROM {matrix_temp} WHERE row_id <= {dim[1]}
         """.format(**locals()))
     if is_output_sparse:
@@ -3022,10 +3037,8 @@ def _matrix_create_scalar(schema_madlib, row_dim, col_dim, matrix_out, out_args,
     _assert(scalar is not None,
             "Matrix error: Invalid none value for elements.")
 
-    out_args = parse_matrix_args(out_args,
-                                 in_default_args={'row': 'row',
-                                                  'col': 'col',
-                                                  'val': 'val'})
+    out_args = parse_matrix_args(
+        out_args, in_default_args={'row': 'row', 'col': 'col', 'val': 'val'})
 
     if 'fmt' not in out_args or out_args['fmt'] == 'sparse':
         if scalar != 0:

http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/e2af0033/src/ports/postgres/modules/linalg/matrix_ops.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/linalg/matrix_ops.sql_in b/src/ports/postgres/modules/linalg/matrix_ops.sql_in
index 92c46db..eb70e60 100644
--- a/src/ports/postgres/modules/linalg/matrix_ops.sql_in
+++ b/src/ports/postgres/modules/linalg/matrix_ops.sql_in
@@ -1168,22 +1168,6 @@ PythonFunction(linalg, matrix_help_message, matrix_add_help_message)
 $$ LANGUAGE plpythonu IMMUTABLE
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `CONTAINS SQL', `');
 
-CREATE OR REPLACE FUNCTION
-MADLIB_SCHEMA.matrix_add
-(
-    matrix_a        TEXT,
-    a_args          TEXT,
-    matrix_b        TEXT,
-    b_args          TEXT,
-    matrix_out      TEXT
-)
-RETURNS MADLIB_SCHEMA.matrix_result AS $$
-    SELECT
-        MADLIB_SCHEMA.matrix_add(
-            $1, $2, $3, $4, $5, NULL);
-$$ LANGUAGE sql
-m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
-
 CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.matrix_add()
 RETURNS TEXT AS $$
 BEGIN
@@ -1404,7 +1388,6 @@ RETURNS MADLIB_SCHEMA.matrix_result AS $$
 $$ LANGUAGE SQL
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
-
 CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.matrix_zeros(
     message     TEXT
 ) RETURNS TEXT AS $$
@@ -1455,6 +1438,20 @@ RETURNS MADLIB_SCHEMA.matrix_result AS $$
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
+CREATE OR REPLACE FUNCTION
+MADLIB_SCHEMA.matrix_max
+(
+    matrix_in      TEXT,
+    in_args        TEXT,
+    dim            INTEGER,
+    matrix_out     TEXT
+)
+RETURNS MADLIB_SCHEMA.matrix_result AS $$
+    SELECT MADLIB_SCHEMA.matrix_max($1, $2, $3, $4, FALSE);
+$$ LANGUAGE SQL
+m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
+
+
 CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.matrix_max(
     message     TEXT
 ) RETURNS TEXT AS $$
@@ -1506,6 +1503,19 @@ RETURNS MADLIB_SCHEMA.matrix_result AS $$
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
+CREATE OR REPLACE FUNCTION
+MADLIB_SCHEMA.matrix_min
+(
+    matrix_in      TEXT,
+    in_args        TEXT,
+    dim            INTEGER,
+    matrix_out     TEXT
+)
+RETURNS MADLIB_SCHEMA.matrix_result AS $$
+    SELECT MADLIB_SCHEMA.matrix_min($1, $2, $3, $4, FALSE);
+$$ LANGUAGE SQL
+m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
+
 CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.matrix_min(
     message     TEXT
 ) RETURNS TEXT AS $$
@@ -1547,6 +1557,17 @@ RETURNS FLOAT8[] AS $$
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
+CREATE OR REPLACE FUNCTION
+MADLIB_SCHEMA.matrix_sum
+(
+    matrix_in      TEXT,
+    in_args        TEXT
+)
+RETURNS FLOAT8[] AS $$
+    SELECT MADLIB_SCHEMA.matrix_sum($1, $2, 1);
+$$ LANGUAGE SQL
+m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
+
 CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.matrix_sum(
     message     TEXT
 ) RETURNS TEXT AS $$
@@ -1588,6 +1609,17 @@ RETURNS FLOAT8[] AS $$
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
+CREATE OR REPLACE FUNCTION
+MADLIB_SCHEMA.matrix_mean
+(
+    matrix_in      TEXT,
+    in_args        TEXT
+)
+RETURNS FLOAT8[] AS $$
+    SELECT MADLIB_SCHEMA.matrix_mean($1, $2, 1);
+$$ LANGUAGE SQL
+m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
+
 CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.matrix_mean(
     message     TEXT
 ) RETURNS TEXT AS $$
@@ -1636,6 +1668,16 @@ $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
 CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.matrix_scalar_mult(
+    matrix_in      TEXT,
+    in_args        TEXT,
+    scalar         FLOAT8,
+    matrix_out     TEXT
+) RETURNS MADLIB_SCHEMA.matrix_result AS $$
+    SELECT MADLIB_SCHEMA.matrix_scalar_mult($1, $2, $3, $4, ''::text);
+$$ LANGUAGE SQL
+m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
+
+CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.matrix_scalar_mult(
     message     TEXT
 ) RETURNS TEXT AS $$
 PythonFunction(linalg, matrix_help_message, matrix_scalar_mult_help_message)
@@ -1744,7 +1786,6 @@ RETURNS MADLIB_SCHEMA.matrix_result AS $$
 $$ LANGUAGE SQL
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
-
 CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.matrix_elem_mult(
     message     TEXT
 ) RETURNS TEXT AS $$
@@ -1752,23 +1793,6 @@ PythonFunction(linalg, matrix_help_message, matrix_elem_mult_help_message)
 $$ LANGUAGE plpythonu IMMUTABLE
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `CONTAINS SQL', `');
 
-CREATE OR REPLACE FUNCTION
-MADLIB_SCHEMA.matrix_elem_mult
-(
-    matrix_a        TEXT,
-    a_args          TEXT,
-    matrix_b        TEXT,
-    b_args          TEXT,
-    matrix_out      TEXT
-)
-RETURNS MADLIB_SCHEMA.matrix_result AS $$
-    SELECT
-        MADLIB_SCHEMA.matrix_elem_mult(
-            $1, $2, $3, $4, $5, NULL);
-$$ LANGUAGE sql
-m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
-
-
 CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.matrix_elem_mult()
 RETURNS TEXT AS $$
 BEGIN
@@ -1816,10 +1840,8 @@ MADLIB_SCHEMA.matrix_trans
     matrix_out      TEXT
 )
 RETURNS MADLIB_SCHEMA.matrix_result AS $$
-    SELECT
-        MADLIB_SCHEMA.matrix_trans(
-            $1, $2, $3, NULL);
-$$ LANGUAGE sql
+    SELECT MADLIB_SCHEMA.matrix_trans($1, $2, $3, ''::TEXT);
+$$ LANGUAGE SQL
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
 CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.matrix_trans(
@@ -1858,8 +1880,8 @@ MADLIB_SCHEMA.matrix_sparsify
 )
 RETURNS MADLIB_SCHEMA.matrix_result AS $$
     PythonFunctionBodyOnly(`linalg', `matrix_ops')
-    matrix_ops.matrix_sparsify(schema_madlib, matrix_in, in_args, matrix_out,
-                               out_args)
+    matrix_ops.matrix_sparsify(schema_madlib, matrix_in, in_args,
+                               matrix_out, out_args)
     return [matrix_out]
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
@@ -1873,7 +1895,7 @@ MADLIB_SCHEMA.matrix_sparsify
     matrix_out      TEXT
 )
 RETURNS MADLIB_SCHEMA.matrix_result AS $$
-    SELECT MADLIB_SCHEMA.matrix_sparsify($1, $2, $3, '');
+    SELECT MADLIB_SCHEMA.matrix_sparsify($1, $2, $3, ''::TEXT);
 $$ LANGUAGE SQL
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
@@ -1923,7 +1945,6 @@ RETURNS MADLIB_SCHEMA.matrix_result AS $$
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
-
 CREATE OR REPLACE FUNCTION
 MADLIB_SCHEMA.matrix_densify
 (
@@ -1932,7 +1953,7 @@ MADLIB_SCHEMA.matrix_densify
     matrix_out      TEXT
 )
 RETURNS MADLIB_SCHEMA.matrix_result AS $$
-    SELECT MADLIB_SCHEMA.matrix_densify($1, $2, $3, '');
+    SELECT MADLIB_SCHEMA.matrix_densify($1, $2, $3, ''::TEXT);
 $$ LANGUAGE SQL
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
@@ -1987,6 +2008,20 @@ PythonFunction(linalg, matrix_ops, matrix_scale_and_add)
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
+CREATE OR REPLACE FUNCTION  MADLIB_SCHEMA.matrix_scale_and_add(
+    matrix_a    TEXT,
+    a_args      TEXT,
+    matrix_b    TEXT,
+    b_args      TEXT,
+    scale       DOUBLE PRECISION,
+    matrix_out  TEXT
+)
+RETURNS VOID AS $$
+  SELECT MADLIB_SCHEMA.matrix_scale_and_add(
+      $1, $2, $3, $4, $5, $6, ''::TEXT)
+$$ LANGUAGE SQL
+m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
+
 
 ------------------ Matrix Norms ------------------------------
 
@@ -2023,28 +2058,13 @@ PythonFunctionBodyOnly(`linalg', `matrix_ops')
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `READS SQL DATA', `');
 
-/**
- * @brief Compute matrix norm of fro
- *
- * @param matrix_a Source matrix table (dense matrix format)
- *
- * @return DOUBLE PRECISION
- *
- * @usage Currenty, we support the following norms
- * (a) 'fro': Computes the frobenius norm
- *
- * <pre>
- * SELECT matrix_norm('<em>matrix_table_name</em>', 'fro');
- * </pre>
- */
-
 CREATE OR REPLACE FUNCTION
 MADLIB_SCHEMA.matrix_norm(
     matrix_in    TEXT,
     in_args      TEXT
 )
 RETURNS DOUBLE PRECISION AS $$
-    SELECT MADLIB_SCHEMA.matrix_norm($1, $2, NULL)
+    SELECT MADLIB_SCHEMA.matrix_norm($1, $2, 'fro'::TEXT)
 $$ LANGUAGE SQL
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `READS SQL DATA', `');
 
@@ -2083,7 +2103,6 @@ RETURNS MADLIB_SCHEMA.matrix_result AS $$
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
-
 CREATE OR REPLACE FUNCTION
 MADLIB_SCHEMA.matrix_block_square
 (
@@ -2100,7 +2119,6 @@ RETURNS MADLIB_SCHEMA.matrix_result AS $$
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
-
 CREATE OR REPLACE FUNCTION
 MADLIB_SCHEMA.matrix_block_trans
 (
@@ -2144,7 +2162,6 @@ RETURNS MADLIB_SCHEMA.matrix_result AS $$
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
-
 CREATE OR REPLACE FUNCTION
 MADLIB_SCHEMA.matrix_square
 (
@@ -2230,13 +2247,6 @@ MADLIB_SCHEMA.matrix_extract_diag
     matrix_in      TEXT,
     in_args        TEXT
 )
-/**
-RETURNS MADLIB_SCHEMA.matrix_result AS $$
-    PythonFunctionBodyOnly(`linalg', `matrix_ops')
-    matrix_ops.matrix_extract_diag(schema_madlib,
-        matrix_in, in_args, matrix_out, out_args)
-    return [matrix_out]
-*/
 RETURNS float[] AS $$
     PythonFunctionBodyOnly(`linalg', `matrix_ops')
     return  matrix_ops.matrix_extract_diag(schema_madlib, matrix_in, in_args)
@@ -2500,7 +2510,6 @@ RETURNS MADLIB_SCHEMA.matrix_result AS $$
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
-
 CREATE OR REPLACE FUNCTION
 MADLIB_SCHEMA.matrix_pinv
 (
@@ -2599,16 +2608,29 @@ MADLIB_SCHEMA.matrix_eigen
 (
     matrix_in   TEXT,
     in_args     TEXT,
-    matrix_out  TEXT
+    matrix_out  TEXT,
+    out_args    TEXT
 )
 RETURNS MADLIB_SCHEMA.matrix_result AS $$
     PythonFunctionBodyOnly(`linalg', `matrix_ops')
     matrix_ops.matrix_eigen(schema_madlib, matrix_in, in_args,
-                            matrix_out)
+                            matrix_out, out_args)
     return [matrix_out]
 $$ LANGUAGE plpythonu
 m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
 
+CREATE OR REPLACE FUNCTION
+MADLIB_SCHEMA.matrix_eigen
+(
+    matrix_in   TEXT,
+    in_args     TEXT,
+    matrix_out  TEXT
+)
+RETURNS MADLIB_SCHEMA.matrix_result AS $$
+    SELECT MADLIB_SCHEMA.matrix_eigen($1, $2, $3, ''::TEXT)
+$$ LANGUAGE SQL
+m4_ifdef(`__HAS_FUNCTION_PROPERTIES__', `MODIFIES SQL DATA', `');
+
 CREATE OR REPLACE FUNCTION MADLIB_SCHEMA.matrix_eigen(
     message     TEXT
 ) RETURNS TEXT AS $$