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

Function createSubArray

src/backend/oneapi/Array.cpp:430–461  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

428
429template<typename T>
430Array<T> createSubArray(const Array<T> &parent, const vector<af_seq> &index,
431 bool copy) {
432 parent.eval();
433
434 dim4 dDims = parent.getDataDims();
435 dim4 parent_strides = parent.strides();
436
437 if (parent.isLinear() == false) {
438 const Array<T> parentCopy = copyArray(parent);
439 return createSubArray(parentCopy, index, copy);
440 }
441
442 const dim4 &pDims = parent.dims();
443
444 dim4 dims = toDims(index, pDims);
445 dim4 strides = toStride(index, dDims);
446
447 // Find total offsets after indexing
448 dim4 offsets = toOffset(index, pDims);
449 dim_t offset = parent.getOffset();
450 for (int i = 0; i < 4; i++) { offset += offsets[i] * parent_strides[i]; }
451
452 Array<T> out = Array<T>(parent, dims, offset, strides);
453
454 if (!copy) { return out; }
455
456 if (strides[0] != 1 || strides[1] < 0 || strides[2] < 0 || strides[3] < 0) {
457 out = copyArray(out);
458 }
459
460 return out;
461}
462
463template<typename T>
464Array<T> createHostDataArray(const dim4 &dims, const T *const data) {

Callers

nothing calls this directly

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