// Assign values to an array array::array_proxy& af::array::array_proxy::operator=(const array &other) { unsigned nd = numDims(impl->parent_->get()); const dim4 this_dims = getDims(impl->parent_->get()); const dim4 other_dims = other.dims(); int dim = gforDim(impl->indices_); af_array other_arr = other.get(); bool batch_assign = false; bool is_reordered = false; if (dim >= 0) { //FIXME: Figure out a faster, cleaner way to do this dim4 out_dims = seqToDims(impl->indices_, this_dims, false); batch_assign = true; for (int i = 0; i < AF_MAX_DIMS; i++) { if (this->impl->indices_[i].isBatch) batch_assign &= (other_dims[i] == 1); else batch_assign &= (other_dims[i] == out_dims[i]); } if (batch_assign) { af_array out; AF_THROW(af_tile(&out, other_arr, out_dims[0] / other_dims[0], out_dims[1] / other_dims[1], out_dims[2] / other_dims[2], out_dims[3] / other_dims[3])); other_arr = out; } else if (out_dims != other_dims) { // HACK: This is a quick check to see if other has been reordered inside gfor // TODO: Figure out if this breaks and implement a cleaner method other_arr = gforReorder(other_arr, dim); is_reordered = true; } } af_array par_arr = 0; if (impl->is_linear_) { AF_THROW(af_flat(&par_arr, impl->parent_->get())); nd = 1; } else { par_arr = impl->parent_->get(); } af_array tmp = 0; AF_THROW(af_assign_gen(&tmp, par_arr, nd, impl->indices_, other_arr)); af_array res = 0; if (impl->is_linear_) { AF_THROW(af_moddims(&res, tmp, this_dims.ndims(), this_dims.get())); AF_THROW(af_release_array(par_arr)); AF_THROW(af_release_array(tmp)); } else { res = tmp; } impl->parent_->set(res); if (dim >= 0 && (is_reordered || batch_assign)) { if (other_arr) AF_THROW(af_release_array(other_arr)); } return *this; }
array::array(const array& input, const dim_t dim0, const dim_t dim1, const dim_t dim2, const dim_t dim3) : arr(0) { dim_t dims[] = {dim0, dim1, dim2, dim3}; AF_THROW(af_moddims(&arr, input.get(), AF_MAX_DIMS, dims)); }
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::array(const array& input, const dim4& dims) : arr(0) { AF_THROW(af_moddims(&arr, input.get(), AF_MAX_DIMS, dims.get())); }
} af_err err = af_join_many(arr_ud, I(L, 1), count, &arrays.front()); return PushErr(L, err); // num, arrays, inputs, err, arr_ud } }, { "af_moddims", [](lua_State * L) { lua_settop(L, 3); // arr, ndims, dims LuaDims dims(L, 2); af_array * arr_ud = NewArray(L);// arr, ndims, dims, arr_ud af_err err = af_moddims(arr_ud, GetArray(L, 1), dims.GetNDims(), dims.GetDims()); return PushErr(L, err); // arr, ndims, dims, err, arr_ud } }, OUTIN_ARG4(reorder, unsigned, unsigned, unsigned, unsigned), #if AF_API_VERSION >= 31 { "af_replace", [](lua_State * L) { lua_settop(L, 3); // a, cond, b af_err err = af_replace(GetArray(L, 1), GetArray(L, 2), GetArray(L, 3)); lua_pushinteger(L, err);// a, cond, b, err