-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.lua
More file actions
64 lines (54 loc) · 1.25 KB
/
Copy pathfunctions.lua
File metadata and controls
64 lines (54 loc) · 1.25 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local Array = require('array')
local function printTable(t)
if type(t[1]) == 'table' then
for _, row in ipairs(t) do
printTable(row)
end
elseif type(t) == 'table' then
print(table.concat(t, "\t"))
else
print(t)
end
end
local function genTable(fillValue, ...)
local fillValue = fillValue or 0
local axes = {...}
local numDim = #axes
if numDim < 1 then
error("Dimension < 1")
end
if numDim == 1 then
local outTable = {}
for i = 1, axes[1] do
outTable[i] = fillValue
end
return outTable
else
local outTable = {}
for i = 1, table.remove(axes, 1) do
outTable[i] = genTable(fillValue, unpack(axes))
end
return outTable
end
end
function genArray(fillValue, ...)
local outArray = Array()
outArray._data = genTable(fillValue, ...)
outArray._shape = {...}
return outArray
end
local function zeros(...)
return genTable(0, ...)
end
local function ones(...)
return genTable(1, ...)
end
-- expose table containing functions
return {
printTable = printTable,
genTable = genTable,
genArray = genArray,
zeros = zeros,
ones = ones,
shape = shape,
}