MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / rotate

Function rotate

src/backend/opencl/kernel/rotate.hpp:44–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43template<typename T>
44void rotate(Param out, const Param in, const float theta, af_interp_type method,
45 int order) {
46 using cl::EnqueueArgs;
47 using cl::NDRange;
48 using std::string;
49 using std::vector;
50 using BT = typename dtype_traits<T>::base_type;
51
52 constexpr int TX = 16;
53 constexpr int TY = 16;
54 // Used for batching images
55 constexpr int TI = 4;
56 constexpr bool isComplex =
57 static_cast<af_dtype>(dtype_traits<T>::af_type) == c32 ||
58 static_cast<af_dtype>(dtype_traits<T>::af_type) == c64;
59
60 vector<TemplateArg> tmpltArgs = {
61 TemplateTypename<T>(),
62 TemplateArg(order),
63 };
64 ToNumStr<T> toNumStr;
65 vector<string> compileOpts = {
66 DefineKeyValue(T, dtype_traits<T>::getName()),
67 DefineKeyValue(ZERO, toNumStr(scalar<T>(0))),
68 DefineKeyValue(InterpInTy, dtype_traits<T>::getName()),
69 DefineKeyValue(InterpValTy, dtype_traits<vtype_t<T>>::getName()),
70 DefineKeyValue(InterpPosTy, dtype_traits<wtype_t<BT>>::getName()),
71 DefineKeyValue(XDIM, 0),
72 DefineKeyValue(YDIM, 1),
73 DefineKeyValue(INTERP_ORDER, order),
74 DefineKeyValue(IS_CPLX, (isComplex ? 1 : 0)),
75 };
76 if (isComplex) {
77 compileOpts.emplace_back(
78 DefineKeyValue(TB, dtype_traits<BT>::getName()));
79 }
80 compileOpts.emplace_back(getTypeBuildDefinition<T>());
81 addInterpEnumOptions(compileOpts);
82
83 auto rotate =
84 common::getKernel("rotateKernel", {{interp_cl_src, rotate_cl_src}},
85 tmpltArgs, compileOpts);
86
87 const float c = cos(-theta), s = sin(-theta);
88 float tx, ty;
89 {
90 const float nx = 0.5 * (in.info.dims[0] - 1);
91 const float ny = 0.5 * (in.info.dims[1] - 1);
92 const float mx = 0.5 * (out.info.dims[0] - 1);
93 const float my = 0.5 * (out.info.dims[1] - 1);
94 const float sx = (mx * c + my * -s);
95 const float sy = (mx * s + my * c);
96 tx = -(sx - nx);
97 ty = -(sy - ny);
98 }
99
100 // Rounding error. Anything more than 3 decimal points wont make a diff
101 tmat_t t;

Callers

nothing calls this directly

Calls 9

TemplateArgClass · 0.85
getNameFunction · 0.85
addInterpEnumOptionsFunction · 0.85
cosFunction · 0.85
sinFunction · 0.85
roundFunction · 0.85
EnqueueArgsClass · 0.85
getKernelFunction · 0.50
getQueueFunction · 0.50

Tested by

no test coverage detected