-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMethods.cpp
More file actions
101 lines (81 loc) · 1.93 KB
/
Methods.cpp
File metadata and controls
101 lines (81 loc) · 1.93 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
#include <arrayfire.h>
#include "../methods.h"
#include "../template/from.h"
#include "../template/in.h"
#include "../template/out_in.h"
#include "../utils.h"
#define PRED_REG(cond) FROM_NONE(is_##cond, bool)
//
static const struct luaL_Reg array_methods[] = {
OUTIN(copy_array),
IN_NONE(eval),
#if AF_API_VERSION >= 31
FROM_NONE(get_data_ref_count, int),
{
"af_get_data_ptr", [](lua_State * L)
{
lua_settop(L, 2); // data, arr
af_err err = af_get_data_ptr(lua_touserdata(L, 1), GetArray(L, 2));
lua_pushinteger(L, err);// arr, err
return 1;
}
},
#endif
{
"af_get_dims", [](lua_State * L)
{
lua_settop(L, 1); // in
dim_t d1, d2, d3, d4;
af_err err = af_get_dims(&d1, &d2, &d3, &d4, GetArray(L, 1));
lua_pushinteger(L, err);// in, err
lua_pushinteger(L, d1); // in, err, d1
lua_pushinteger(L, d2); // in, err, d1, d2
lua_pushinteger(L, d3); // in, err, d1, d2, d3
lua_pushinteger(L, d4); // in, err, d1, d2, d3, d4
return 5;
}
},
FROM_NONE(get_elements, dim_t),
FROM_NONE(get_numdims, unsigned),
FROM_NONE(get_type, af_dtype),
PRED_REG(empty),
PRED_REG(scalar),
PRED_REG(vector),
PRED_REG(row),
PRED_REG(column),
PRED_REG(complex),
PRED_REG(real),
PRED_REG(double),
PRED_REG(single),
PRED_REG(realfloating),
PRED_REG(floating),
PRED_REG(integer),
PRED_REG(bool),
{
"af_release_array", [](lua_State * L)
{
lua_settop(L, 1); // arr
af_err err = af_release_array(GetArray(L, 1));
ClearArray(L, 1);
lua_pushinteger(L, err);// arr, err
return 1;
}
},
OUTIN(retain_array),
{
"af_write_array", [](lua_State * L)
{
lua_settop(L, 4); // arr, data, bytes, src
af_err err = af_write_array(GetArray(L, 1), GetMemory(L, 2), Arg<size_t>(L, 3), Arg<af_source>(L, 4));
lua_pushinteger(L, err);// arr, data, bytes, src, err
return 1;
}
},
{ NULL, NULL }
};
#undef PRED_REG
int Methods (lua_State * L)
{
luaL_register(L, NULL, array_methods);
return 0;
}