| 159 | } |
| 160 | |
| 161 | af_err af_lookup(af_array* out, const af_array in, const af_array indices, |
| 162 | const unsigned dim) { |
| 163 | try { |
| 164 | const ArrayInfo& idxInfo = getInfo(indices); |
| 165 | |
| 166 | if (idxInfo.ndims() == 0) { |
| 167 | *out = retain(indices); |
| 168 | return AF_SUCCESS; |
| 169 | } |
| 170 | |
| 171 | ARG_ASSERT(3, (dim <= 3)); |
| 172 | ARG_ASSERT(2, idxInfo.isVector() || idxInfo.isScalar()); |
| 173 | |
| 174 | af_dtype idxType = idxInfo.getType(); |
| 175 | |
| 176 | ARG_ASSERT(2, (idxType != c32)); |
| 177 | ARG_ASSERT(2, (idxType != c64)); |
| 178 | ARG_ASSERT(2, (idxType != b8)); |
| 179 | |
| 180 | af_array output = 0; |
| 181 | af_array idx = 0; |
| 182 | |
| 183 | if (!idxInfo.isColumn()) { |
| 184 | // Force a deep copy to flatten the array and handle subarrays of not column vector arrays correctly |
| 185 | AF_CHECK(af_copy_array(&idx, indices)); |
| 186 | } else { |
| 187 | idx = indices; |
| 188 | } |
| 189 | |
| 190 | switch (idxType) { |
| 191 | case f32: output = lookup<float>(in, idx, dim); break; |
| 192 | case f64: output = lookup<double>(in, idx, dim); break; |
| 193 | case s32: output = lookup<int>(in, indices, dim); break; |
| 194 | case u32: output = lookup<unsigned>(in, idx, dim); break; |
| 195 | case s16: output = lookup<short>(in, idx, dim); break; |
| 196 | case u16: output = lookup<ushort>(in, idx, dim); break; |
| 197 | case s64: output = lookup<intl>(in, idx, dim); break; |
| 198 | case u64: output = lookup<uintl>(in, idx, dim); break; |
| 199 | case s8: output = lookup<schar>(in, idx, dim); break; |
| 200 | case u8: output = lookup<uchar>(in, idx, dim); break; |
| 201 | case f16: output = lookup<half>(in, idx, dim); break; |
| 202 | default: TYPE_ERROR(1, idxType); |
| 203 | } |
| 204 | std::swap(*out, output); |
| 205 | |
| 206 | if (idx != indices) { |
| 207 | AF_CHECK(af_release_array(idx)); // Release indices array if a copy has been made |
| 208 | } |
| 209 | } |
| 210 | CATCHALL; |
| 211 | return AF_SUCCESS; |
| 212 | } |
| 213 | |
| 214 | // idxrs parameter to the below static function |
| 215 | // expects 4 values which is handled appropriately |
no test coverage detected