Array<T>* setUnique(const Array<T> &in, const bool is_sorted) { if ((std::is_same<T, double>::value || std::is_same<T, cdouble>::value) && !isDoubleSupported(getActiveDeviceId())) { OPENCL_NOT_SUPPORTED(); } Array<T> *out = copyArray<T>(in); compute::command_queue queue(getQueue()()); compute::buffer out_data((*out->get())()); compute::buffer_iterator<T> begin(out_data, 0); compute::buffer_iterator<T> end(out_data, out->dims()[0]); if (!is_sorted) { compute::sort(begin, end, queue); } end = compute::unique(begin, end, queue); out->resetDims(dim4(std::distance(begin, end), 1, 1, 1)); return out; }
Array<Ty> approx2(const Array<Ty> &in, const Array<Tp> &pos0, const Array<Tp> &pos1, const af_interp_type method, const float offGrid) { if ((std::is_same<Ty, double>::value || std::is_same<Ty, cdouble>::value) && !isDoubleSupported(getActiveDeviceId())) { OPENCL_NOT_SUPPORTED(); } af::dim4 odims = pos0.dims(); odims[2] = in.dims()[2]; odims[3] = in.dims()[3]; // Create output placeholder Array<Ty> out = createEmptyArray<Ty>(odims); switch(method) { case AF_INTERP_NEAREST: kernel::approx2<Ty, Tp, AF_INTERP_NEAREST>(out, in, pos0, pos1, offGrid); break; case AF_INTERP_LINEAR: kernel::approx2<Ty, Tp, AF_INTERP_LINEAR> (out, in, pos0, pos1, offGrid); break; default: break; } return out; }
Array<T> resize(const Array<T> &in, const dim_type odim0, const dim_type odim1, const af_interp_type method) { if ((std::is_same<T, double>::value || std::is_same<T, cdouble>::value) && !isDoubleSupported(getActiveDeviceId())) { OPENCL_NOT_SUPPORTED(); } const af::dim4 iDims = in.dims(); af::dim4 oDims(odim0, odim1, iDims[2], iDims[3]); if(iDims.elements() == 0 || oDims.elements() == 0) { throw std::runtime_error("Elements is 0"); } Array<T> out = createEmptyArray<T>(oDims); switch(method) { case AF_INTERP_NEAREST: kernel::resize<T, AF_INTERP_NEAREST> (out, in); break; case AF_INTERP_BILINEAR: kernel::resize<T, AF_INTERP_BILINEAR>(out, in); break; default: break; } return out; }
void sort_by_key(Array<Tk> &okey, Array<Tv> &oval, const Array<Tk> &ikey, const Array<Tv> &ival, const unsigned dim) { if ((std::is_same<Tk, double>::value || std::is_same<Tk, cdouble>::value) && !isDoubleSupported(getActiveDeviceId())) { OPENCL_NOT_SUPPORTED(); } if ((std::is_same<Tv, double>::value || std::is_same<Tv, cdouble>::value) && !isDoubleSupported(getActiveDeviceId())) { OPENCL_NOT_SUPPORTED(); } try { okey = copyArray<Tk>(ikey); oval = copyArray<Tv>(ival); switch(dim) { case 0: kernel::sort0_by_key<Tk, Tv, isAscending>(okey, oval); break; default: AF_ERROR("Not Supported", AF_ERR_NOT_SUPPORTED); } }catch(std::exception &ex) { AF_ERROR(ex.what(), AF_ERR_INTERNAL); } }
Array<T> *reorder(const Array<T> &in, const af::dim4 &rdims) { if ((std::is_same<T, double>::value || std::is_same<T, cdouble>::value) && !isDoubleSupported(getActiveDeviceId())) { OPENCL_NOT_SUPPORTED(); } const af::dim4 iDims = in.dims(); af::dim4 oDims(0); for(int i = 0; i < 4; i++) oDims[i] = iDims[rdims[i]]; Array<T> *out = createEmptyArray<T>(oDims); kernel::reorder<T>(*out, in, rdims.get()); return out; }
Array<T>* setIntersect(const Array<T> &first, const Array<T> &second, const bool is_unique) { if ((std::is_same<T, double>::value || std::is_same<T, cdouble>::value) && !isDoubleSupported(getActiveDeviceId())) { OPENCL_NOT_SUPPORTED(); } Array<T> unique_first = first; Array<T> unique_second = second; if (!is_unique) { unique_first = *setUnique(first, false); unique_second = *setUnique(second, false); } size_t out_size = std::max(unique_first.dims()[0], unique_second.dims()[0]); Array<T> *out = createEmptyArray<T>(dim4(out_size, 1, 1, 1)); compute::command_queue queue(getQueue()()); compute::buffer first_data((*unique_first.get())()); compute::buffer second_data((*unique_second.get())()); compute::buffer out_data((*out->get())()); compute::buffer_iterator<T> first_begin(first_data, 0); compute::buffer_iterator<T> first_end(first_data, unique_first.dims()[0]); compute::buffer_iterator<T> second_begin(second_data, 0); compute::buffer_iterator<T> second_end(second_data, unique_second.dims()[0]); compute::buffer_iterator<T> out_begin(out_data, 0); compute::buffer_iterator<T> out_end = compute::set_intersection( first_begin, first_end, second_begin, second_end, out_begin, queue ); out->resetDims(dim4(std::distance(out_begin, out_end), 1, 1, 1)); return out; }
Array<T> rotate(const Array<T> &in, const float theta, const af::dim4 &odims, const af_interp_type method) { if ((std::is_same<T, double>::value || std::is_same<T, cdouble>::value) && !isDoubleSupported(getActiveDeviceId())) { OPENCL_NOT_SUPPORTED(); } Array<T> out = createEmptyArray<T>(odims); switch(method) { case AF_INTERP_NEAREST: kernel::rotate<T, AF_INTERP_NEAREST> (out, in, theta); break; case AF_INTERP_BILINEAR: kernel::rotate<T, AF_INTERP_BILINEAR> (out, in, theta); break; default: AF_ERROR("Unsupported interpolation type", AF_ERR_ARG); break; } return out; }