`eltype` of a `ReshapedDistribution` ignores the wrapped distribution
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 92/100
Research direction
Start in src/reshaped.jl by comparing the ReshapedDistribution eltype method with the related partype method mentioned in the issue, then reproduce the Float32 example. Done means reshaped Float32 distributions report the wrapped element type and rand returns Float32 rather than Float64.
Written by the indexing model from the issue text.
Description
reshapeing a Float32 distribution reports — and samples — Float64:
julia> using Distributions, LinearAlgebra
julia> dist = MvNormal(zeros(Float32, 6), Diagonal(ones(Float32, 6)));
julia> eltype(dist), eltype(rand(dist))
(Float32, Float32)
julia> d = reshape(dist, 2, 3);
julia> eltype(d), eltype(rand(d))
(Float64, Float64)
src/reshaped.jl defines
Base.eltype(::Type{ReshapedDistribution{<:Any,<:ValueSupport,D}}) where {D} = eltype(D)
ReshapedDistribution{<:Any,<:ValueSupport,D} is a UnionAll, so Type{...} matches only that type itself and never a concrete ReshapedDistribution{2,Continuous,...}. Dispatch falls through to the generic eltype(::Type{<:Sampleable{F,Continuous}}) = Float64 in src/common.jl, and rand then allocates with that.
Spelling the method with <: fixes both:
Base.eltype(::Type{<:ReshapedDistribution{<:Any,<:ValueSupport,D}}) where {D} = eltype(D)
Found while reviewing #2072, whose new partype method for ReshapedDistribution uses the <: form.
Distributions v0.25.131, Julia 1.12.7.
- Dominant language
- Julia
- Stars
- 1.2k
- Forks
- 447
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaStats/Distributions.jl
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JuliaStats/Distributions.jl#2026 ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 65/100
JuliaStats/Distributions.jl#1173 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JuliaStats/Distributions.jl#1113 · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
JuliaStats/Distributions.jl#609 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
JuliaStats/Distributions.jl#2090 ·
All issues in JuliaStats/Distributions.jl
Similar issues
-
bug 🐞 distributed 🕸️
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
CliMA/Oceananigans.jl#6049 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
JuliaGPU/GPUArrays.jl#780 ·
-
Difficulty 2/5 Half a day Newbie friendliness 76/100
epiforecasts/EpiBranch.jl#304 ·