| 1410 | |
| 1411 | template<typename T> |
| 1412 | af::array cpu_randu(const af::dim4 dims) { |
| 1413 | typedef typename af::dtype_traits<T>::base_type BT; |
| 1414 | |
| 1415 | bool isTypeCplx = is_same_type<T, af::cfloat>::value || |
| 1416 | is_same_type<T, af::cdouble>::value; |
| 1417 | bool isTypeFloat = is_same_type<BT, float>::value || |
| 1418 | is_same_type<BT, double>::value || |
| 1419 | is_same_type<BT, half_float::half>::value; |
| 1420 | |
| 1421 | size_t elements = (isTypeCplx ? 2 : 1) * dims.elements(); |
| 1422 | |
| 1423 | std::vector<BT> out(elements); |
| 1424 | for (size_t i = 0; i < elements; i++) { |
| 1425 | out[i] = isTypeFloat ? (BT)(rand()) / static_cast<double>(RAND_MAX) |
| 1426 | : rand() % 100; |
| 1427 | } |
| 1428 | |
| 1429 | return af::array(dims, (T *)&out[0]); |
| 1430 | } |
| 1431 | |
| 1432 | #define INSTANTIATE(To) template af::array cpu_randu<To>(const af::dim4 dims) |
| 1433 | INSTANTIATE(float); |