aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcloudygoose <[email protected]>2015-06-04 13:04:27 +0800
committercloudygoose <[email protected]>2015-06-04 13:04:27 +0800
commitb53f40144715ef80d26e9a894ddc153e9ebfcc34 (patch)
tree6b48951e08acd720e4fe13c7907ad79748981627
parent2301cba19914f35a8c34c3d27d98deb43ddaaf1d (diff)
...
-rw-r--r--doc/nerv_matrix.md60
1 files changed, 59 insertions, 1 deletions
diff --git a/doc/nerv_matrix.md b/doc/nerv_matrix.md
index 2cef099..1a2778b 100644
--- a/doc/nerv_matrix.md
+++ b/doc/nerv_matrix.md
@@ -98,4 +98,62 @@ Returns a new __Matrix__ which stores the result of `ma*mb`.
* __CuMatrix CuMatrix.new_from_host(MMatrix m)__
Return a new __CuMatrix__ which is a copy of `m`.
* __MMatrix CuMatrix.new_to_host(CuMatrix self)__
-Return a new __MMatrix__ which is a copy of `self`. \ No newline at end of file
+Return a new __MMatrix__ which is a copy of `self`.
+* __string Matrix.\_\_tostring\_\_(Matrix self)__
+Returns a string containing values of __Matrix__ `self`.
+---
+
+##Examples##
+* Use `get_dataref_value` to test __Nerv__'s matrix space allocation.
+```
+m = 10
+n = 10
+fm = nerv.MMatrixFloat(m, n)
+dm = nerv.MMatrixDouble(m, n)
+for i = 0, m - 1 do
+ for j = 0, n - 1 do
+ t = i / (j + 1)
+ fm[i][j] = t
+ dm[i][j] = t
+ end
+end
+print("test fm:get_dataref_value:", fm:get_dataref_value())
+print("forced a garbade collect")
+collectgarbage("collect")
+print("test fm:get_dataref_value:", fm:get_dataref_value())
+print(fm)
+print(dm)
+```
+* Test some __Matrix__ calculations.
+```
+m = 4
+n = 4
+fm = nerv.CuMatrixFloat(m, n)
+dm = nerv.CuMatrixDouble(m, n)
+for i = 0, m - 1 do
+ for j = 0, n - 1 do
+ -- local t = math.random(10)
+ t = i / (j + 1)
+ fm[i][j] = t
+ dm[i][j] = t
+ end
+end
+print(fm)
+fs = fm:create()
+fs:softmax(fm)
+-- print(fs)
+print(dm)
+ds = dm:create()
+ds:softmax(dm)
+-- print(ds)
+print(fs)
+print(fs + fs)
+print(ds + ds)
+print(fs - fs)
+print(ds - ds)
+a = fs:create()
+a:mul_elem(fs, fs)
+print(a)
+a:log_elem(fs)
+print(a)
+``` \ No newline at end of file