travis-ci-com
72 of 72 new or added lines in 5 files covered. (100.0%)
4660 of 5748 relevant lines covered (81.07%)
10782180.32 hits per line
1 |
# Sampler for Uniform Spherical |
|
2 |
|
|
3 |
struct UniformSphericalSampler
|
|
|
n::Int |
8,000,000✔ |
5 |
end |
|
6 |
|
|
7 |
|
|
8 |
function _rand!(rng::AbstractRNG, spl::UniformSphericalSampler, x::AbstractVector) |
4,000,000✔ |
|
n = spl.n |
12,000,000✔ |
10 |
s = 0.0 |
4,000,000✔ |
|
@inbounds for i = 1:(n+1) |
15,600,000✔ |
|
x[i] = xi = randn(rng) |
47,957,570✔ |
|
s += abs2(xi) |
87,600,000✔ |
14 |
end |
|
15 |
|
|
16 |
# normalize x
|
|
|
r = inv(sqrt(s)) |
8,000,000✔ |
|
x .*= r |
12,000,000✔ |
|
return x
|
8,000,000✔ |
20 |
end |
|
21 |
|
|
22 |
|
|
23 |
function _rand!(rng::AbstractRNG, spl::UniformSphericalSampler, x::AbstractMatrix) |
|
|
for j in axes(x, 2) |
× |
|
_rand!(rng, spl, view(x,:,j)) |
× |
26 |
end |
|
|
return x
|
× |
28 |
end |