| 343 | } |
| 344 | |
| 345 | af_err af_randu(af_array *out, const unsigned ndims, const dim_t *const dims, |
| 346 | const af_dtype type) { |
| 347 | try { |
| 348 | AF_CHECK(af_init()); |
| 349 | af_array result; |
| 350 | |
| 351 | af_random_engine engine; |
| 352 | AF_CHECK(af_get_default_random_engine(&engine)); |
| 353 | RandomEngine *e = getRandomEngine(engine); |
| 354 | dim4 d = verifyDims(ndims, dims); |
| 355 | |
| 356 | switch (type) { |
| 357 | case f32: result = uniformDistribution_<float>(d, e); break; |
| 358 | case c32: result = uniformDistribution_<cfloat>(d, e); break; |
| 359 | case f64: result = uniformDistribution_<double>(d, e); break; |
| 360 | case c64: result = uniformDistribution_<cdouble>(d, e); break; |
| 361 | case s32: result = uniformDistribution_<int>(d, e); break; |
| 362 | case u32: result = uniformDistribution_<uint>(d, e); break; |
| 363 | case s64: result = uniformDistribution_<intl>(d, e); break; |
| 364 | case u64: result = uniformDistribution_<uintl>(d, e); break; |
| 365 | case s16: result = uniformDistribution_<short>(d, e); break; |
| 366 | case u16: result = uniformDistribution_<ushort>(d, e); break; |
| 367 | case s8: result = uniformDistribution_<schar>(d, e); break; |
| 368 | case u8: result = uniformDistribution_<uchar>(d, e); break; |
| 369 | case b8: result = uniformDistribution_<char>(d, e); break; |
| 370 | case f16: result = uniformDistribution_<half>(d, e); break; |
| 371 | default: TYPE_ERROR(3, type); |
| 372 | } |
| 373 | std::swap(*out, result); |
| 374 | } |
| 375 | CATCHALL |
| 376 | return AF_SUCCESS; |
| 377 | } |
| 378 | |
| 379 | af_err af_randn(af_array *out, const unsigned ndims, const dim_t *const dims, |
| 380 | const af_dtype type) { |