Skip to content

Commit 3204b8a

Browse files
committed
fix type instability
1 parent 5e06e4e commit 3204b8a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/multivariate/stereographic.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ function AbstractMCMC.setparams!!(
1919
end
2020

2121
function rand_uniform_sphere_orthogonal_subspace(
22-
rng::Random.AbstractRNG, subspace_vector::AbstractVector
23-
)
22+
rng::Random.AbstractRNG, subspace_vector::AbstractVector{T}
23+
) where {T<:Real}
2424
z = subspace_vector
2525
d = length(subspace_vector)
26-
v = randn(rng, d)
26+
v = randn(rng, T, d)
2727
v_proj = dot(z, v) / sum(abs2, z) * z
2828
v_orth = v - v_proj
2929
return v_orth / norm(v_orth)
@@ -34,9 +34,9 @@ function stereographic_projection(z::AbstractVector)
3434
return z[1:d] ./ (1 - z[d + 1])
3535
end
3636

37-
function stereographic_inverse_projection(x::AbstractVector)
37+
function stereographic_inverse_projection(x::AbstractVector{T}) where {T<:Real}
3838
d = length(x)
39-
z = zeros(d + 1)
39+
z = zeros(T, d + 1)
4040
x_norm2 = sum(abs2, x)
4141
z[1:d] = 2 * x / (x_norm2 + 1)
4242
z[d + 1] = (x_norm2 - 1) / (x_norm2 + 1)
@@ -79,7 +79,7 @@ function AbstractMCMC.step(
7979
ℓp_sphere = logdensity_sphere(ℓp, x)
8080
ℓw = ℓp_sphere - Random.randexp(rng, eltype(x))
8181

82-
θ = convert(eltype(x), 2π)*rand(rng)
82+
θ = convert(eltype(x), 2π) * rand(rng)
8383
θ_max = θ
8484
θ_min = θ - convert(eltype(x), 2π)
8585

@@ -107,7 +107,7 @@ function AbstractMCMC.step(
107107
θ_max = θ
108108
end
109109

110-
θ = (θ_max - θ_min)*rand(rng)
110+
θ = (θ_max - θ_min) * rand(rng)
111111
end
112112
t = Transition(x, ℓp, (num_proposals=props,))
113113
return t, t

0 commit comments

Comments
 (0)