1.8
User Documentation for MADlib
matrix_ops.sql_in File Reference

Implementation of matrix operations in SQL. More...

Functions

text matrix_info (text message)
 
text matrix_info ()
 
matrix_result matrix_mult (text matrix_a, text a_args, text matrix_b, text b_args, text matrix_out, text out_args)
 Multiplies two matrices. It requires that all the values are NON-NULL. This is the sparse representation of the matrix where the matrix elements are indexed by the row and column index. More...
 
matrix_result matrix_mult (text matrix_a, text a_args, text matrix_b, text b_args, text matrix_out)
 
text matrix_mult (text message)
 
text matrix_mult ()
 
matrix_result matrix_add (text matrix_a, text a_args, text matrix_b, text b_args, text matrix_out, text out_args)
 Adds two matrices. It requires that all the values are NON-NULL. This is the sparse representation of the matrix where the matrix elements are indexed by the row and column index. More...
 
matrix_result matrix_add (text matrix_a, text a_args, text matrix_b, text b_args, text matrix_out)
 
text matrix_add (text message)
 
text matrix_add ()
 
matrix_result matrix_sub (text matrix_a, text a_args, text matrix_b, text b_args, text matrix_out, text out_args)
 Subs two matrices. It requires that all the values are NON-NULL. This is the sparse representation of the matrix where the matrix elements are indexed by the row and column id. More...
 
matrix_result matrix_sub (text matrix_a, text a_args, text matrix_b, text b_args, text matrix_out)
 
text matrix_sub (text message)
 
text matrix_sub ()
 
float8[] matrix_extract_row (text matrix_in, text in_args, integer index)
 Extract row from matrix given row index. It requires that all the values are NON-NULL. This is the dense or sparse representation of the matrix where the matrix elements are indexed by row id for dense and by the row and column id for sparse. More...
 
text matrix_extract_row (text message)
 
text matrix_extract_row ()
 
float8[] matrix_extract_col (text matrix_in, text in_args, integer index)
 Extract column from matrix given column index. It requires that all the values are NON-NULL. This is the dense or sparse representation of the matrix where the matrix elements are indexed by row id for dense and by the row and column id for sparse. More...
 
text matrix_extract_col (text message)
 
text matrix_extract_col ()
 
matrix_result matrix_max (text matrix_in, text in_args, integer dim, text matrix_out, boolean fetch_index)
 Get max value along dimension from matrix. Also returns corresponding index if set fetch_index. It requires that all the values are NON-NULL. This is the dense or sparse representation of the matrix where the matrix elements are indexed by row id for dense and by the row and column id for sparse. More...
 
text matrix_max (text message)
 
text matrix_max ()
 
matrix_result matrix_min (text matrix_in, text in_args, integer dim, text matrix_out, boolean fetch_index)
 Get min value along dimension from matrix. Also returns corresponding index if set fetch_index. It requires that all the values are NON-NULL. This is the dense or sparse representation of the matrix where the matrix elements are indexed by row id for dense and by the row and column id for sparse. More...
 
text matrix_min (text message)
 
text matrix_min ()
 
float8[] matrix_sum (text matrix_in, text in_args, integer dim)
 Calculate sum along dimension for matrix. It requires that all the values are NON-NULL. This is the sparse representation of the matrix where the matrix elements are indexed by the row and column id. More...
 
text matrix_sum (text message)
 
text matrix_sum ()
 
float8[] matrix_mean (text matrix_in, text in_args, integer dim)
 Calculate mean along dimension for matrix. It requires that all the values are NON-NULL. This is the sparse representation of the matrix where the matrix elements are indexed by the row and column id. More...
 
text matrix_mean (text message)
 
text matrix_mean ()
 
matrix_result matrix_scalar_mult (text matrix_in, text in_args, float8 scalar, text matrix_out, text out_args)
 Multiplies one matrix with scalar. It requires that all the values are NON-NULL. This is the sparse representation of the matrix where the matrix elements are indexed by the row and column id. More...
 
text matrix_scalar_mult (text message)
 
text matrix_scalar_mult ()
 
float8[] matrix_vec_mult (text matrix_in, text in_args, float8[] vector)
 Multiplies one matrix with vector. It requires that all the values are NON-NULL. This is the sparse representation of the matrix where the matrix elements are indexed by the row and column id. More...
 
text matrix_vec_mult (text message)
 
text matrix_vec_mult ()
 
matrix_result matrix_elem_mult (text matrix_a, text a_args, text matrix_b, text b_args, text matrix_out, text out_args)
 Multiplies two matrices by element. It requires that all the values are NON-NULL. This is the sparse representation of the matrix where the matrix elements are indexed by the row and column id. More...
 
matrix_result matrix_elem_mult (text matrix_a, text a_args, text matrix_b, text b_args, text matrix_out)
 
text matrix_elem_mult (text message)
 
text matrix_elem_mult ()
 
matrix_result matrix_trans (text matrix_in, text in_args, text matrix_out, text out_args, boolean use_temp_table)
 Transpose matrix. It requires that all the values are NON-NULL. This is the sparse representation of the matrix where the matrix elements are indexed by the row and column index. More...
 
matrix_result matrix_trans (text matrix_in, text in_args, text matrix_out, text out_args)
 
matrix_result matrix_trans (text matrix_in, text in_args, text matrix_out)
 
text matrix_trans (text message)
 
text matrix_trans ()
 
matrix_result matrix_sparsify (text matrix_in, text in_args, text matrix_out, text out_args, boolean use_temp_table)
 Converts matrix to sparse representation. It requires that all the values are NON-NULL. This is the dense representation of the matrix where the matrix elements are indexed by the row and column index. More...
 
matrix_result matrix_sparsify (text matrix_in, text in_args, text matrix_out, text out_args)
 
matrix_result matrix_sparsify (text matrix_in, text in_args, text matrix_out)
 
text matrix_sparsify (text message)
 
text matrix_sparsify ()
 
matrix_result matrix_densify (text matrix_in, text in_args, text matrix_out, text out_args, boolean use_temp_table)
 Converts matrix to dense representation. It requires that all the values are NON-NULL. This is the sparse representation of the matrix where the matrix elements are indexed by the row index. More...
 
matrix_result matrix_densify (text matrix_in, text in_args, text matrix_out, text out_args)
 
matrix_result matrix_densify (text matrix_in, text in_args, text matrix_out)
 
text matrix_densify (text message)
 
text matrix_densify ()
 
void matrix_scale_and_add (text matrix_a, text a_args, text matrix_b, text b_args, float8 scale, text matrix_out, text out_args)
 Scale and add matrix operation ( R <- A + sB) More...
 
float8 matrix_norm (text matrix_in, text in_args, text norm_type)
 Compute matrix norm (of various types) More...
 
float8 matrix_norm (text matrix_in, text in_args)
 Compute matrix norm of fro. More...
 
matrix_result matrix_block_mult (text matrix_a, text a_args, text matrix_b, text b_args, text matrix_out, text out_args)
 
matrix_result matrix_block_square (text matrix_in, text in_args, text matrix_out, text out_args)
 
matrix_result matrix_block_trans (text matrix_in, text in_args, text matrix_out, text out_args, boolean use_temp_table)
 
matrix_result matrix_block_trans (text matrix_in, text in_args, text matrix_out, text out_args)
 
matrix_result matrix_square (text matrix_in, text in_args, text matrix_out, text out_args)
 Calculate square of matrix. It requires that all the values are NON-NULL. This is the dense representation of the matrix where the matrix elements are indexed by the row index. More...
 
matrix_result matrix_square (text matrix_in, text in_args, text matrix_out)
 
integer[] __rand_vector (integer dim)
 
integer[] __rand_block (integer row_dim, integer col_dim)
 
integer[] __rand_block (integer dim)
 
set< float8[]> __matrix_row_split (float8[] row_in, integer size)
 
float8[] __matrix_densify_sfunc (float8[] state, integer col_dim, integer col_id, float8 val)
 
aggregate float8[] __matrix_densify_agg (integer, integer, float8)
 
float8[] __matrix_blockize_sfunc (float8[] state, integer row_id, float8[] row_vec, integer rsize)
 
aggregate float8[] __matrix_blockize_agg (integer, float8[], integer)
 
float8[] __matrix_unblockize_sfunc (float8[] state, integer total_col_dim, integer col_id, float8[] row_vec)
 
aggregate float8[] __matrix_unblockize_agg (integer, integer, float8[])
 
float8[] matrix_mem_mult (float[] matrix_a, float[] matrix_b, boolean trans_b)
 
float8[] matrix_mem_mult (float[] matrix_a, float[] matrix_b)
 
float8[] matrix_mem_trans (float[] matrix)
 
float8[] __matrix_mem_sum_sfunc (float[] state, float[] matrix)
 
aggregate float8[] __matrix_mem_sum (float8[])
 
matrix_result __matrix_column_to_array_format (text matrix_in, text row_id, text matrix_out, boolean istemp)
 
matrix_result matrix_blockize (text matrix_in, text in_args, integer rsize, integer csize, text matrix_out, text out_args)
 
matrix_result matrix_blockize (text matrix_in, text in_args, integer rsize, integer csize, text matrix_out)
 
matrix_result matrix_unblockize (text matrix_in, text in_args, text matrix_out, text out_args)
 
set< float8[]> __matrix_unnest_block (float8[] block)
 

Detailed Description

Date
April 2011

Function Documentation

aggregate float8 [] __matrix_blockize_agg ( integer  ,
float8  [],
integer   
)
float8 [] __matrix_blockize_sfunc ( float8[]  state,
integer  row_id,
float8[]  row_vec,
integer  rsize 
)
matrix_result __matrix_column_to_array_format ( text  matrix_in,
text  row_id,
text  matrix_out,
boolean  istemp 
)
aggregate float8 [] __matrix_densify_agg ( integer  ,
integer  ,
float8   
)
float8 [] __matrix_densify_sfunc ( float8[]  state,
integer  col_dim,
integer  col_id,
float8  val 
)
aggregate float8 [] __matrix_mem_sum ( float8  [])
float8 [] __matrix_mem_sum_sfunc ( float[]  state,
float[]  matrix 
)
set<float8[]> __matrix_row_split ( float8[]  row_in,
integer  size 
)
aggregate float8 [] __matrix_unblockize_agg ( integer  ,
integer  ,
float8  [] 
)
float8 [] __matrix_unblockize_sfunc ( float8[]  state,
integer  total_col_dim,
integer  col_id,
float8[]  row_vec 
)
set<float8[]> __matrix_unnest_block ( float8[]  block)
integer [] __rand_block ( integer  row_dim,
integer  col_dim 
)
integer [] __rand_block ( integer  dim)
integer [] __rand_vector ( integer  dim)
matrix_result matrix_add ( text  matrix_a,
text  a_args,
text  matrix_b,
text  b_args,
text  matrix_out,
text  out_args 
)
Parameters
matrix_aName of the table containing the first matrix
a_rowName of the column containing the row index for the first matrix
a_colName of the column containing the column index for the first matrix
a_valName of the column containing the matrix values for the first matrix
matrix_bName of the table containing the second matrix
b_rowName of the column containing the row index for the second matrix
b_colName of the column containing the column index for the second matrix
b_valName of the column containing the matrix values for the second matrix
matrix_outName of the table where to output the result matrix
Returns
Name of the table containing the result matrix
matrix_result matrix_add ( text  matrix_a,
text  a_args,
text  matrix_b,
text  b_args,
text  matrix_out 
)
text matrix_add ( text  message)
text matrix_add ( )
matrix_result matrix_block_mult ( text  matrix_a,
text  a_args,
text  matrix_b,
text  b_args,
text  matrix_out,
text  out_args 
)
matrix_result matrix_block_square ( text  matrix_in,
text  in_args,
text  matrix_out,
text  out_args 
)
matrix_result matrix_block_trans ( text  matrix_in,
text  in_args,
text  matrix_out,
text  out_args,
boolean  use_temp_table 
)
matrix_result matrix_block_trans ( text  matrix_in,
text  in_args,
text  matrix_out,
text  out_args 
)
matrix_result matrix_blockize ( text  matrix_in,
text  in_args,
integer  rsize,
integer  csize,
text  matrix_out,
text  out_args 
)
matrix_result matrix_blockize ( text  matrix_in,
text  in_args,
integer  rsize,
integer  csize,
text  matrix_out 
)
matrix_result matrix_densify ( text  matrix_in,
text  in_args,
text  matrix_out,
text  out_args,
boolean  use_temp_table 
)
Parameters
matrix_inName of the table containing the input matrix
in_rowName of the column containing the row index for the input matrix
in_colName of the column containing the column index for the input matrix
in_valName of the column containing the matrix values for the input matrix
matrix_outName of the table where to output the result matrix
use_temp_tableSpecify if use temp table for result
Returns
Name of the table containing the result matrix
matrix_result matrix_densify ( text  matrix_in,
text  in_args,
text  matrix_out,
text  out_args 
)
matrix_result matrix_densify ( text  matrix_in,
text  in_args,
text  matrix_out 
)
text matrix_densify ( text  message)
text matrix_densify ( )
matrix_result matrix_elem_mult ( text  matrix_a,
text  a_args,
text  matrix_b,
text  b_args,
text  matrix_out,
text  out_args 
)
Parameters
matrix_aName of the table containing the first matrix
a_rowName of the column containing the row id for the first matrix
a_colName of the column containing the column id for the first matrix
a_valName of the column containing the matrix values for the first matrix
matrix_bName of the table containing the second matrix
b_rowName of the column containing the row id for the second matrix
b_colName of the column containing the column id for the second matrix
b_valName of the column containing the matrix values for the second matrix
matrix_outName of the table where to output the result matrix
Returns
Name of the table containing the result matrix
matrix_result matrix_elem_mult ( text  matrix_a,
text  a_args,
text  matrix_b,
text  b_args,
text  matrix_out 
)
text matrix_elem_mult ( text  message)
text matrix_elem_mult ( )
float8 [] matrix_extract_col ( text  matrix_in,
text  in_args,
integer  index 
)
Parameters
matrix_inName of the table containing the matrix
in_argsA string containing multiple named arguments of the form "name=value". This argument is used as a container for multiple parameters related to a single matrix.
indexColumn index for wanted.
Returns
Vector containing given column elements.
text matrix_extract_col ( text  message)
text matrix_extract_col ( )
float8 [] matrix_extract_row ( text  matrix_in,
text  in_args,
integer  index 
)
Parameters
matrix_inName of the table containing the matrix
in_argsA string containing multiple named arguments of the form "name=value". This argument is used as a container for multiple parameters related to a single matrix.
indexRow index for wanted.
Returns
Vector containing given row elements.
text matrix_extract_row ( text  message)
text matrix_extract_row ( )
text matrix_info ( text  message)
text matrix_info ( )
matrix_result matrix_max ( text  matrix_in,
text  in_args,
integer  dim,
text  matrix_out,
boolean  fetch_index 
)
Parameters
matrix_inName of the table containing the matrix
in_argsA string containing multiple named arguments of the form "name=value". This argument is used as a container for multiple parameters related to a single matrix.
dimWhich dimension to collapse. 1 means row wise, and 2 means column wise
matrix_outResult matrix which contains one column: max, and another column: index if fetch_index is set. The type of column is array
fetch_indexTrue when want to get corresponding index of max value. Default is false
Returns
matrix_out.
text matrix_max ( text  message)
text matrix_max ( )
float8 [] matrix_mean ( text  matrix_in,
text  in_args,
integer  dim 
)
Parameters
matrix_inName of the table containing the matrix
in_argsName-value pair string containing options for matrix_in
dimWhich dimension to collapse. 1 means row wise, and 2 means column wise
text matrix_mean ( text  message)
text matrix_mean ( )
float8 [] matrix_mem_mult ( float[]  matrix_a,
float[]  matrix_b,
boolean  trans_b 
)
float8 [] matrix_mem_mult ( float[]  matrix_a,
float[]  matrix_b 
)
float8 [] matrix_mem_trans ( float[]  matrix)
matrix_result matrix_min ( text  matrix_in,
text  in_args,
integer  dim,
text  matrix_out,
boolean  fetch_index 
)
Parameters
matrix_inName of the table containing the matrix
in_argsA string containing multiple named arguments of the form "name=value". This argument is used as a container for multiple parameters related to a single matrix.
dimWhich dimension to collapse. 1 means row wise, and 2 means column wise
matrix_outResult matrix which contains one column: min, and another column: index if fetch_index is set. The type of column is array
fetch_indexTrue when want to get corresponding index of min value. Default is false
Returns
matrix_out.
text matrix_min ( text  message)
text matrix_min ( )
matrix_result matrix_mult ( text  matrix_a,
text  a_args,
text  matrix_b,
text  b_args,
text  matrix_out,
text  out_args 
)
Parameters
matrix_aName of the table containing the first matrix
a_rowName of the column containing the row index for the first matrix
a_colName of the column containing the column index for the first matrix
a_valName of the column containing the matrix values for the first matrix
a_transBoolean to indicate if first matrix should be transposed before multiplication
matrix_bName of the table containing the second matrix
b_rowName of the column containing the row index for the second matrix
b_colName of the column containing the column index for the second matrix
b_valName of the column containing the matrix values for the second matrix
b_transBoolean to indicate if second matrix should be transposed before multiplication
matrix_outName of the table where to output the result matrix
Returns
Name of the table containing the result matrix
matrix_result matrix_mult ( text  matrix_a,
text  a_args,
text  matrix_b,
text  b_args,
text  matrix_out 
)
text matrix_mult ( text  message)
text matrix_mult ( )
float8 matrix_norm ( text  matrix_in,
text  in_args,
text  norm_type 
)
Parameters
matrix_aSource matrix table (dense matrix format)
norm_typeType of norm used (default: fro)
Returns
DOUBLE PRECISION
Usage Currenty, we support the following norms
(a) 'fro': Computes the frobenius norm
SELECT matrix_norm('matrix_table_name', 'fro');
float8 matrix_norm ( text  matrix_in,
text  in_args 
)
Parameters
matrix_aSource matrix table (dense matrix format)
Returns
DOUBLE PRECISION
Usage Currenty, we support the following norms
(a) 'fro': Computes the frobenius norm
SELECT matrix_norm('matrix_table_name', 'fro');
matrix_result matrix_scalar_mult ( text  matrix_in,
text  in_args,
float8  scalar,
text  matrix_out,
text  out_args 
)
Parameters
matrix_inName of the table containing the matrix
in_argsName-value pair string containing options for matrix_in
scalarScalar value used to be multiplied with matrix_in
matrix_outName of the table where to output the result matrix
out_argsName-value pair string containing options for matrix_in
Returns
Name of the table containing the result matrix
text matrix_scalar_mult ( text  message)
text matrix_scalar_mult ( )
void matrix_scale_and_add ( text  matrix_a,
text  a_args,
text  matrix_b,
text  b_args,
float8  scale,
text  matrix_out,
text  out_args 
)
Parameters
matrix_aSource matrix table A (dense matrix format)
matrix_bSource matrix table B (dense matrix format)
scaleScale for matrix B
matrix_outOutput table for matrix R <- A + sB
Returns
VOID
Usage
For matrix addition and subtration, you can use the same function with different values of scalar
SELECT matrix_scale_and_add('matrix_a', 'matrix_b', 1, 'matrix_out');
SELECT matrix_scale_and_add('matrix_a', 'matrix_b', -1, 'matrix_out');
matrix_result matrix_sparsify ( text  matrix_in,
text  in_args,
text  matrix_out,
text  out_args,
boolean  use_temp_table 
)
Parameters
matrix_inName of the table containing the input matrix
matrix_outName of the table where to output the result matrix
use_temp_tableSpecify if use temp table for result
Returns
Name of the table containing the result matrix
matrix_result matrix_sparsify ( text  matrix_in,
text  in_args,
text  matrix_out,
text  out_args 
)
matrix_result matrix_sparsify ( text  matrix_in,
text  in_args,
text  matrix_out 
)
text matrix_sparsify ( text  message)
text matrix_sparsify ( )
matrix_result matrix_square ( text  matrix_in,
text  in_args,
text  matrix_out,
text  out_args 
)
Parameters
matrix_inName of the table containing the input matrix
matrix_outName of the table where to output the result matrix
Returns
Name of the table containing the result matrix
matrix_result matrix_square ( text  matrix_in,
text  in_args,
text  matrix_out 
)
matrix_result matrix_sub ( text  matrix_a,
text  a_args,
text  matrix_b,
text  b_args,
text  matrix_out,
text  out_args 
)
Parameters
matrix_aName of the table containing the first matrix
a_rowName of the column containing the row id for the first matrix
a_colName of the column containing the column id for the first matrix
a_valName of the column containing the matrix values for the first matrix
matrix_bName of the table containing the second matrix
b_rowName of the column containing the row id for the second matrix
b_colName of the column containing the column id for the second matrix
b_valName of the column containing the matrix values for the second matrix
matrix_outName of the table where to output the result matrix
Returns
Name of the table containing the result matrix
matrix_result matrix_sub ( text  matrix_a,
text  a_args,
text  matrix_b,
text  b_args,
text  matrix_out 
)
text matrix_sub ( text  message)
text matrix_sub ( )
float8 [] matrix_sum ( text  matrix_in,
text  in_args,
integer  dim 
)
Parameters
matrix_inName of the table containing the matrix
in_argsName-value pair string containing options for matrix_in
dimWhich dimension to collapse. 1 means row wise, and 2 means column wise
text matrix_sum ( text  message)
text matrix_sum ( )
matrix_result matrix_trans ( text  matrix_in,
text  in_args,
text  matrix_out,
text  out_args,
boolean  use_temp_table 
)
Parameters
matrix_inName of the table containing the input matrix
in_rowName of the column containing the row index for the input matrix
in_colName of the column containing the column index for the input matrix
in_valName of the column containing the matrix values for the input matrix
matrix_outName of the table where to output the result matrix
use_temp_tableSpecify if use temp table for result
Returns
Name of the table containing the result matrix
matrix_result matrix_trans ( text  matrix_in,
text  in_args,
text  matrix_out,
text  out_args 
)
matrix_result matrix_trans ( text  matrix_in,
text  in_args,
text  matrix_out 
)
text matrix_trans ( text  message)
text matrix_trans ( )
matrix_result matrix_unblockize ( text  matrix_in,
text  in_args,
text  matrix_out,
text  out_args 
)
float8 [] matrix_vec_mult ( text  matrix_in,
text  in_args,
float8[]  vector 
)
Parameters
matrix_inName of the table containing the matrix
in_argsName-value pair string containing options for matrix_in
vectorVector value used to be multiplied with matrix_in
Returns
Column vector which is the result of matrix_in * vector
text matrix_vec_mult ( text  message)
text matrix_vec_mult ( )