From 839d938df0d83ec311c5d1299923c667adff6a87 Mon Sep 17 00:00:00 2001 From: cloudygoose Date: Fri, 12 Jun 2015 13:06:27 +0800 Subject: git rebase ... ... ... ... .. .. ... .... ... ... .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... git rebase ... ... ... doc change doc change ... added nerv.Matrix:randomize() ... doc change for DAGLayer bug fix in nerv.Matrix:random() doc change --- matrix/init.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'matrix') 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) -- cgit v1.2.3-70-g09d2 From 9a8ef8091806c004bc53c529d0b9f514eb6ac3da Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 21 Jun 2015 13:51:15 +0800 Subject: add nerv.Matrix:generate() --- matrix/init.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'matrix') diff --git a/matrix/init.lua b/matrix/init.lua index 769ef2d..1a8925f 100644 --- a/matrix/init.lua +++ b/matrix/init.lua @@ -27,17 +27,18 @@ 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) +-- 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, 1 do - self[j] = func() + for j = 0, self:ncol() - 1 do + self[j] = gen(j) end else - for i = 0, self:nrow() - 1, 1 do - for j = 0, self:ncol() - 1, 1 do - self[i][j] = func() + 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 -- cgit v1.2.3-70-g09d2