-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmathematics.lua
More file actions
116 lines (104 loc) · 1.63 KB
/
mathematics.lua
File metadata and controls
116 lines (104 loc) · 1.63 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
--- Mathematics functions.
-- Modules --
local af = require("arrayfire_lib")
local array = require("impl.array")
-- Imports --
local CallWrap = array.CallWrap
local GetLib = array.GetLib
local IsArray = array.IsArray
local TwoArrays = array.TwoArrays
-- Exports --
local M = {}
-- See also: https://github.com/arrayfire/arrayfire/blob/devel/src/api/cpp/binary.cpp
--
local function Binary (name)
return function(a, b)
return TwoArrays(name, a, b, IsArray(a) and IsArray(b) and GetLib().gforGet())
end
end
--
local function Unary (name)
return function(in_arr)
return CallWrap(name, in_arr:get())
end
end
local function LoadFuncs (into, funcs, op)
for _, v in ipairs(funcs) do
local name = "af_" .. v
into[v] = af[name] and op(name) -- ignore conditionally unavailable functions
end
end
--
function M.Add (into)
LoadFuncs(into, {
"abs",
"acos",
"acosh",
"arg",
"asin",
"asinh",
"atan",
"atanh",
"cbrt",
"ceil",
"conjg",
"cos",
"cosh",
"cplx",
"erf",
"erfc",
"exp",
"expm1",
"factorial",
"floor",
"imag",
"lgamma",
"log",
"log10",
"log1p",
"not",
"real",
"round",
"sigmoid",
"sign",
"sin",
"sinh",
"sqrt",
"tan",
"tanh",
"trunc",
"tgamma"
}, Unary)
LoadFuncs(into, {
"add",
"and",
"atan2",
"bitand",
"bitor",
"bitshiftl",
"bitshiftr",
"bitxor",
"cplx2",
"div",
"eq",
"ge",
"gt",
"hypot",
"le",
"lt",
"maxof",
"minof",
"mod",
"mul",
"neq",
"or",
"pow",
"rem",
"root",
"sub"
}, Binary)
-- Use C++ name. (TODO: maxof, minof... re. vector)
into.complex, into.cplx2 = into.cplx2
end
-- Export the module.
return M