MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / operator()

Method operator()

test/src/helper.cpp:62–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60/* ========================== HostTensorGenerator ========================== */
61template <typename dtype>
62std::shared_ptr<HostTensorND> HostTensorGenerator<dtype, RandomDistribution::GAUSSIAN>::
63operator()(const TensorShape& shape, CompNode cn) {
64 if (!cn.valid())
65 cn = CompNode::load("xpu0");
66 std::shared_ptr<HostTensorND> ret =
67 std::make_shared<HostTensorND>(cn, shape, dtype());
68 auto ptr = ret->ptr<ctype>();
69 auto mean = m_mean, std = m_std;
70 for (size_t i = 0, it = shape.total_nr_elems(); i < it; i += 2) {
71 ctype u1 = ctype((m_rng() + 1.0) / (m_rng.max() + 1.0)),
72 u2 = ctype((m_rng() + 1.0) / (m_rng.max() + 1.0)),
73 r = ctype(std * std::sqrt(-2 * std::log(u1))),
74 theta = ctype(2 * M_PI * u2), z0 = ctype(r * std::cos(theta) + mean),
75 z1 = ctype(r * std::sin(theta) + mean);
76 ptr[i] = z0;
77 ptr[std::min(i + 1, it - 1)] = z1;
78 }
79 return ret;
80}
81
82template <typename dtype>
83std::shared_ptr<HostTensorND> HostTensorGenerator<dtype, RandomDistribution::UNIFORM>::

Callers

nothing calls this directly

Calls 13

loadFunction · 0.50
sqrtFunction · 0.50
logFunction · 0.50
cosFunction · 0.50
sinFunction · 0.50
minFunction · 0.50
BoolClass · 0.50
validMethod · 0.45
total_nr_elemsMethod · 0.45
maxMethod · 0.45
paramMethod · 0.45
dequantizeMethod · 0.45

Tested by

no test coverage detected