Skip to content

Commit 31ff418

Browse files
authored
Make rand!(A::FixedSizeArray) return A instead of its parent (#140)
1 parent 598eb31 commit 31ff418

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## Version [v1.0.1](https://github.com/JuliaArrays/FixedSizeArrays.jl/releases/tag/v1.0.1) - 2025-06-08
6+
7+
### Fixed
8+
9+
* `rand!(A::FixedSizeArray)` now returns `A`, instead of its parent. ([#139](https://github.com/JuliaArrays/FixedSizeArrays.jl/issues/139), [#140](https://github.com/JuliaArrays/FixedSizeArrays.jl/pull/140))
10+
511
## Version [v1.0.0](https://github.com/JuliaArrays/FixedSizeArrays.jl/releases/tag/v1.0.0) - 2025-06-04
612

713
Initial release.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FixedSizeArrays"
22
uuid = "3821ddf9-e5b5-40d5-8e25-6813ab96b5e2"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
authors = ["Mosè Giordano <mose@gnu.org>, Neven Sajko <s@purelymail.com>, Oscar Smith <oscar.smith@juliacomputing.com>, and contributors"]
55

66
[deps]

ext/RandomExt.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@ module RandomExt
33
using Random: Random
44
using FixedSizeArrays: FixedSizeArray
55

6-
Random.rand!(rng::Random.AbstractRNG, A::FixedSizeArray{T,N}, sp::Random.Sampler) where {N,T} =
6+
function Random.rand!(rng::Random.AbstractRNG, A::FixedSizeArray{T,N}, sp::Random.Sampler) where {N,T}
77
Random.rand!(rng, parent(A), sp)
8+
return A
9+
end
810

911
# Methods needed only to resolve ambiguities, we don't care too much about them
10-
Random.rand!(r::Random.MersenneTwister, A::FixedSizeArray{Float64,N}, I::Random.SamplerTrivial{<:Random.FloatInterval{Float64}}) where {N} =
12+
function Random.rand!(r::Random.MersenneTwister, A::FixedSizeArray{Float64,N}, I::Random.SamplerTrivial{<:Random.FloatInterval{Float64}}) where {N}
1113
Random.rand!(r, parent(A), I)
14+
return A
15+
end
16+
1217
if VERSION < v"1.11"
13-
Random.rand!(::Random._GLOBAL_RNG, A::FixedSizeArray{Float64,N}, I::Random.SamplerTrivial{<:Random.FloatInterval{Float64}}) where {N} =
18+
function Random.rand!(::Random._GLOBAL_RNG, A::FixedSizeArray{Float64,N}, I::Random.SamplerTrivial{<:Random.FloatInterval{Float64}}) where {N}
1419
Random.rand!(Random.default_rng(), parent(A), I)
20+
return A
21+
end
1522
end
1623

1724
end # module RandomExt

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,8 @@ end
631631
rng1 = Random.seed!(rng, seed)
632632
Random.rand!(rng1, v)
633633
rng2 = Random.seed!(rng, seed)
634-
Random.rand!(rng2, fv)
634+
# Make sure `rand!` returns `fv` itself.
635+
@test Random.rand!(rng2, fv) === fv
635636
# Make sure rand!(::FixedSizeArrays) generates same stream of
636637
# numbers as rand!(::Memory)
637638
@test v == fv

0 commit comments

Comments
 (0)