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

Function createSubArray

src/backend/opencl/Array.cpp:442–473  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

440
441template<typename T>
442Array<T> createSubArray(const Array<T> &parent, const vector<af_seq> &index,
443 bool copy) {
444 parent.eval();
445
446 dim4 dDims = parent.getDataDims();
447 dim4 parent_strides = parent.strides();
448
449 if (parent.isLinear() == false) {
450 const Array<T> parentCopy = copyArray(parent);
451 return createSubArray(parentCopy, index, copy);
452 }
453
454 const dim4 &pDims = parent.dims();
455
456 dim4 dims = toDims(index, pDims);
457 dim4 strides = toStride(index, dDims);
458
459 // Find total offsets after indexing
460 dim4 offsets = toOffset(index, pDims);
461 dim_t offset = parent.getOffset();
462 for (int i = 0; i < 4; i++) { offset += offsets[i] * parent_strides[i]; }
463
464 Array<T> out = Array<T>(parent, dims, offset, strides);
465
466 if (!copy) { return out; }
467
468 if (strides[0] != 1 || strides[1] < 0 || strides[2] < 0 || strides[3] < 0) {
469 out = copyArray(out);
470 }
471
472 return out;
473}
474
475template<typename T>
476Array<T> createHostDataArray(const dim4 &dims, const T *const data) {

Callers 1

susanFunction · 0.70

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