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

Function conv_image

test/arrayfire_test.cpp:1357–1390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1355// TODO: perform conversion on device for CUDA and OpenCL
1356template<typename T>
1357af_err conv_image(af_array *out, af_array in) {
1358 af_array outArray;
1359
1360 dim_t d0, d1, d2, d3;
1361 af_get_dims(&d0, &d1, &d2, &d3, in);
1362 af::dim4 idims(d0, d1, d2, d3);
1363
1364 dim_t nElems = 0;
1365 af_get_elements(&nElems, in);
1366
1367 float *in_data = new float[nElems];
1368 af_get_data_ptr(in_data, in);
1369
1370 T *out_data = new T[nElems];
1371
1372 af_dtype out_type = (af_dtype)af::dtype_traits<T>::af_type;
1373 for (int i = 0; i < (int)nElems; i++) {
1374 if (out_type == s8) {
1375 // shift to avoid overflow
1376 out_data[i] = (T)(std::trunc(in_data[i]) - 128.f);
1377 } else {
1378 out_data[i] = (T)in_data[i];
1379 }
1380 }
1381
1382 af_create_array(&outArray, out_data, idims.ndims(), idims.get(), out_type);
1383
1384 std::swap(*out, outArray);
1385
1386 delete[] in_data;
1387 delete[] out_data;
1388
1389 return AF_SUCCESS;
1390}
1391
1392#define INSTANTIATE(To) \
1393 template af_err conv_image<To>(af_array * out, af_array in)

Callers

nothing calls this directly

Calls 8

af_get_elementsFunction · 0.85
truncFunction · 0.85
swapFunction · 0.85
af_get_dimsFunction · 0.50
af_get_data_ptrFunction · 0.50
af_create_arrayFunction · 0.50
ndimsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected