| 81 | |
| 82 | template<af_op_t op, typename To> |
| 83 | static af_err reduce_type(af_array *out, const af_array in, const int dim) { |
| 84 | try { |
| 85 | ARG_ASSERT(2, dim >= 0); |
| 86 | ARG_ASSERT(2, dim < 4); |
| 87 | |
| 88 | const ArrayInfo &in_info = getInfo(in); |
| 89 | |
| 90 | if (dim >= static_cast<int>(in_info.ndims())) { |
| 91 | *out = retain(in); |
| 92 | return AF_SUCCESS; |
| 93 | } |
| 94 | |
| 95 | af_dtype type = in_info.getType(); |
| 96 | af_array res; |
| 97 | |
| 98 | switch (type) { |
| 99 | case f32: res = reduce<op, float, To>(in, dim); break; |
| 100 | case f64: res = reduce<op, double, To>(in, dim); break; |
| 101 | case c32: res = reduce<op, cfloat, To>(in, dim); break; |
| 102 | case c64: res = reduce<op, cdouble, To>(in, dim); break; |
| 103 | case u32: res = reduce<op, uint, To>(in, dim); break; |
| 104 | case s32: res = reduce<op, int, To>(in, dim); break; |
| 105 | case u64: res = reduce<op, uintl, To>(in, dim); break; |
| 106 | case s64: res = reduce<op, intl, To>(in, dim); break; |
| 107 | case u16: res = reduce<op, ushort, To>(in, dim); break; |
| 108 | case s16: res = reduce<op, short, To>(in, dim); break; |
| 109 | case b8: res = reduce<op, char, To>(in, dim); break; |
| 110 | case u8: res = reduce<op, uchar, To>(in, dim); break; |
| 111 | case s8: res = reduce<op, schar, To>(in, dim); break; |
| 112 | case f16: res = reduce<op, half, To>(in, dim); break; |
| 113 | default: TYPE_ERROR(1, type); |
| 114 | } |
| 115 | |
| 116 | std::swap(*out, res); |
| 117 | } |
| 118 | CATCHALL; |
| 119 | |
| 120 | return AF_SUCCESS; |
| 121 | } |
| 122 | |
| 123 | template<af_op_t op, typename To> |
| 124 | static af_err reduce_by_key_type(af_array *keys_out, af_array *vals_out, |