-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils.h
70 lines (48 loc) · 1.67 KB
/
utils.h
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
#ifndef UTILS_H
#define UTILS_H
#include "template/args.h"
#include <arrayfire.h>
#include <vector>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
}
af_dtype GetDataType (lua_State * L, int index);
void PushResult (lua_State * L, af_err err);
int PushErr (lua_State * L, af_err err, int nret = 1);
void * GetMemory (lua_State * L, int index);
af_array GetArray (lua_State * L, int index);
af_features GetFeatures (lua_State * L, int index);
af_index_t * GetIndexer (lua_State * L, int index);
af_array * NewArray (lua_State * L);
af_features * NewFeatures (lua_State * L);
af_index_t ** NewIndexer (lua_State * L);
void ClearArray (lua_State * L, int index);
void ClearFeatures (lua_State * L, int index);
void ClearIndexer (lua_State * L, int index);
class LuaDims {
std::vector<dim_t> mDims;
public:
LuaDims (lua_State * L, int first);
int GetNDims (void) const { return mDims.size(); }
const dim_t * GetDims (void) const { return &mDims.front(); }
};
class LuaData {
af_dtype mType;
std::vector<char> mData;
const char * mDataPtr;
public:
LuaData (lua_State * L, int index, int type_index, bool copy = false);
const char * GetData (void) const { return mDataPtr; }
af_dtype GetType (void) const { return mType; }
};
template<af_err (*func)(af_array *, const unsigned, const dim_t *, const af_dtype)> int DimsAndType(lua_State * L)
{
lua_settop(L, 3); // ndims, dims, type
LuaDims dt(L, 1);
af_array * arr_ud = NewArray(L);// ndims, dims, type, arr_ud
af_err err = func(arr_ud, dt.GetNDims(), dt.GetDims(), Arg<af_dtype>(L, 3));
return PushErr(L, err); // ndims, dims, type, err, arr_ud
}
#define DIMS_AND_TYPE(name) { "af_"#name, DimsAndType<&af_##name> }
#endif