diff options
author | Determinant <[email protected]> | 2015-05-15 03:13:31 +0800 |
---|---|---|
committer | Determinant <[email protected]> | 2015-05-15 03:13:31 +0800 |
commit | 902faa66e3da52a1a4cf7b1dc7da6e6bf0d47d34 (patch) | |
tree | d3c5bad9e01ecc13a510fd552b97b080e70c38ad /matrix/init.lua | |
parent | d77baabfd42d169c2cf7318b770c1f2547ebe17d (diff) |
add cumatrix
Diffstat (limited to 'matrix/init.lua')
-rw-r--r-- | matrix/init.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/matrix/init.lua b/matrix/init.lua new file mode 100644 index 0000000..59b8384 --- /dev/null +++ b/matrix/init.lua @@ -0,0 +1,38 @@ +function nerv.FloatCuMatrix:__tostring__() + local ncol = self:ncol() + local nrow = self:nrow() + local strt = {} + + if nrow == 1 then + for col = 0, ncol - 1 do + table.insert(strt, string.format("%f ", 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("%f ", rp[col])) + end + table.insert(strt, "\n") + end + end + table.insert(strt, string.format("[Float Matrix %d x %d]", nrow, ncol)) + return table.concat(strt) +end + +function nerv.FloatMatrix:__tostring__() + local ncol = self:ncol() + local nrow = self:nrow() + local i = 0 + local strt = {} + for row = 0, nrow - 1 do + for col = 0, ncol - 1 do + table.insert(strt, string.format("%f ", self:get_elem(i))) + i = i + 1 + end + table.insert(strt, "\n") + end + table.insert(strt, string.format("[Float Matrix %d x %d]", nrow, ncol)) + return table.concat(strt) +end |