MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / cpu_randu

Function cpu_randu

test/arrayfire_test.cpp:1412–1430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1410
1411template<typename T>
1412af::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)
1433INSTANTIATE(float);

Callers

nothing calls this directly

Calls 2

arrayClass · 0.50
elementsMethod · 0.45

Tested by

no test coverage detected