Skip to content

Commit

Permalink
fix: pass in RNG to shuffle (#1188)
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal authored Jan 8, 2025
1 parent d2dc63f commit 76dfdb5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/WeightInitializers/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "WeightInitializers"
uuid = "d49dbf32-c5c2-4618-8acc-27bb2598ef2d"
authors = ["Avik Pal <[email protected]> and contributors"]
version = "1.0.4"
version = "1.0.5"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
2 changes: 1 addition & 1 deletion lib/WeightInitializers/src/WeightInitializers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module WeightInitializers
using ArgCheck: @argcheck
using GPUArraysCore: @allowscalar
using LinearAlgebra: LinearAlgebra, Diagonal, qr
using Random: Random, AbstractRNG, shuffle
using Random: Random, AbstractRNG
using SpecialFunctions: SpecialFunctions, erfinv # TODO: Move to Ext in v2.0
using Statistics: Statistics, std

Expand Down
14 changes: 13 additions & 1 deletion lib/WeightInitializers/src/initializers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,19 @@ function sparse_init(rng::AbstractRNG, ::Type{T}, dims::Integer...;
sparse_array .*= T(std)
fill!(view(sparse_array, 1:num_zeros, :), zero(T))

return @allowscalar mapslices(shuffle, sparse_array; dims=1)
if applicable(Random.rng_native_52, rng)
@inbounds for i in axes(sparse_array, 2)
@allowscalar Random.shuffle!(rng, view(sparse_array, :, i))
end
else
@warn "`rng` is not supported by `Random.shuffle!`. Ignoring the `rng` for \
shuffle." maxlog=1
@inbounds for i in axes(sparse_array, 2)
@allowscalar Random.shuffle!(view(sparse_array, :, i))
end
end

return sparse_array
end

"""
Expand Down

2 comments on commit 76dfdb5

@avik-pal
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register subdir=lib/WeightInitializers

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/122557

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a WeightInitializers-v1.0.5 -m "<description of version>" 76dfdb58f36976e323cafd0e3f99e96fa76af1c9
git push origin WeightInitializers-v1.0.5

Please sign in to comment.