| 60 | /* ========================== HostTensorGenerator ========================== */ |
| 61 | template <typename dtype> |
| 62 | std::shared_ptr<HostTensorND> HostTensorGenerator<dtype, RandomDistribution::GAUSSIAN>:: |
| 63 | operator()(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 | |
| 82 | template <typename dtype> |
| 83 | std::shared_ptr<HostTensorND> HostTensorGenerator<dtype, RandomDistribution::UNIFORM>:: |
nothing calls this directly
no test coverage detected