-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathConstructor.cpp
More file actions
125 lines (91 loc) · 2.87 KB
/
Constructor.cpp
File metadata and controls
125 lines (91 loc) · 2.87 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
117
118
119
120
121
122
123
124
125
#include <arrayfire.h>
#include "../funcs.h"
#include "../utils.h"
#include "../template/args.h"
#include "../template/out_in.h"
template<typename T, af_err(*func)(af_array *, const T, const unsigned, const dim_t *)> int Long (lua_State * L)
{
lua_settop(L, 3); // val, ndims, dims
LuaDims dims(L, 2);
af_array * arr_ud = NewArray(L);// val, ndims, dims, arr_ud
af_err err = af_constant_ulong(arr_ud, Arg<T>(L, 1), dims.GetNDims(), dims.GetDims());
return PushErr(L, err); // val, ndims, dims, err, arr_ud
}
#define LONG(name, t) { "af_"#name, Long<t, &af_##name> }
//
static const struct luaL_Reg constructor_funcs[] = {
{
"af_constant", [](lua_State * L)
{
lua_settop(L, 4); // val, ndims, dims, type
LuaDims dt(L, 2);
af_array * arr_ud = NewArray(L);// val, ndims, dims, type, arr_ud
af_err err = af_constant(arr_ud, D(L, 1), dt.GetNDims(), dt.GetDims(), Arg<af_dtype>(L, 4));
return PushErr(L, err); // val, ndims, dims, type, err, arr_ud
}
}, {
"af_constant_complex", [](lua_State * L)
{
lua_settop(L, 5); // real, imag, ndims, dims, type
LuaDims dt(L, 3);
af_array * arr_ud = NewArray(L);// real, imag, ndims, dims, type, arr_ud
af_err err = af_constant_complex(arr_ud, D(L, 1), D(L, 2), dt.GetNDims(), dt.GetDims(), Arg<af_dtype>(L, 5));
return PushErr(L, err); // real, imag, ndims, dims, type, err, arr_ud
}
},
LONG(constant_long, intl),
LONG(constant_ulong, uintl),
OUTIN_ARG(diag_create, int),
OUTIN_ARG(diag_extract, int),
{
"af_get_seed", [](lua_State * L)
{
lua_settop(L, 0); // (empty)
uintl seed = 0;
af_err err = af_get_seed(&seed);
lua_pushinteger(L, seed); // seed
return PushErr(L, err); // err, seed
}
},
DIMS_AND_TYPE(identity),
{
"af_iota", [](lua_State * L)
{
lua_settop(L, 5); // ndims, dims, t_ndims, tdims, type
LuaDims dims(L, 1);
LuaDims t_dt(L, 3);
af_array * arr_ud = NewArray(L);// ndims, dims, t_ndims, tdims, type, arr_ud
af_err err = af_iota(arr_ud, dims.GetNDims(), dims.GetDims(), t_dt.GetNDims(), t_dt.GetDims(), Arg<af_dtype>(L, 5));
return PushErr(L, err); // ndims, dims, t_ndims, tdims, type, err, arr_ud
}
},
OUTIN_ARG(lower, bool),
DIMS_AND_TYPE(randn),
DIMS_AND_TYPE(randu),
{
"af_range", [](lua_State * L)
{
lua_settop(L, 4); // ndims, dims, seq_dim, type
LuaDims dt(L, 1);
af_array * arr_ud = NewArray(L);// ndims, dims, seq_dim, type, arr_ud
af_err err = af_range(arr_ud, dt.GetNDims(), dt.GetDims(), I(L, 3), Arg<af_dtype>(L, 4));
return PushErr(L, err); // ndims, dims, seq_dim, type, err, arr_ud
}
}, {
"af_set_seed", [](lua_State * L)
{
lua_settop(L, 1); // seed
af_err err = af_set_seed(Arg<uintl>(L, 1));
lua_pushinteger(L, err);// seed, err
return 1;
}
},
OUTIN_ARG(upper, bool),
{ NULL, NULL }
};
#undef LONG
int Constructor (lua_State * L)
{
luaL_register(L, NULL, constructor_funcs);
return 0;
}