aboutsummaryrefslogtreecommitdiff
path: root/matrix/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'matrix/init.lua')
-rw-r--r--matrix/init.lua13
1 files changed, 10 insertions, 3 deletions
diff --git a/matrix/init.lua b/matrix/init.lua
index 0075668..057b085 100644
--- a/matrix/init.lua
+++ b/matrix/init.lua
@@ -2,17 +2,22 @@ function nerv.Matrix:__tostring__()
local ncol = self:ncol()
local nrow = self:nrow()
local strt = {}
-
+ local fmt
+ if self.fmt then
+ fmt = self.fmt
+ else
+ fmt = "%.10f "
+ end
if nrow == 1 then
for col = 0, ncol - 1 do
- table.insert(strt, string.format("%f ", self[col]))
+ table.insert(strt, string.format(fmt, self[col]))
end
table.insert(strt, "\n")
else
for row = 0, nrow - 1 do
local rp = self[row]
for col = 0, ncol - 1 do
- table.insert(strt, string.format("%.10f ", rp[col]))
+ table.insert(strt, string.format(fmt, rp[col]))
end
table.insert(strt, "\n")
end
@@ -21,6 +26,8 @@ function nerv.Matrix:__tostring__()
return table.concat(strt)
end
+nerv.MMatrixInt.fmt = "%d "
+
function nerv.CuMatrix:__add__(b)
c = self:create()
c:add(self, b, 1.0, 1.0)