You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by lr...@apache.org on 2015/11/19 21:46:57 UTC
[15/50] [abbrv] incubator-systemml git commit: [SYSML-363] Built-in
functions cbind and rbind added to documentation
[SYSML-363] Built-in functions cbind and rbind added to documentation
New built-in functions cbind and rbind added to DML Language Reference.
Use of matrix append discouraged. Replaced append example with cbind
in DML and PyDML Programming Guide.
Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/3c0a8d46
Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/3c0a8d46
Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/3c0a8d46
Branch: refs/heads/master
Commit: 3c0a8d46901875a56e1df65b3760cde9fff5a5f7
Parents: b5f8ddf
Author: Deron Eriksson <de...@us.ibm.com>
Authored: Fri Oct 30 12:54:33 2015 -0300
Committer: Luciano Resende <lr...@apache.org>
Committed: Fri Oct 30 12:54:33 2015 -0300
----------------------------------------------------------------------
docs/dml-and-pydml-programming-guide.md | 22 +++++++++++-----------
docs/dml-language-reference.md | 4 +++-
2 files changed, 14 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/3c0a8d46/docs/dml-and-pydml-programming-guide.md
----------------------------------------------------------------------
diff --git a/docs/dml-and-pydml-programming-guide.md b/docs/dml-and-pydml-programming-guide.md
index d8dc836..85367e5 100644
--- a/docs/dml-and-pydml-programming-guide.md
+++ b/docs/dml-and-pydml-programming-guide.md
@@ -629,10 +629,10 @@ Currently, if a function returns nothing, it still needs to be assigned to a var
{% highlight r %}
doSomething = function(matrix[double] mat) return (matrix[double] ret) {
additionalCol = matrix(1, rows=nrow(mat), cols=1) # 1x3 matrix with 1 values
- ret = append(mat, additionalCol) # append column to matrix
- ret = append(ret, seq(0, 2, 1)) # append column (0,1,2) to matrix
- ret = append(ret, rowMaxs(ret)) # append column of max row values to matrix
- ret = append(ret, rowSums(ret)) # append column of row sums to matrix
+ ret = cbind(mat, additionalCol) # concatenate column to matrix
+ ret = cbind(ret, seq(0, 2, 1)) # concatenate column (0,1,2) to matrix
+ ret = cbind(ret, rowMaxs(ret)) # concatenate column of max row values to matrix
+ ret = cbind(ret, rowSums(ret)) # concatenate column of row sums to matrix
}
A = rand(rows=3, cols=2, min=0, max=2) # random 3x2 matrix with values 0 to 2
@@ -646,10 +646,10 @@ write(B, "B.csv", format="csv")
{% highlight python %}
def doSomething(mat: matrix[float]) -> (ret: matrix[float]):
additionalCol = full(1, rows=nrow(mat), cols=1) # 1x3 matrix with 1 values
- ret = append(mat, additionalCol) # append column to matrix
- ret = append(ret, seq(0, 2, 1)) # append column (0,1,2) to matrix
- ret = append(ret, rowMaxs(ret)) # append column of max row values to matrix
- ret = append(ret, rowSums(ret)) # append column of row sums to matrix
+ ret = cbind(mat, additionalCol) # concatenate column to matrix
+ ret = cbind(ret, seq(0, 2, 1)) # concatenate column (0,1,2) to matrix
+ ret = cbind(ret, rowMaxs(ret)) # concatenate column of max row values to matrix
+ ret = cbind(ret, rowSums(ret)) # concatenate column of row sums to matrix
A = rand(rows=3, cols=2, min=0, max=2) # random 3x2 matrix with values 0 to 2
B = doSomething(A)
@@ -663,9 +663,9 @@ save(B, "B.csv", format="csv")
In the above example, a 3x2 matrix of random doubles between 0 and 2 is created using the **`rand()`** function.
Additional parameters can be passed to **`rand()`** to control sparsity and other matrix characteristics.
-Matrix A is passed to the `doSomething` function. A column of 1 values is appended to the matrix. A column
-consisting of the values `(0, 1, 2)` is appended to the matrix. Next, a column consisting of the maximum row values
-is appended to the matrix. A column consisting of the row sums is appended to the matrix, and this resulting
+Matrix A is passed to the `doSomething` function. A column of 1 values is concatenated to the matrix. A column
+consisting of the values `(0, 1, 2)` is concatenated to the matrix. Next, a column consisting of the maximum row values
+is concatenated to the matrix. A column consisting of the row sums is concatenated to the matrix, and this resulting
matrix is returned to variable B. Matrix A is output to the `A.csv` file and matrix B is saved as the `B.csv` file.
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/3c0a8d46/docs/dml-language-reference.md
----------------------------------------------------------------------
diff --git a/docs/dml-language-reference.md b/docs/dml-language-reference.md
index de73ab2..f6915a3 100644
--- a/docs/dml-language-reference.md
+++ b/docs/dml-language-reference.md
@@ -526,7 +526,8 @@ Table 3. Matrix Construction, Manipulation, and Aggregation Built-In Functions
Function | Description | Parameters | Example
-------- | ----------- | ---------- | -------
-append() | Adds the second argument as additional columns to the first argument (note that the first argument is not over-written). Append is meant to be used in situations where one cannot use left-indexing. | Input : (X <matrix>, Y <matrix>) <br/>Output : <matrix> <br/> X and Y are matrices (with possibly multiple columns), where the number of rows in X and Y must be the same. Output is a matrix with exactly the same number of rows as X and Y. Let n1 and n2 denote the number of columns of matrix X and Y, respectively. The returned matrix has n1+n2 columns, where the first n1 columns contain X and the last n2 columns contain Y. | A = matrix(1, rows=2,cols=5) <br/> B = matrix(1, rows=2,cols=3) <br/> C = append(A,B) <br/> print( "Dimensions of C:" + nrow(C) + " X " + ncol(C)) <br/> The output of above example is: <br/> Dimensions of C:2 X 8
+append() | Adds the second argument as additional columns to the first argument (note that the first argument is not over-written). Append is meant to be used in situations where one cannot use left-indexing. <br/> **NOTE: append() has been replaced by cbind(), so its use is discouraged.** | Input: (X <matrix>, Y <matrix>) <br/>Output: <matrix> <br/> X and Y are matrices (with possibly multiple columns), where the number of rows in X and Y must be the same. Output is a matrix with exactly the same number of rows as X and Y. Let n1 and n2 denote the number of columns of matrix X and Y, respectively. The returned matrix has n1+n2 columns, where the first n1 columns contain X and the last n2 columns contain Y. | A = matrix(1, rows=2,cols=5) <br/> B = matrix(1, rows=2,cols=3) <br/> C = append(A,B) <br/> print("Dimensions of C: " + nrow(C) + " X " + ncol(C)) <br/> The output of above example is: <br/> Dimensions of C: 2 X 8
+cbind() | Column-wise matrix concatenation. Concatenates the second matrix as additional columns to the first matrix | Input: (X <matrix>, Y <matrix>) <br/>Output: <matrix> <br/> X and Y are matrices, where the number of rows in X and the number of rows in Y are the same. | A = matrix(1, rows=2,cols=3) <br/> B = matrix(2, rows=2,cols=3) <br/> C = cbind(A,B) <br/> print("Dimensions of C: " + nrow(C) + " X " + ncol(C)) <br/> Output: <br/> Dimensions of C: 2 X 6
matrix() | Matrix constructor (assigning all the cells to numeric literals). | Input: (<init>, rows=<value>, cols=<value>) <br/> init: numeric literal; <br/> rows/cols: number of rows/cols (expression) <br/> Output: matrix | # 10x10 matrix initialized to 0 <br/> A = matrix (0, rows=10, cols=10)
| Matrix constructor (reshaping an existing matrix). | Input: (<existing matrix>, rows=<value>, cols=<value>, byrow=TRUE) <br/> Output: matrix | A = matrix (0, rows=10, cols=10) <br/> B = matrix (A, rows=100, cols=1)
| Matrix constructor (initializing using string). | Input: (<initialization string>, rows=<value>, cols=<value>) <br/> Output: matrix | A = matrix("4 3 2 5 7 8", rows=3, cols=2) <br/> Creates a matrix: [ [4, 3], [2, 5], [7, 8] ]
@@ -535,6 +536,7 @@ min() <br/> max() | Return the minimum/maximum cell values of two matrices, matr
nrow(), <br/> ncol(), <br/> length() | Return the number of rows, number of columns, or number of cells in matrix respectively. | Input: matrix <br/> Output: scalar | nrow(X)
prod() | Return the product of all cells in matrix | Input: matrix <br/> Output: scalarj | prod(X)
rand() | Generates a random matrix | Input: (rows=<value>, cols=<value>, min=<value>, max=<value>, sparsity=<value>, pdf=<string>, seed=<value>) <br/> rows/cols: Number of rows/cols (expression) <br/> min/max: Min/max value for cells (either constant value, or variable that evaluates to constant value) <br/> sparsity: fraction of non-zero cells (constant value) <br/> pdf: “uniform” (min, max) distribution, or “normal” (0,1) distribution; or “poisson” (lambda=1) distribution. string; default value is “uniform”. Note that, for the Poisson distribution, users can provide the mean/lambda parameter as follows: <br/> rand(rows=1000,cols=1000, pdf=”poisson”, lambda=2.5). <br/> The default value for lambda is 1. <br/> seed: Every invocation of rand() internally generates a random seed with which the cell values are generated. One can optionally provide a seed when repeatability is desired. <br/> Output: matrix | X = rand(rows=1
0, cols=20, min=0, max=1, pdf="uniform", sparsity=0.2) <br/> The example generates a 10 x 20 matrix, with cell values uniformly chosen at random between 0 and 1, and approximately 20% of cells will have non-zero values.
+rbind() | Row-wise matrix concatenation. Concatenates the second matrix as additional rows to the first matrix | Input: (X <matrix>, Y <matrix>) <br/>Output: <matrix> <br/> X and Y are matrices, where the number of columns in X and the number of columns in Y are the same. | A = matrix(1, rows=2,cols=3) <br/> B = matrix(2, rows=2,cols=3) <br/> C = rbind(A,B) <br/> print("Dimensions of C: " + nrow(C) + " X " + ncol(C)) <br/> Output: <br/> Dimensions of C: 4 X 3
removeEmpty() | Removes all empty rows or columns from the input matrix target X according to the specified margin. | Input : (target= X <matrix>, margin="...") <br/> Output : <matrix> <br/> Valid values for margin are "rows" or "cols". | A = removeEmpty(target=X, margin="rows")
replace() | Creates a copy of input matrix X, where all values that are equal to the scalar pattern s1 are replaced with the scalar replacement s2. | Input : (target= X <matrix>, pattern=<scalar>, replacement=<scalar>) <br/> Output : <matrix> <br/> If s1 is NaN, then all NaN values of X are treated as equal and hence replaced with s2. Positive and negative infinity are treated as different values. | A = replace(target=X, pattern=s1, replacement=s2)
seq() | Creates a single column vector with values starting from <from>, to <to>, in increments of <increment> | Input: (<from>, <to>, <increment>) <br/> Output: <matrix> | S = seq (10, 200, 10)