| 50 | |
| 51 | template<typename Tout, typename Tin> |
| 52 | static void assign(Array<Tout>& out, const vector<af_seq> seqs, |
| 53 | const Array<Tin>& in) { |
| 54 | size_t ndims = seqs.size(); |
| 55 | const dim4& outDs = out.dims(); |
| 56 | const dim4& iDims = in.dims(); |
| 57 | |
| 58 | if (iDims.elements() == 0) { return; } |
| 59 | |
| 60 | out.eval(); |
| 61 | |
| 62 | dim4 oDims = toDims(seqs, outDs); |
| 63 | |
| 64 | bool isVec = true; |
| 65 | for (int i = 0; isVec && i < static_cast<int>(oDims.ndims()) - 1; i++) { |
| 66 | isVec &= oDims[i] == 1; |
| 67 | } |
| 68 | |
| 69 | isVec &= in.isVector() || in.isScalar(); |
| 70 | |
| 71 | for (auto i = static_cast<dim_t>(ndims); i < in.ndims(); i++) { |
| 72 | oDims[i] = 1; |
| 73 | } |
| 74 | |
| 75 | if (isVec) { |
| 76 | if (oDims.elements() != in.elements() && in.elements() != 1) { |
| 77 | AF_ERROR("Size mismatch between input and output", AF_ERR_SIZE); |
| 78 | } |
| 79 | |
| 80 | // If both out and in are vectors of equal elements, |
| 81 | // reshape in to out dims |
| 82 | Array<Tin> in_ = in.elements() == 1 ? arrayfire::common::tile(in, oDims) |
| 83 | : modDims(in, oDims); |
| 84 | auto dst = createSubArray<Tout>(out, seqs, false); |
| 85 | |
| 86 | copyArray<Tin, Tout>(dst, in_); |
| 87 | } else { |
| 88 | for (int i = 0; i < AF_MAX_DIMS; i++) { |
| 89 | if (oDims[i] != iDims[i]) { |
| 90 | AF_ERROR("Size mismatch between input and output", AF_ERR_SIZE); |
| 91 | } |
| 92 | } |
| 93 | Array<Tout> dst = createSubArray<Tout>(out, seqs, false); |
| 94 | |
| 95 | copyArray<Tin, Tout>(dst, in); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | template<typename T> |
| 100 | static if_complex<T> assign(Array<T>& out, const vector<af_seq> iv, |