summaryrefslogtreecommitdiff
path: root/matrix
diff options
context:
space:
mode:
authorTed Yin <[email protected]>2015-06-21 13:44:15 +0800
committerTed Yin <[email protected]>2015-06-21 13:44:15 +0800
commit9ced612c86b5e24409e8f1d81bfbd1da893f2157 (patch)
tree474c536ff4a7d757bb61915a1bfc7a073f40d09f /matrix
parentf3f4e74eb4dbb8829e5ee136ba4b0c0a7938b551 (diff)
parentad2c4013dec71667d6bbd5e9a249df2085208507 (diff)
Merge pull request #32 from cloudygoose/master
change doc
Diffstat (limited to 'matrix')
-rw-r--r--matrix/init.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/matrix/init.lua b/matrix/init.lua
index 7bbc6a4..769ef2d 100644
--- a/matrix/init.lua
+++ b/matrix/init.lua
@@ -27,6 +27,22 @@ function nerv.Matrix:__tostring__()
return table.concat(strt)
end
+--func: function
+--All entrys in the matrix will be assigned by calling func()
+function nerv.Matrix:randomize(func)
+ if (self:nrow() == 1) then
+ for j = 0, self:ncol() - 1, 1 do
+ self[j] = func()
+ end
+ else
+ for i = 0, self:nrow() - 1, 1 do
+ for j = 0, self:ncol() - 1, 1 do
+ self[i][j] = func()
+ end
+ end
+ end
+end
+
nerv.MMatrixInt.fmt = "%d "
function nerv.CuMatrix:__add__(b)