static af_err af_arith_real(af_array *out, const af_array lhs, const af_array rhs, const bool batchMode) { try { ArrayInfo linfo = getInfo(lhs); ArrayInfo rinfo = getInfo(rhs); dim4 odims = getOutDims(linfo.dims(), rinfo.dims(), batchMode); const af_dtype otype = implicit(linfo.getType(), rinfo.getType()); af_array res; switch (otype) { case f32: res = arithOp<float , op>(lhs, rhs, odims); break; case f64: res = arithOp<double , op>(lhs, rhs, odims); break; case s32: res = arithOp<int , op>(lhs, rhs, odims); break; case u32: res = arithOp<uint , op>(lhs, rhs, odims); break; case u8 : res = arithOp<uchar , op>(lhs, rhs, odims); break; case b8 : res = arithOp<char , op>(lhs, rhs, odims); break; case s64: res = arithOp<intl , op>(lhs, rhs, odims); break; case u64: res = arithOp<uintl , op>(lhs, rhs, odims); break; case s16: res = arithOp<short , op>(lhs, rhs, odims); break; case u16: res = arithOp<ushort , op>(lhs, rhs, odims); break; default: TYPE_ERROR(0, otype); } std::swap(*out, res); } CATCHALL; return AF_SUCCESS; }
af_err af_corrcoef(double *realVal, double *imagVal, const af_array X, const af_array Y) { try { ArrayInfo xInfo = getInfo(X); ArrayInfo yInfo = getInfo(Y); dim4 xDims = xInfo.dims(); dim4 yDims = yInfo.dims(); af_dtype xType = xInfo.getType(); af_dtype yType = yInfo.getType(); ARG_ASSERT(2, (xType==yType)); ARG_ASSERT(2, (xDims.ndims()==yDims.ndims())); for (dim_t i=0; i<xDims.ndims(); ++i) ARG_ASSERT(2, (xDims[i]==yDims[i])); switch(xType) { case f64: *realVal = corrcoef<double, double>(X, Y); break; case f32: *realVal = corrcoef<float , float >(X, Y); break; case s32: *realVal = corrcoef<int , float >(X, Y); break; case u32: *realVal = corrcoef<uint , float >(X, Y); break; case s64: *realVal = corrcoef<intl , double>(X, Y); break; case u64: *realVal = corrcoef<uintl , double>(X, Y); break; case s16: *realVal = corrcoef<short , float >(X, Y); break; case u16: *realVal = corrcoef<ushort, float >(X, Y); break; case u8: *realVal = corrcoef<uchar , float >(X, Y); break; case b8: *realVal = corrcoef<char , float >(X, Y); break; default : TYPE_ERROR(1, xType); } } CATCHALL; return AF_SUCCESS; }
af_err af_replace_scalar(af_array a, const af_array cond, const double b) { try { ArrayInfo ainfo = getInfo(a); ArrayInfo cinfo = getInfo(cond); ARG_ASSERT(1, cinfo.getType() == b8); DIM_ASSERT(1, cinfo.ndims() == ainfo.ndims()); dim4 adims = ainfo.dims(); dim4 cdims = cinfo.dims(); for (int i = 0; i < 4; i++) { DIM_ASSERT(1, cdims[i] == adims[i]); } switch (ainfo.getType()) { case f32: replace_scalar<float >(a, cond, b); break; case f64: replace_scalar<double >(a, cond, b); break; case c32: replace_scalar<cfloat >(a, cond, b); break; case c64: replace_scalar<cdouble>(a, cond, b); break; case s32: replace_scalar<int >(a, cond, b); break; case u32: replace_scalar<uint >(a, cond, b); break; case s64: replace_scalar<intl >(a, cond, b); break; case u64: replace_scalar<uintl >(a, cond, b); break; case u8: replace_scalar<uchar >(a, cond, b); break; case b8: replace_scalar<char >(a, cond, b); break; default: TYPE_ERROR(2, ainfo.getType()); } } CATCHALL; return AF_SUCCESS; }
af_err af_matmul(af_array *out, const af_array lhs, const af_array rhs, const af_mat_prop optLhs, const af_mat_prop optRhs) { using namespace detail; try { ArrayInfo lhsInfo = getInfo(lhs, false, true); ArrayInfo rhsInfo = getInfo(rhs, true, true); if(lhsInfo.isSparse()) return af_sparse_matmul(out, lhs, rhs, optLhs, optRhs); af_dtype lhs_type = lhsInfo.getType(); af_dtype rhs_type = rhsInfo.getType(); if (!(optLhs == AF_MAT_NONE || optLhs == AF_MAT_TRANS || optLhs == AF_MAT_CTRANS)) { AF_ERROR("Using this property is not yet supported in matmul", AF_ERR_NOT_SUPPORTED); } if (!(optRhs == AF_MAT_NONE || optRhs == AF_MAT_TRANS || optRhs == AF_MAT_CTRANS)) { AF_ERROR("Using this property is not yet supported in matmul", AF_ERR_NOT_SUPPORTED); } if (lhsInfo.ndims() > 2 || rhsInfo.ndims() > 2) { AF_ERROR("matmul can not be used in batch mode", AF_ERR_BATCH); } TYPE_ASSERT(lhs_type == rhs_type); af_array output = 0; int aColDim = (optLhs == AF_MAT_NONE) ? 1 : 0; int bRowDim = (optRhs == AF_MAT_NONE) ? 0 : 1; DIM_ASSERT(1, lhsInfo.dims()[aColDim] == rhsInfo.dims()[bRowDim]); switch(lhs_type) { case f32: output = matmul<float >(lhs, rhs, optLhs, optRhs); break; case c32: output = matmul<cfloat >(lhs, rhs, optLhs, optRhs); break; case f64: output = matmul<double >(lhs, rhs, optLhs, optRhs); break; case c64: output = matmul<cdouble>(lhs, rhs, optLhs, optRhs); break; default: TYPE_ERROR(1, lhs_type); } std::swap(*out, output); } CATCHALL return AF_SUCCESS; }
af_err af_nearest_neighbour(af_array* idx, af_array* dist, const af_array query, const af_array train, const dim_t dist_dim, const uint n_dist, const af_match_type dist_type) { try { ArrayInfo qInfo = getInfo(query); ArrayInfo tInfo = getInfo(train); af_dtype qType = qInfo.getType(); af_dtype tType = tInfo.getType(); af::dim4 qDims = qInfo.dims(); af::dim4 tDims = tInfo.dims(); uint train_samples = (dist_dim == 0) ? 1 : 0; DIM_ASSERT(2, qDims[dist_dim] == tDims[dist_dim]); DIM_ASSERT(2, qDims[2] == 1 && qDims[3] == 1); DIM_ASSERT(3, tDims[2] == 1 && tDims[3] == 1); DIM_ASSERT(4, (dist_dim == 0 || dist_dim == 1)); DIM_ASSERT(5, n_dist > 0 && n_dist <= (uint)tDims[train_samples]); ARG_ASSERT(6, dist_type == AF_SAD || dist_type == AF_SSD || dist_type == AF_SHD); TYPE_ASSERT(qType == tType); // For Hamming, only u8, u32 and u64 allowed. af_array oIdx; af_array oDist; if(dist_type == AF_SHD) { TYPE_ASSERT(qType == u8 || qType == u32 || qType == u64); switch(qType) { case u8: nearest_neighbour<uchar, uint>(&oIdx, &oDist, query, train, dist_dim, n_dist, dist_type); break; case u32: nearest_neighbour<uint , uint>(&oIdx, &oDist, query, train, dist_dim, n_dist, dist_type); break; case u64: nearest_neighbour<uintl, uint>(&oIdx, &oDist, query, train, dist_dim, n_dist, dist_type); break; default : TYPE_ERROR(1, qType); } } else { switch(qType) { case f32: nearest_neighbour<float , float >(&oIdx, &oDist, query, train, dist_dim, n_dist, dist_type); break; case f64: nearest_neighbour<double, double>(&oIdx, &oDist, query, train, dist_dim, n_dist, dist_type); break; case s32: nearest_neighbour<int , int >(&oIdx, &oDist, query, train, dist_dim, n_dist, dist_type); break; case u32: nearest_neighbour<uint , uint >(&oIdx, &oDist, query, train, dist_dim, n_dist, dist_type); break; case s64: nearest_neighbour<intl , intl >(&oIdx, &oDist, query, train, dist_dim, n_dist, dist_type); break; case u64: nearest_neighbour<uintl , uintl >(&oIdx, &oDist, query, train, dist_dim, n_dist, dist_type); break; case u8: nearest_neighbour<uchar , uint >(&oIdx, &oDist, query, train, dist_dim, n_dist, dist_type); break; default : TYPE_ERROR(1, qType); } } std::swap(*idx, oIdx); std::swap(*dist, oDist); } CATCHALL; return AF_SUCCESS; }
af_err af_select(af_array *out, const af_array cond, const af_array a, const af_array b) { try { ArrayInfo ainfo = getInfo(a); ArrayInfo binfo = getInfo(b); ArrayInfo cinfo = getInfo(cond); if(cinfo.ndims() == 0) { return af_retain_array(out, cond); } ARG_ASSERT(2, ainfo.getType() == binfo.getType()); ARG_ASSERT(1, cinfo.getType() == b8); DIM_ASSERT(1, cinfo.ndims() == std::min(ainfo.ndims(), binfo.ndims())); dim4 adims = ainfo.dims(); dim4 bdims = binfo.dims(); dim4 cdims = cinfo.dims(); dim4 odims(1, 1, 1, 1); for (int i = 0; i < 4; i++) { DIM_ASSERT(1, cdims[i] == std::min(adims[i], bdims[i])); DIM_ASSERT(2, adims[i] == bdims[i] || adims[i] == 1 || bdims[i] == 1); odims[i] = std::max(adims[i], bdims[i]); } af_array res; switch (ainfo.getType()) { case f32: res = select<float >(cond, a, b, odims); break; case f64: res = select<double >(cond, a, b, odims); break; case c32: res = select<cfloat >(cond, a, b, odims); break; case c64: res = select<cdouble>(cond, a, b, odims); break; case s32: res = select<int >(cond, a, b, odims); break; case u32: res = select<uint >(cond, a, b, odims); break; case s64: res = select<intl >(cond, a, b, odims); break; case u64: res = select<uintl >(cond, a, b, odims); break; case s16: res = select<short >(cond, a, b, odims); break; case u16: res = select<ushort >(cond, a, b, odims); break; case u8: res = select<uchar >(cond, a, b, odims); break; case b8: res = select<char >(cond, a, b, odims); break; default: TYPE_ERROR(2, ainfo.getType()); } std::swap(*out, res); } CATCHALL; return AF_SUCCESS; }
af_err convolve2_sep(af_array *out, af_array col_filter, af_array row_filter, af_array signal) { try { ArrayInfo sInfo = getInfo(signal); ArrayInfo cfInfo= getInfo(col_filter); ArrayInfo rfInfo= getInfo(row_filter); af_dtype signalType = sInfo.getType(); dim4 signalDims = sInfo.dims(); ARG_ASSERT(1, (signalDims.ndims()==2 || signalDims.ndims()==3)); ARG_ASSERT(2, cfInfo.isVector()); ARG_ASSERT(3, rfInfo.isVector()); af_array output; switch(signalType) { case c32: output = convolve2<cfloat , cfloat, expand>(signal, col_filter, row_filter); break; case c64: output = convolve2<cdouble, cdouble, expand>(signal, col_filter, row_filter); break; case f32: output = convolve2<float , float, expand>(signal, col_filter, row_filter); break; case f64: output = convolve2<double , double, expand>(signal, col_filter, row_filter); break; case u32: output = convolve2<uint , float, expand>(signal, col_filter, row_filter); break; case s32: output = convolve2<int , float, expand>(signal, col_filter, row_filter); break; case u8: output = convolve2<uchar , float, expand>(signal, col_filter, row_filter); break; case b8: output = convolve2<char , float, expand>(signal, col_filter, row_filter); break; default: TYPE_ERROR(1, signalType); } std::swap(*out,output); } CATCHALL; return AF_SUCCESS; }
af_err af_sort_index(af_array *out, af_array *indices, const af_array in, const unsigned dim, const bool isAscending) { try { ArrayInfo info = getInfo(in); af_dtype type = info.getType(); DIM_ASSERT(2, info.elements() > 0); // Only Dim 0 supported ARG_ASSERT(3, dim == 0); af_array val; af_array idx; switch(type) { case f32: sort_index<float >(&val, &idx, in, dim, isAscending); break; case f64: sort_index<double >(&val, &idx, in, dim, isAscending); break; case s32: sort_index<int >(&val, &idx, in, dim, isAscending); break; case u32: sort_index<uint >(&val, &idx, in, dim, isAscending); break; case u8: sort_index<uchar >(&val, &idx, in, dim, isAscending); break; case b8: sort_index<char >(&val, &idx, in, dim, isAscending); break; default: TYPE_ERROR(1, type); } std::swap(*out , val); std::swap(*indices, idx); } CATCHALL; return AF_SUCCESS; }
af_err convolve(af_array *out, af_array signal, af_array filter) { try { ArrayInfo sInfo = getInfo(signal); ArrayInfo fInfo = getInfo(filter); af_dtype stype = sInfo.getType(); dim4 sdims = sInfo.dims(); dim4 fdims = fInfo.dims(); dim_type batchDim = baseDim+1; ARG_ASSERT(1, (sdims.ndims()<=batchDim)); ARG_ASSERT(2, (fdims.ndims()<=batchDim)); ConvolveBatchKind convBT = identifyBatchKind<baseDim>(sdims.ndims(), fdims.ndims()); af_array output; switch(stype) { case c32: output = convolve<cfloat , cfloat, baseDim, expand>(signal, filter, convBT); break; case c64: output = convolve<cdouble, cdouble, baseDim, expand>(signal, filter, convBT); break; case f32: output = convolve<float , float, baseDim, expand>(signal, filter, convBT); break; case f64: output = convolve<double , double, baseDim, expand>(signal, filter, convBT); break; case u32: output = convolve<uint , float, baseDim, expand>(signal, filter, convBT); break; case s32: output = convolve<int , float, baseDim, expand>(signal, filter, convBT); break; case u8: output = convolve<uchar , float, baseDim, expand>(signal, filter, convBT); break; case b8: output = convolve<char , float, baseDim, expand>(signal, filter, convBT); break; default: TYPE_ERROR(1, stype); } std::swap(*out,output); } CATCHALL; return AF_SUCCESS; }
static void assign_helper(Array<T> &out, const unsigned &ndims, const af_seq *index, const af_array &in_) { ArrayInfo iInfo = getInfo(in_); af_dtype iType = iInfo.getType(); if(out.getType() == c64 || out.getType() == c32) { switch(iType) { case c64: assign<T, cdouble>(out, ndims, index, getArray<cdouble >(in_)); break; case c32: assign<T, cfloat >(out, ndims, index, getArray<cfloat >(in_)); break; default : TYPE_ERROR(1, iType); break; } } else { switch(iType) { case f64: assign<T, double >(out, ndims, index, getArray<double >(in_)); break; case f32: assign<T, float >(out, ndims, index, getArray<float >(in_)); break; case s32: assign<T, int >(out, ndims, index, getArray<int >(in_)); break; case u32: assign<T, uint >(out, ndims, index, getArray<uint >(in_)); break; case s64: assign<T, intl >(out, ndims, index, getArray<intl >(in_)); break; case u64: assign<T, uintl >(out, ndims, index, getArray<uintl >(in_)); break; case u8 : assign<T, uchar >(out, ndims, index, getArray<uchar >(in_)); break; case b8 : assign<T, char >(out, ndims, index, getArray<char >(in_)); break; default : TYPE_ERROR(1, iType); break; } } }
af_err af_sort_by_key(af_array *out_keys, af_array *out_values, const af_array keys, const af_array values, const unsigned dim, const bool isAscending) { try { ArrayInfo info = getInfo(keys); af_dtype type = info.getType(); ArrayInfo vinfo = getInfo(values); DIM_ASSERT(3, info.elements() > 0); DIM_ASSERT(4, info.dims() == vinfo.dims()); // Only Dim 0 supported ARG_ASSERT(5, dim == 0); af_array oKey; af_array oVal; switch(type) { case f32: sort_by_key_tmplt<float >(&oKey, &oVal, keys, values, dim, isAscending); break; case f64: sort_by_key_tmplt<double >(&oKey, &oVal, keys, values, dim, isAscending); break; case s32: sort_by_key_tmplt<int >(&oKey, &oVal, keys, values, dim, isAscending); break; case u32: sort_by_key_tmplt<uint >(&oKey, &oVal, keys, values, dim, isAscending); break; case u8: sort_by_key_tmplt<uchar >(&oKey, &oVal, keys, values, dim, isAscending); break; case b8: sort_by_key_tmplt<char >(&oKey, &oVal, keys, values, dim, isAscending); break; default: TYPE_ERROR(1, type); } std::swap(*out_keys , oKey); std::swap(*out_values , oVal); } CATCHALL; return AF_SUCCESS; }
af_err plot3Wrapper(const af_window wind, const af_array P, const af_cell* const props, const fg::PlotType type=fg::FG_LINE, const fg::MarkerType marker=fg::FG_NONE) { if(wind==0) { std::cerr<<"Not a valid window"<<std::endl; return AF_SUCCESS; } try { ArrayInfo Pinfo = getInfo(P); af_dtype Ptype = Pinfo.getType(); fg::Window* window = reinterpret_cast<fg::Window*>(wind); window->makeCurrent(); fg::Plot3* plot3 = NULL; switch(Ptype) { case f32: plot3 = setup_plot3<float >(P, type, marker); break; case s32: plot3 = setup_plot3<int >(P, type, marker); break; case u32: plot3 = setup_plot3<uint >(P, type, marker); break; case s16: plot3 = setup_plot3<short >(P, type, marker); break; case u16: plot3 = setup_plot3<ushort>(P, type, marker); break; case u8 : plot3 = setup_plot3<uchar >(P, type, marker); break; default: TYPE_ERROR(1, Ptype); } if (props->col>-1 && props->row>-1) window->draw(props->col, props->row, *plot3, props->title); else window->draw(*plot3); } CATCHALL; return AF_SUCCESS; }
af_err af_stdev_all(double *realVal, double *imagVal, const af_array in) { try { ArrayInfo info = getInfo(in); af_dtype type = info.getType(); switch(type) { case f64: *realVal = stdev<double, double>(in); break; case f32: *realVal = stdev<float , float >(in); break; case s32: *realVal = stdev<int , float >(in); break; case u32: *realVal = stdev<uint , float >(in); break; case s16: *realVal = stdev<short , float >(in); break; case u16: *realVal = stdev<ushort, float >(in); break; case s64: *realVal = stdev<intl , double>(in); break; case u64: *realVal = stdev<uintl , double>(in); break; case u8: *realVal = stdev<uchar , float >(in); break; case b8: *realVal = stdev<char , float >(in); break; // TODO: FIXME: sqrt(complex) is not present in cuda/opencl backend //case c32: { // cfloat tmp = stdev<cfloat,cfloat>(in); // *realVal = real(tmp); // *imagVal = imag(tmp); // } break; //case c64: { // cdouble tmp = stdev<cdouble,cdouble>(in); // *realVal = real(tmp); // *imagVal = imag(tmp); // } break; default : TYPE_ERROR(1, type); } } CATCHALL; return AF_SUCCESS; }
static af_err morph3d(af_array *out, const af_array &in, const af_array &mask) { try { ArrayInfo info = getInfo(in); ArrayInfo mInfo= getInfo(mask); af::dim4 dims = info.dims(); af::dim4 mdims = mInfo.dims(); dim_type in_ndims = dims.ndims(); dim_type mask_ndims = mdims.ndims(); DIM_ASSERT(1, (in_ndims == 3)); DIM_ASSERT(2, (mask_ndims == 3)); af_array output; af_dtype type = info.getType(); switch(type) { case f32: output = morph3d<float , isDilation>(in, mask); break; case f64: output = morph3d<double, isDilation>(in, mask); break; case b8 : output = morph3d<char , isDilation>(in, mask); break; case s32: output = morph3d<int , isDilation>(in, mask); break; case u32: output = morph3d<uint , isDilation>(in, mask); break; case u8 : output = morph3d<uchar , isDilation>(in, mask); break; default : TYPE_ERROR(1, type); } std::swap(*out, output); } CATCHALL; return AF_SUCCESS; }
af_err af_sort(af_array *out, const af_array in, const unsigned dim, const bool isAscending) { try { ArrayInfo info = getInfo(in); af_dtype type = info.getType(); if(info.elements() == 0) { return af_retain_array(out, in); } DIM_ASSERT(1, info.elements() > 0); af_array val; switch(type) { case f32: val = sort<float >(in, dim, isAscending); break; case f64: val = sort<double >(in, dim, isAscending); break; case s32: val = sort<int >(in, dim, isAscending); break; case u32: val = sort<uint >(in, dim, isAscending); break; case s16: val = sort<short >(in, dim, isAscending); break; case u16: val = sort<ushort >(in, dim, isAscending); break; case s64: val = sort<intl >(in, dim, isAscending); break; case u64: val = sort<uintl >(in, dim, isAscending); break; case u8: val = sort<uchar >(in, dim, isAscending); break; case b8: val = sort<char >(in, dim, isAscending); break; default: TYPE_ERROR(1, type); } std::swap(*out, val); } CATCHALL; return AF_SUCCESS; }
af_array retain(const af_array in) { ArrayInfo info = getInfo(in, false, false); af_dtype ty = info.getType(); if(info.isSparse()) { switch(ty) { case f32: return retainSparseHandle<float >(in); case f64: return retainSparseHandle<double >(in); case c32: return retainSparseHandle<detail::cfloat >(in); case c64: return retainSparseHandle<detail::cdouble>(in); default: TYPE_ERROR(1, ty); } } else { switch(ty) { case f32: return retainHandle<float >(in); case f64: return retainHandle<double >(in); case s32: return retainHandle<int >(in); case u32: return retainHandle<uint >(in); case u8: return retainHandle<uchar >(in); case c32: return retainHandle<detail::cfloat >(in); case c64: return retainHandle<detail::cdouble >(in); case b8: return retainHandle<char >(in); case s64: return retainHandle<intl >(in); case u64: return retainHandle<uintl >(in); case s16: return retainHandle<short >(in); case u16: return retainHandle<ushort >(in); default: TYPE_ERROR(1, ty); } } }
af_err convert(af_array* out, const af_array in, const float r, const float g, const float b) { try { ArrayInfo info = getInfo(in); af_dtype iType = info.getType(); af::dim4 inputDims = info.dims(); // 2D is not required. if(info.elements() == 0) { dim_t my_dims[] = {0, 0, 0, 0}; return af_create_handle(out, AF_MAX_DIMS, my_dims, iType); } // If RGB is input, then assert 3 channels // else 1 channel if (isRGB2GRAY) ARG_ASSERT(1, (inputDims[2]==3)); else ARG_ASSERT(1, (inputDims[2]==1)); af_array output = 0; switch(iType) { case f64: output = convert<double, double, isRGB2GRAY>(in, r, g, b); break; case f32: output = convert<float , float , isRGB2GRAY>(in, r, g, b); break; case u32: output = convert<uint , float , isRGB2GRAY>(in, r, g, b); break; case s32: output = convert<int , float , isRGB2GRAY>(in, r, g, b); break; case u16: output = convert<ushort, float , isRGB2GRAY>(in, r, g, b); break; case s16: output = convert<short , float , isRGB2GRAY>(in, r, g, b); break; case u8: output = convert<uchar , float , isRGB2GRAY>(in, r, g, b); break; default: TYPE_ERROR(1, iType); break; } std::swap(*out, output); } CATCHALL; return AF_SUCCESS; }
//Strong Exception Guarantee af_err af_get_data_ref_count(int *use_count, const af_array in) { try { ArrayInfo info = getInfo(in, false, false); const af_dtype type = info.getType(); int res; switch(type) { case f32: res = getArray<float >(in).useCount(); break; case c32: res = getArray<cfloat >(in).useCount(); break; case f64: res = getArray<double >(in).useCount(); break; case c64: res = getArray<cdouble >(in).useCount(); break; case b8: res = getArray<char >(in).useCount(); break; case s32: res = getArray<int >(in).useCount(); break; case u32: res = getArray<uint >(in).useCount(); break; case u8: res = getArray<uchar >(in).useCount(); break; case s64: res = getArray<intl >(in).useCount(); break; case u64: res = getArray<uintl >(in).useCount(); break; case s16: res = getArray<short >(in).useCount(); break; case u16: res = getArray<ushort >(in).useCount(); break; default: TYPE_ERROR(1, type); } std::swap(*use_count, res); } CATCHALL return AF_SUCCESS; }
//Strong Exception Guarantee af_err af_copy_array(af_array *out, const af_array in) { try { ArrayInfo info = getInfo(in); const af_dtype type = info.getType(); if(info.ndims() == 0) { dim_t my_dims[] = {0, 0, 0, 0}; return af_create_handle(out, AF_MAX_DIMS, my_dims, type); } af_array res; switch(type) { case f32: res = copyArray<float >(in); break; case c32: res = copyArray<cfloat >(in); break; case f64: res = copyArray<double >(in); break; case c64: res = copyArray<cdouble >(in); break; case b8: res = copyArray<char >(in); break; case s32: res = copyArray<int >(in); break; case u32: res = copyArray<uint >(in); break; case u8: res = copyArray<uchar >(in); break; case s64: res = copyArray<intl >(in); break; case u64: res = copyArray<uintl >(in); break; case s16: res = copyArray<short >(in); break; case u16: res = copyArray<ushort >(in); break; default: TYPE_ERROR(1, type); } std::swap(*out, res); } CATCHALL return AF_SUCCESS; }
af_err af_resize(af_array *out, const af_array in, const dim_type odim0, const dim_type odim1, const af_interp_type method) { try { ArrayInfo info = getInfo(in); af_dtype type = info.getType(); af::dim4 dims = info.dims(); DIM_ASSERT(1, (dims.ndims() == 2 || dims.ndims() == 3)); ARG_ASSERT(4, (method == AF_INTERP_BILINEAR || method == AF_INTERP_NEAREST)); DIM_ASSERT(2, odim0 > 0); DIM_ASSERT(3, odim1 > 0); af_array output; switch(type) { case f32: output = resize<float >(in, odim0, odim1, method); break; case f64: output = resize<double >(in, odim0, odim1, method); break; case b8: output = resize<char >(in, odim0, odim1, method); break; case s32: output = resize<int >(in, odim0, odim1, method); break; case u32: output = resize<uint >(in, odim0, odim1, method); break; case u8: output = resize<uchar >(in, odim0, odim1, method); break; case s8: output = resize<char >(in, odim0, odim1, method); break; default: TYPE_ERROR(1, type); } std::swap(*out,output); } CATCHALL; return AF_SUCCESS; }
static af_err bilateral(af_array *out, const af_array &in, const float &s_sigma, const float &c_sigma) { try { ArrayInfo info = getInfo(in); af_dtype type = info.getType(); af::dim4 dims = info.dims(); DIM_ASSERT(1, (dims.ndims()>=2)); af_array output; switch(type) { case f64: output = bilateral<double, double, isColor> (in, s_sigma, c_sigma); break; case f32: output = bilateral<float , float, isColor> (in, s_sigma, c_sigma); break; case b8 : output = bilateral<char , float, isColor> (in, s_sigma, c_sigma); break; case s32: output = bilateral<int , float, isColor> (in, s_sigma, c_sigma); break; case u32: output = bilateral<uint , float, isColor> (in, s_sigma, c_sigma); break; case u8 : output = bilateral<uchar , float, isColor> (in, s_sigma, c_sigma); break; case s16: output = bilateral<short , float, isColor> (in, s_sigma, c_sigma); break; case u16: output = bilateral<ushort, float, isColor> (in, s_sigma, c_sigma); break; default : TYPE_ERROR(1, type); } std::swap(*out,output); } CATCHALL; return AF_SUCCESS; }
af_err af_fast(af_features *out, const af_array in, const float thr, const unsigned arc_length, const bool non_max, const float feature_ratio, const unsigned edge) { try { ArrayInfo info = getInfo(in); af::dim4 dims = info.dims(); ARG_ASSERT(2, (dims[0] >= (int)(2*edge+1) || dims[1] >= (int)(2*edge+1))); ARG_ASSERT(3, thr > 0.0f); ARG_ASSERT(4, (arc_length >= 9 && arc_length <= 16)); ARG_ASSERT(6, (feature_ratio > 0.0f && feature_ratio <= 1.0f)); dim_type in_ndims = dims.ndims(); DIM_ASSERT(1, (in_ndims <= 3 && in_ndims >= 2)); af_dtype type = info.getType(); switch(type) { case f32: *out = fast<float >(in, thr, arc_length, non_max, feature_ratio, edge); break; case f64: *out = fast<double>(in, thr, arc_length, non_max, feature_ratio, edge); break; case b8 : *out = fast<char >(in, thr, arc_length, non_max, feature_ratio, edge); break; case s32: *out = fast<int >(in, thr, arc_length, non_max, feature_ratio, edge); break; case u32: *out = fast<uint >(in, thr, arc_length, non_max, feature_ratio, edge); break; case u8 : *out = fast<uchar >(in, thr, arc_length, non_max, feature_ratio, edge); break; default : TYPE_ERROR(1, type); } } CATCHALL; return AF_SUCCESS; }
af_err af_diff2(af_array *out, const af_array in, const int dim) { try { ARG_ASSERT(2, ((dim >= 0) && (dim < 4))); ArrayInfo info = getInfo(in); af_dtype type = info.getType(); af::dim4 in_dims = info.dims(); DIM_ASSERT(1, in_dims[dim] >= 3); af_array output; switch(type) { case f32: output = diff2<float >(in,dim); break; case c32: output = diff2<cfloat >(in,dim); break; case f64: output = diff2<double >(in,dim); break; case c64: output = diff2<cdouble>(in,dim); break; case b8: output = diff2<char >(in,dim); break; case s32: output = diff2<int >(in,dim); break; case u32: output = diff2<uint >(in,dim); break; case s64: output = diff2<intl >(in,dim); break; case u64: output = diff2<uintl >(in,dim); break; case u8: output = diff2<uchar >(in,dim); break; default: TYPE_ERROR(1, type); } std::swap(*out,output); } CATCHALL; return AF_SUCCESS; }
//Strong Exception Guarantee af_err af_copy_array(af_array *out, const af_array in) { ArrayInfo info = getInfo(in); const unsigned ndims = info.ndims(); const af::dim4 dims = info.dims(); const af_dtype type = info.getType(); af_err ret = AF_ERR_ARG; ret = af_create_handle(out, ndims, dims.get(), type); if(ret != AF_SUCCESS) { return ret; } try { switch(type) { case f32: copyArray<float >(out, in); break; case c32: copyArray<cfloat >(out, in); break; case f64: copyArray<double >(out, in); break; case c64: copyArray<cdouble >(out, in); break; case b8: copyArray<char >(out, in); break; case s32: copyArray<int >(out, in); break; case u32: copyArray<unsigned>(out, in); break; case u8: copyArray<uchar >(out, in); break; default: ret = AF_ERR_NOT_SUPPORTED; break; } } CATCHALL return ret; }
af_err af_histogram(af_array *out, const af_array in, const unsigned nbins, const double minval, const double maxval) { try { ArrayInfo info = getInfo(in); af_dtype type = info.getType(); af::dim4 dims = info.dims(); DIM_ASSERT(1, (dims.ndims()<=3)); af_array output; switch(type) { case f32: output = histogram<float , uint>(in, nbins, minval, maxval); break; case f64: output = histogram<double, uint>(in, nbins, minval, maxval); break; case b8 : output = histogram<char , uint>(in, nbins, minval, maxval); break; case s32: output = histogram<int , uint>(in, nbins, minval, maxval); break; case u32: output = histogram<uint , uint>(in, nbins, minval, maxval); break; case u8 : output = histogram<uchar , uint>(in, nbins, minval, maxval); break; default : TYPE_ERROR(1, type); } std::swap(*out,output); } CATCHALL; return AF_SUCCESS; }
af_err af_stdev(af_array *out, const af_array in, const dim_t dim) { try { ARG_ASSERT(2, (dim>=0 && dim<=3)); af_array output = 0; ArrayInfo info = getInfo(in); af_dtype type = info.getType(); switch(type) { case f64: output = stdev<double, double>(in, dim); break; case f32: output = stdev<float , float >(in, dim); break; case s32: output = stdev<int , float >(in, dim); break; case u32: output = stdev<uint , float >(in, dim); break; case s16: output = stdev<short , float >(in, dim); break; case u16: output = stdev<ushort, float >(in, dim); break; case s64: output = stdev<intl , double>(in, dim); break; case u64: output = stdev<uintl , double>(in, dim); break; case u8: output = stdev<uchar , float >(in, dim); break; case b8: output = stdev<char , float >(in, dim); break; // TODO: FIXME: sqrt(complex) is not present in cuda/opencl backend //case c32: output = stdev<cfloat, cfloat>(in, dim); break; //case c64: output = stdev<cdouble,cdouble>(in, dim); break; default : TYPE_ERROR(1, type); } std::swap(*out, output); } CATCHALL; return AF_SUCCESS; }
af_err af_tile(af_array *out, const af_array in, const af::dim4 &tileDims) { try { ArrayInfo info = getInfo(in); af_dtype type = info.getType(); if(info.ndims() == 0) { return af_retain_array(out, in); } DIM_ASSERT(1, info.dims().elements() > 0); DIM_ASSERT(2, tileDims.elements() > 0); af_array output; switch(type) { case f32: output = tile<float >(in, tileDims); break; case c32: output = tile<cfloat >(in, tileDims); break; case f64: output = tile<double >(in, tileDims); break; case c64: output = tile<cdouble>(in, tileDims); break; case b8: output = tile<char >(in, tileDims); break; case s32: output = tile<int >(in, tileDims); break; case u32: output = tile<uint >(in, tileDims); break; case s64: output = tile<intl >(in, tileDims); break; case u64: output = tile<uintl >(in, tileDims); break; case s16: output = tile<short >(in, tileDims); break; case u16: output = tile<ushort >(in, tileDims); break; case u8: output = tile<uchar >(in, tileDims); break; default: TYPE_ERROR(1, type); } std::swap(*out,output); } CATCHALL; return AF_SUCCESS; }
af_err af_histogram(af_array *out, const af_array in, const unsigned nbins, const double minval, const double maxval) { try { ArrayInfo info = getInfo(in); af_dtype type = info.getType(); af_array output; switch(type) { case f32: output = histogram<float , uint>(in, nbins, minval, maxval, info.isLinear()); break; case f64: output = histogram<double, uint>(in, nbins, minval, maxval, info.isLinear()); break; case b8 : output = histogram<char , uint>(in, nbins, minval, maxval, info.isLinear()); break; case s32: output = histogram<int , uint>(in, nbins, minval, maxval, info.isLinear()); break; case u32: output = histogram<uint , uint>(in, nbins, minval, maxval, info.isLinear()); break; case s16: output = histogram<short , uint>(in, nbins, minval, maxval, info.isLinear()); break; case u16: output = histogram<ushort, uint>(in, nbins, minval, maxval, info.isLinear()); break; case s64: output = histogram<intl , uint>(in, nbins, minval, maxval, info.isLinear()); break; case u64: output = histogram<uintl , uint>(in, nbins, minval, maxval, info.isLinear()); break; case u8 : output = histogram<uchar , uint>(in, nbins, minval, maxval, info.isLinear()); break; default : TYPE_ERROR(1, type); } std::swap(*out,output); } CATCHALL; return AF_SUCCESS; }
af_err af_regions(af_array *out, const af_array in, const af_connectivity connectivity, const af_dtype type) { try { ARG_ASSERT(2, (connectivity==AF_CONNECTIVITY_4 || connectivity==AF_CONNECTIVITY_8)); ArrayInfo info = getInfo(in); af::dim4 dims = info.dims(); dim_t in_ndims = dims.ndims(); DIM_ASSERT(1, (in_ndims <= 3 && in_ndims >= 2)); af_dtype in_type = info.getType(); if (in_type != b8) { TYPE_ERROR(1, in_type); } af_array output; switch(type) { case f32: output = regions<float >(in, connectivity); break; case f64: output = regions<double>(in, connectivity); break; case s32: output = regions<int >(in, connectivity); break; case u32: output = regions<uint >(in, connectivity); break; case s16: output = regions<short >(in, connectivity); break; case u16: output = regions<ushort>(in, connectivity); break; default : TYPE_ERROR(0, type); } std::swap(*out, output); } CATCHALL; return AF_SUCCESS; }
af_err af_shift(af_array *out, const af_array in, const af::dim4 &sdims) { try { ArrayInfo info = getInfo(in); af_dtype type = info.getType(); DIM_ASSERT(1, info.elements() > 0); af_array output; switch(type) { case f32: output = shift<float >(in, sdims); break; case c32: output = shift<cfloat >(in, sdims); break; case f64: output = shift<double >(in, sdims); break; case c64: output = shift<cdouble>(in, sdims); break; case b8: output = shift<char >(in, sdims); break; case s32: output = shift<int >(in, sdims); break; case u32: output = shift<uint >(in, sdims); break; case u8: output = shift<uchar >(in, sdims); break; default: TYPE_ERROR(1, type); } std::swap(*out,output); } CATCHALL; return AF_SUCCESS; }