aboutsummaryrefslogtreecommitdiff
path: root/matrix.lua
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2015-05-14 18:23:46 +0800
committerDeterminant <[email protected]>2015-05-14 18:23:46 +0800
commitb03471e2b0d604806773b540551cd047979b7b3b (patch)
tree3bc14575d8fd4534975f09f12ad74dd63de293a7 /matrix.lua
parentf48dc493b5b77fd4e4472dd6c78b7542a4884129 (diff)
add matrix indexing support
Diffstat (limited to 'matrix.lua')
-rw-r--r--matrix.lua10
1 files changed, 5 insertions, 5 deletions
diff --git a/matrix.lua b/matrix.lua
index 2a70590..7aa1f12 100644
--- a/matrix.lua
+++ b/matrix.lua
@@ -2,14 +2,14 @@ function nerv.FloatMatrix:__tostring__()
local ncol = self:ncol()
local nrow = self:nrow()
local i = 0
- local res = ""
+ local strt = {}
for row = 0, nrow - 1 do
for col = 0, ncol - 1 do
- res = res .. string.format("%f ", self:get_elem(i))
+ table.insert(strt, string.format("%f ", self:get_elem(i)))
i = i + 1
end
- res = res .. "\n"
+ table.insert(strt, "\n")
end
- res = res .. string.format("[Float Matrix %d x %d]", nrow, ncol)
- return res
+ table.insert(strt, string.format("[Float Matrix %d x %d]", nrow, ncol))
+ return table.concat(strt)
end