aboutsummaryrefslogtreecommitdiff
path: root/matrix/init.lua
blob: 59b83840ecb4f6a7421d5e3413bcb680a9f8db00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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