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

Function createSubArray

src/backend/cpu/Array.cpp:275–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

273
274template<typename T>
275Array<T> createSubArray(const Array<T> &parent, const vector<af_seq> &index,
276 bool copy) {
277 parent.eval();
278
279 dim4 dDims = parent.getDataDims();
280 dim4 parent_strides = parent.strides();
281
282 if (parent.isLinear() == false) {
283 const Array<T> parentCopy = copyArray(parent);
284 return createSubArray(parentCopy, index, copy);
285 }
286
287 const dim4 &pDims = parent.dims();
288 dim4 dims = toDims(index, pDims);
289 dim4 strides = toStride(index, dDims);
290
291 // Find total offsets after indexing
292 dim4 offsets = toOffset(index, pDims);
293 dim_t offset = parent.getOffset();
294 for (int i = 0; i < 4; i++) { offset += offsets[i] * parent_strides[i]; }
295
296 Array<T> out = Array<T>(parent, dims, offset, strides);
297
298 if (!copy) { return out; }
299
300 if (strides[0] != 1 || strides[1] < 0 || strides[2] < 0 || strides[3] < 0) {
301 out = copyArray(out);
302 }
303
304 return out;
305}
306
307template<typename T>
308void destroyArray(Array<T> *A) {

Callers 7

morphFunction · 0.70
flipFunction · 0.50
multiplyIndexedFunction · 0.50
otsuThresholdFunction · 0.50
indexBySeqsFunction · 0.50
rgb2grayFunction · 0.50
convertFunction · 0.50

Calls 10

toDimsFunction · 0.85
toStrideFunction · 0.85
toOffsetFunction · 0.85
copyArrayFunction · 0.70
evalMethod · 0.45
getDataDimsMethod · 0.45
stridesMethod · 0.45
isLinearMethod · 0.45
dimsMethod · 0.45
getOffsetMethod · 0.45

Tested by

no test coverage detected