-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgfor.lua
More file actions
68 lines (50 loc) · 1022 Bytes
/
gfor.lua
File metadata and controls
68 lines (50 loc) · 1022 Bytes
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
65
66
67
68
--- gfor() mechanism.
-- Standard library imports --
local assert = assert
-- Modules --
local array = require("impl.array")
-- Imports --
local GetLib = array.GetLib
-- Exports --
local M = {}
--- See also: https://github.com/arrayfire/arrayfire/blob/devel/include/af/gfor.h
-- https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/gfor.cpp
-- --
local Status = false
--
local function AuxGfor (seq)
Status = not Status
if Status then
return seq
end
end
--
function M.Add (into)
for k, v in pairs{
--
batchFunc = function(lhs, rhs, func)
assert(not Status, "batchFunc can not be used inside GFOR") -- TODO: AF_ERR_ARG
Status = true
local res = func(lhs, rhs)
Status = false
return res
end,
--
gfor = function(...)
local lib = GetLib()
return AuxGfor, lib.seq(lib.seq(...), true)
end,
--
gforGet = function()
return Status
end,
--
gforSet = function(val)
Status = not not val
end
} do
into[k] = v
end
end
-- Export the module.
return M