diff options
author | Determinant <[email protected]> | 2015-06-21 23:01:20 +0800 |
---|---|---|
committer | Determinant <[email protected]> | 2015-06-21 23:01:20 +0800 |
commit | 196e9b48a3541caccdffc5743001cced70667091 (patch) | |
tree | a639873e282727c01746319169a08766c086965b /matrix | |
parent | f3f14b85d3b9c1ccebb1faea37b7b57012fba347 (diff) | |
parent | 9a8ef8091806c004bc53c529d0b9f514eb6ac3da (diff) |
Merge branch 'master' of github.com:Determinant/nerv
Diffstat (limited to 'matrix')
-rw-r--r-- | matrix/init.lua | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/matrix/init.lua b/matrix/init.lua index 7bbc6a4..1a8925f 100644 --- a/matrix/init.lua +++ b/matrix/init.lua @@ -27,6 +27,23 @@ function nerv.Matrix:__tostring__() return table.concat(strt) end +-- gen: a function takes take indices of the matrix and return the generated +-- all entrys in the matrix will be assigned by calling gen(i, j) +function nerv.Matrix:generate(gen) + if (self:nrow() == 1) then + for j = 0, self:ncol() - 1 do + self[j] = gen(j) + end + else + for i = 0, self:nrow() - 1 do + local row = self[i] + for j = 0, self:ncol() - 1 do + row[j] = gen(i, j) + end + end + end +end + nerv.MMatrixInt.fmt = "%d " function nerv.CuMatrix:__add__(b) |