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

Function createSubArray

src/backend/cuda/Array.cpp:387–417  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

385
386template<typename T>
387Array<T> createSubArray(const Array<T> &parent,
388 const std::vector<af_seq> &index, bool copy) {
389 parent.eval();
390
391 dim4 dDims = parent.getDataDims();
392 dim4 parent_strides = parent.strides();
393
394 if (parent.isLinear() == false) {
395 const Array<T> parentCopy = copyArray(parent);
396 return createSubArray(parentCopy, index, copy);
397 }
398
399 const dim4 &pDims = parent.dims();
400 dim4 dims = toDims(index, pDims);
401 dim4 strides = toStride(index, dDims);
402
403 // Find total offsets after indexing
404 dim4 offsets = toOffset(index, pDims);
405 dim_t offset = parent.getOffset();
406 for (int i = 0; i < 4; i++) { offset += offsets[i] * parent_strides[i]; }
407
408 Array<T> out = Array<T>(parent, dims, offset, strides);
409
410 if (!copy) { return out; }
411
412 if (strides[0] != 1 || strides[1] < 0 || strides[2] < 0 || strides[3] < 0) {
413 out = copyArray(out);
414 }
415
416 return out;
417}
418
419template<typename T>
420Array<T> createParamArray(Param<T> &tmp, bool owner) {

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