aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/nerv_matrix.md28
-rw-r--r--matrix/generic/cumatrix.c2
2 files changed, 28 insertions, 2 deletions
diff --git a/doc/nerv_matrix.md b/doc/nerv_matrix.md
index 0585ee6..aedefbe 100644
--- a/doc/nerv_matrix.md
+++ b/doc/nerv_matrix.md
@@ -42,6 +42,32 @@ Get `nrow`, the number of rows.
Returns the value(not a pointer) of space the `data_ref` pointer pointed to. This function is mainly for debugging.
* __Matrix/Element\_type, boolean Matrix.\_\_index\_\_(Matrix self, int index)__
If the matrix has more than one row, will return the row at `index` as a __Matrix__ . Otherwise it will return the value at `index`.
-* __void Matrix.\_\_newindex\_\_(Matrix self, int index, Element_type value)__
+* __void Matrix.\_\_newindex\_\_(Matrix self, int index, Element_type value)__
Set the element at `index` to be `value`.
---
+* __Matrix Matrix.create(Matrix a)__
+Return a new __Matrix__ of `a`'s size(of the same number of rows and columns).
+* __Matrix Matrix.colsum(Matrix self)__
+Return a new __Matrix__ of size (1,`self.ncol`), which stores the sum of all columns of __Matrix__ `self`.
+* __Matrix Matrix.rowsum(Matrix self)__
+Return a new __Matrix__ of size (`self.nrow`,1), which stores the sum of all rows of __Matrix__ `self`.
+* __Matrix Matrix.rowmax(Matrix self)__
+Return a new __Matrix__ of size (`self.nrow`,1), which stores the max value of all rows of __Matrix__ `self`.
+* __Matrix Matrix.trans(Matrix self)__
+Return a new __Matrix__ of size (`self.ncol`,`self.nrow`), which stores the transpose of __Matrix__ `self`.
+* __void Matrix.copy_fromh(Matrix self, MMatrix a)__
+Copy the content of a __MMatrix__ `a` to __Matrix__ `self`, they should be of the same size.
+* __void Matrix.copy_fromd(Matrix self, CuMatrix a)__
+Copy the content of a __CuMatrix__ `a` to __Matrix__ `self`, they should be of the same size.
+* __void Matrix.copy_toh(Matrix self, MMatrix a)__
+Copy the content of the __Matrix__ `self` to a __MMatrix__ `a`.
+* __void Matrix.copy_tod(Matrix self, CuMatrix a)__
+Copy the content of the __Matrix__ `self` to a __CuMatrix__ `a`.
+* __void Matrix.add(Matrix self, Matrix ma, Matrix mb, Element_type alpha, Element_type beta)__
+It sets the content of __Matrix__ `self` to be `alpha * ma + beta * mb`.__Matrix__ `ma,mb,self` should be of the same size.
+* __void Matrix.mul(Matrix self, Matrix ma, Matrix mb, Element_type alpha, Element_type beta, [string ta, string tb])__
+It sets the content of __Matrix__ `self` to be `beta * self + alpha * ma * mb`. `ta` and `tb` is optional, if `ta` is 'T', then `ma` will be transposed, also if `tb` is 'T', `mb` will be transposed.
+* __void Matrix.add_row(Matrix self, Matrix va, Element_type beta)__
+It sets the content of __Matrix__ `self`(which should be row vector) to be `self + beta * va`.
+* __void Matrix.fill(Matrix self, Element_type value)__
+Fill the content of __Matrix__ to be `value`. \ No newline at end of file
diff --git a/matrix/generic/cumatrix.c b/matrix/generic/cumatrix.c
index 58f3679..0df1bd7 100644
--- a/matrix/generic/cumatrix.c
+++ b/matrix/generic/cumatrix.c
@@ -74,7 +74,7 @@ static int nerv_matrix_(mul)(lua_State *L) {
if (an != bm)
nerv_error(L, "Wrong dimension of multipliers");
/* MATRIX_ELEM alpha = 1.0f, beta = 0.0f; */
- CUBLAS_SAFE_CALL(
+ CUBLAS_SAFE_CALL( //Because matrix in Nerv is row-major, here b comes first
NERV_CUBLAS_(gemm)(cublas_handle, tb, ta,
bn, am, bm,
&alpha,