MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / assign

Function assign

src/api/c/assign.cpp:52–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50
51template<typename Tout, typename Tin>
52static 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
99template<typename T>
100static if_complex<T> assign(Array<T>& out, const vector<af_seq> iv,

Callers 1

af_assign_seqFunction · 0.70

Calls 10

toDimsFunction · 0.85
isVectorMethod · 0.80
tileFunction · 0.70
modDimsFunction · 0.70
dimsMethod · 0.45
elementsMethod · 0.45
evalMethod · 0.45
ndimsMethod · 0.45
isScalarMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected