MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / gen_nozero

Function gen_nozero

src/opr/test/basic_arith/elemwise.cpp:155–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153
154template <typename ctype, bool stable_sign = false>
155void gen_nozero(HostTensorND& dest) {
156 static RNGxorshf rng{next_rand_seed()};
157 auto ptr = dest.template ptr<ctype>();
158
159 if (DTypeTrait<ctype>::category == DTypeCategory::FLOAT) {
160 for (size_t i = 0, it = dest.shape().total_nr_elems(); i < it; ++i) {
161 auto v = rng() / (rng.max() + 1.0) * 3 - 1.5;
162 bool vsign = v > 0;
163 if (stable_sign) {
164 vsign = i % 2;
165 }
166 v = std::abs(v) + 0.1;
167 ptr[i] = vsign ? v : -v;
168 }
169 } else {
170 for (size_t i = 0, it = dest.shape().total_nr_elems(); i < it; ++i) {
171 ctype v = rng() / (rng.max() + 1.0) * 65536 - 32767, vsat = i % 2 * 2 - 1;
172 ptr[i] = v == 0 ? vsat : v;
173 }
174 }
175}
176
177template <class Trait>
178struct CheckerConfig {

Callers

nothing calls this directly

Calls 4

absFunction · 0.50
total_nr_elemsMethod · 0.45
shapeMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected