| 101 | |
| 102 | template<typename ScalarType, bool IsScalarTrueOutput> |
| 103 | af_err selectScalar(af_array* out, const af_array cond, const af_array e, |
| 104 | const ScalarType c) { |
| 105 | try { |
| 106 | const ArrayInfo& einfo = getInfo(e); |
| 107 | const ArrayInfo& cinfo = getInfo(cond); |
| 108 | |
| 109 | ARG_ASSERT(1, cinfo.getType() == b8); |
| 110 | |
| 111 | dim4 edims = einfo.dims(); |
| 112 | dim4 cond_dims = cinfo.dims(); |
| 113 | dim4 odims(1); |
| 114 | |
| 115 | for (int i = 0; i < 4; i++) { |
| 116 | DIM_ASSERT(1, cond_dims[i] == edims[i] || cond_dims[i] == 1 || |
| 117 | edims[i] == 1); |
| 118 | odims[i] = std::max(cond_dims[i], edims[i]); |
| 119 | } |
| 120 | |
| 121 | af_array res; |
| 122 | |
| 123 | switch (einfo.getType()) { |
| 124 | case f16: |
| 125 | res = select_scalar<half, ScalarType, IsScalarTrueOutput>( |
| 126 | cond, e, c, odims); |
| 127 | break; |
| 128 | case f32: |
| 129 | res = select_scalar<float, ScalarType, IsScalarTrueOutput>( |
| 130 | cond, e, c, odims); |
| 131 | break; |
| 132 | case f64: |
| 133 | res = select_scalar<double, ScalarType, IsScalarTrueOutput>( |
| 134 | cond, e, c, odims); |
| 135 | break; |
| 136 | case c32: |
| 137 | res = select_scalar<cfloat, ScalarType, IsScalarTrueOutput>( |
| 138 | cond, e, c, odims); |
| 139 | break; |
| 140 | case c64: |
| 141 | res = select_scalar<cdouble, ScalarType, IsScalarTrueOutput>( |
| 142 | cond, e, c, odims); |
| 143 | break; |
| 144 | case s32: |
| 145 | res = select_scalar<int, ScalarType, IsScalarTrueOutput>( |
| 146 | cond, e, c, odims); |
| 147 | break; |
| 148 | case u32: |
| 149 | res = select_scalar<uint, ScalarType, IsScalarTrueOutput>( |
| 150 | cond, e, c, odims); |
| 151 | break; |
| 152 | case s16: |
| 153 | res = select_scalar<short, ScalarType, IsScalarTrueOutput>( |
| 154 | cond, e, c, odims); |
| 155 | break; |
| 156 | case u16: |
| 157 | res = select_scalar<ushort, ScalarType, IsScalarTrueOutput>( |
| 158 | cond, e, c, odims); |
| 159 | break; |
| 160 | case s64: |
no test coverage detected