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

Function af_clamp

src/api/c/clamp.cpp:47–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47af_err af_clamp(af_array* out, const af_array in, const af_array lo,
48 const af_array hi, const bool batch) {
49 try {
50 const ArrayInfo& linfo = getInfo(lo);
51 const ArrayInfo& hinfo = getInfo(hi);
52 const ArrayInfo& iinfo = getInfo(in);
53
54 DIM_ASSERT(2, linfo.dims() == hinfo.dims());
55 TYPE_ASSERT(linfo.getType() == hinfo.getType());
56
57 dim4 odims = getOutDims(iinfo.dims(), linfo.dims(), batch);
58 const af_dtype otype = implicit(iinfo.getType(), linfo.getType());
59
60 af_array res;
61 switch (otype) {
62 case f32: res = clampOp<float>(in, lo, hi, odims); break;
63 case f64: res = clampOp<double>(in, lo, hi, odims); break;
64 case c32: res = clampOp<cfloat>(in, lo, hi, odims); break;
65 case c64: res = clampOp<cdouble>(in, lo, hi, odims); break;
66 case s32: res = clampOp<int>(in, lo, hi, odims); break;
67 case u32: res = clampOp<uint>(in, lo, hi, odims); break;
68 case s8: res = clampOp<schar>(in, lo, hi, odims); break;
69 case u8: res = clampOp<uchar>(in, lo, hi, odims); break;
70 case b8: res = clampOp<char>(in, lo, hi, odims); break;
71 case s64: res = clampOp<intl>(in, lo, hi, odims); break;
72 case u64: res = clampOp<uintl>(in, lo, hi, odims); break;
73 case s16: res = clampOp<short>(in, lo, hi, odims); break;
74 case u16: res = clampOp<ushort>(in, lo, hi, odims); break;
75 case f16: res = clampOp<half>(in, lo, hi, odims); break;
76 default: TYPE_ERROR(0, otype);
77 }
78
79 std::swap(*out, res);
80 }
81 CATCHALL;
82 return AF_SUCCESS;
83}

Callers 1

clampFunction · 0.50

Calls 5

getOutDimsFunction · 0.85
implicitFunction · 0.85
swapFunction · 0.85
dimsMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected