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

Function af_pad

src/api/c/data.cpp:423–470  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

421}
422
423af_err af_pad(af_array *out, const af_array in, const unsigned begin_ndims,
424 const dim_t *const begin_dims, const unsigned end_ndims,
425 const dim_t *const end_dims, const af_border_type pad_type) {
426 try {
427 DIM_ASSERT(2, begin_ndims > 0 && begin_ndims <= 4);
428 DIM_ASSERT(4, end_ndims > 0 && end_ndims <= 4);
429 ARG_ASSERT(3, begin_dims != NULL);
430 ARG_ASSERT(5, end_dims != NULL);
431 ARG_ASSERT(6, (pad_type >= AF_PAD_ZERO && pad_type <= AF_PAD_PERIODIC));
432 for (unsigned i = 0; i < begin_ndims; i++) {
433 DIM_ASSERT(3, begin_dims[i] >= 0);
434 }
435 for (unsigned i = 0; i < end_ndims; i++) {
436 DIM_ASSERT(5, end_dims[i] >= 0);
437 }
438
439 dim4 lPad(begin_ndims, begin_dims);
440 dim4 uPad(end_ndims, end_dims);
441 for (unsigned i = begin_ndims; i < AF_MAX_DIMS; i++) { lPad[i] = 0; }
442 for (unsigned i = end_ndims; i < AF_MAX_DIMS; i++) { uPad[i] = 0; }
443
444 const ArrayInfo &info = getInfo(in);
445 af_dtype type = info.getType();
446
447 if (info.ndims() == 0) { return af_retain_array(out, in); }
448
449 af_array res = 0;
450 switch (type) {
451 case f32: res = pad<float>(in, lPad, uPad, pad_type); break;
452 case f64: res = pad<double>(in, lPad, uPad, pad_type); break;
453 case c32: res = pad<cfloat>(in, lPad, uPad, pad_type); break;
454 case c64: res = pad<cdouble>(in, lPad, uPad, pad_type); break;
455 case s32: res = pad<int>(in, lPad, uPad, pad_type); break;
456 case u32: res = pad<uint>(in, lPad, uPad, pad_type); break;
457 case s64: res = pad<intl>(in, lPad, uPad, pad_type); break;
458 case u64: res = pad<uintl>(in, lPad, uPad, pad_type); break;
459 case s16: res = pad<short>(in, lPad, uPad, pad_type); break;
460 case u16: res = pad<ushort>(in, lPad, uPad, pad_type); break;
461 case s8: res = pad<schar>(in, lPad, uPad, pad_type); break;
462 case u8: res = pad<uchar>(in, lPad, uPad, pad_type); break;
463 case b8: res = pad<char>(in, lPad, uPad, pad_type); break;
464 case f16: res = pad<half>(in, lPad, uPad, pad_type); break;
465 }
466 std::swap(*out, res);
467 }
468 CATCHALL
469 return AF_SUCCESS;
470}

Callers 2

TESTFunction · 0.50
padFunction · 0.50

Calls 4

swapFunction · 0.85
af_retain_arrayFunction · 0.70
getTypeMethod · 0.45
ndimsMethod · 0.45

Tested by

no test coverage detected