// Helper functions dim4 array::dims() const { dim_type d0, d1, d2, d3; AF_THROW(af_get_dims(&d0, &d1, &d2, &d3, arr)); return dim4(d0, d1, d2, d3); }
array upper(const array &in, bool is_unit_diag) { af_array res; AF_THROW(af_upper(&res, in.get(), is_unit_diag)); return array(res); }
void Window::hist(const array& X, const double minval, const double maxval, const char* const title) { af_cell temp{_r, _c, title, AF_COLORMAP_DEFAULT}; AF_THROW(af_draw_hist(get(), X.get(), minval, maxval, &temp)); }
array tile(const array& in, const af::dim4 &dims) { af_array out = 0; AF_THROW(af_tile(&out, in.get(), dims[0], dims[1], dims[2], dims[3])); return array(out); }
array shift(const array& in, const int x, const int y, const int z, const int w) { af_array out = 0; AF_THROW(af_shift(&out, in.get(), x, y, z, w)); return array(out); }
array identity(const dim4 &dims, const af::dtype type) { af_array res; AF_THROW(af_identity(&res, dims.ndims(), dims.get(), type)); return array(res); }
array flat(const array& in) { af_array out = 0; AF_THROW(af_flat(&out, in.get())); return array(out); }
void array::eval() const { AF_THROW(af_eval(get())); }
void array::free(const void *ptr) { //FIXME: look up map and call the right free AF_THROW(af_free_device((void *)ptr)); }
array array::as(af_dtype type) const { af_array out; AF_THROW(af_cast(&out, this->get(), type)); return array(out); }
array::array(const array& in) : arr(0), isRef(false) { AF_THROW(af_weak_copy(&arr, in.get())); }
array array::copy() const { af_array *other = 0; AF_THROW(af_copy_array(other, arr)); return array(*other); }
size_t array::bytes() const { dim_type nElements; AF_THROW(af_get_elements(&nElements, arr)); return nElements * size_of(type()); }
unsigned array::numdims() const { unsigned nd; AF_THROW(af_get_numdims(&nd, arr)); return nd; }
array range(const dim4 &dims, const int seq_dim, const af::dtype ty) { af_array out; AF_THROW(af_range(&out, dims.ndims(), dims.get(), seq_dim, ty)); return array(out); }
array approx1(const array& yi, const array &xo, const interpType method, const float offGrid) { af_array yo = 0; AF_THROW(af_approx1(&yo, yi.get(), xo.get(), method, offGrid)); return array(yo); }
array iota(const dim4 &dims, const dim4 &tile_dims, const af::dtype ty) { af_array out; AF_THROW(af_iota(&out, dims.ndims(), dims.get(), tile_dims.ndims(), tile_dims.get(), ty)); return array(out); }
AFAPI array median(const array& in, const dim_t dim) { af_array temp = 0; AF_THROW(af_median(&temp, in.get(), getFNSD(dim, in.dims()))); return array(temp); }
array moddims(const array& in, const unsigned ndims, const dim_t * const dims) { af_array out = 0; AF_THROW(af_moddims(&out, in.get(), ndims, dims)); return array(out); }
array transform(const array& in, const array& transform, const dim_type odim0, const dim_type odim1, const bool inverse) { af_array out = 0; AF_THROW(af_transform(&out, in.get(), transform.get(), odim0, odim1, inverse)); return array(out); }
array join(const int dim, const array& first, const array& second) { af_array out = 0; AF_THROW(af_join(&out, dim, first.get(), second.get())); return array(out); }
array scale(const array& in, const float scale0, const float scale1, const dim_t odim0, const dim_t odim1, const interpType method) { af_array out = 0; AF_THROW(af_scale(&out, in.get(), scale0, scale1, odim0, odim1, method)); return array(out); }
array reorder(const array& in, const unsigned x, const unsigned y, const unsigned z, const unsigned w) { af_array out = 0; AF_THROW(af_reorder(&out, in.get(), x, y, z, w)); return array(out); }
array randn(const dim4 &dims, const af::dtype type) { af_array res; AF_THROW(af_randn(&res, dims.ndims(), dims.get(), type)); return array(res); }
array flip(const array &in, const unsigned dim) { af_array out = 0; AF_THROW(af_flip(&out, in.get(), dim)); return array(out); }
void setSeed(const uintl seed) { AF_THROW(af_set_seed(seed)); }
void Window::scatter3(const array& P, af::markerType marker, const char* const title) { af_cell temp{_r, _c, title, AF_COLORMAP_DEFAULT}; AF_THROW(af_draw_scatter_nd(get(), P.get(), marker, &temp)); }
uintl getSeed() { uintl seed = 0; AF_THROW(af_get_seed(&seed)); return seed; }
void Window::surface(const array& S, const char* const title) { af::array xVals = range(S.dims(0)); af::array yVals = range(S.dims(1)); af_cell temp{_r, _c, title, AF_COLORMAP_DEFAULT}; AF_THROW(af_draw_surface(get(), xVals.get(), yVals.get(), S.get(), &temp)); }
void array::host(void *data) const { AF_THROW(af_get_data_ptr(data, arr)); }