| 50 | } |
| 51 | |
| 52 | af_err af_example_function(af_array* out, const af_array a, |
| 53 | const af_someenum_t param) { |
| 54 | try { |
| 55 | af_array output = 0; |
| 56 | const ArrayInfo& info = |
| 57 | getInfo(a); // ArrayInfo is the base class which |
| 58 | // each backend specific Array inherits |
| 59 | // This class stores the basic array meta-data |
| 60 | // such as type of data, dimensions, |
| 61 | // offsets and strides. This class is declared |
| 62 | // in src/backend/common/ArrayInfo.hpp |
| 63 | af::dim4 dims = info.dims(); |
| 64 | |
| 65 | ARG_ASSERT(2, (dims.ndims() >= 0 && dims.ndims() <= 3)); |
| 66 | // defined in err_common.hpp |
| 67 | // there are other useful Macros |
| 68 | // for different purposes, feel free |
| 69 | // to look at the header |
| 70 | |
| 71 | af_dtype type = info.getType(); |
| 72 | |
| 73 | switch (type) { // Based on the data type, call backend specific |
| 74 | // implementation |
| 75 | case f64: output = example<double>(a, a, param); break; |
| 76 | case f32: output = example<float>(a, a, param); break; |
| 77 | case s32: output = example<int>(a, a, param); break; |
| 78 | case u32: output = example<uint>(a, a, param); break; |
| 79 | case s8: output = example<schar>(a, a, param); break; |
| 80 | case u8: output = example<uchar>(a, a, param); break; |
| 81 | case b8: output = example<char>(a, a, param); break; |
| 82 | case c32: output = example<cfloat>(a, a, param); break; |
| 83 | case c64: output = example<cdouble>(a, a, param); break; |
| 84 | default: |
| 85 | TYPE_ERROR(1, |
| 86 | type); // Another helpful macro from err_common.hpp |
| 87 | // that helps throw type based error messages |
| 88 | } |
| 89 | |
| 90 | std::swap(*out, output); // if the function has returned successfully, |
| 91 | // swap the temporary 'output' variable with |
| 92 | // '*out' |
| 93 | } |
| 94 | CATCHALL; // All throws/exceptions from any internal |
| 95 | // implementations are caught by this CATCHALL |
| 96 | // macro and handled appropriately. |
| 97 | |
| 98 | return AF_SUCCESS; // In case of successfull completion, return AF_SUCCESS |
| 99 | // There are set of error codes defined in defines.h |
| 100 | // which you are used by CATCHALL to return approriate |
| 101 | // code |
| 102 | } |
no test coverage detected