Skip to content

Conversation

@KnutAM
Copy link
Member

@KnutAM KnutAM commented Mar 15, 2024

Following Hooking into the Random API I replaced the Base.rand(Type{<:AbstractTensor}) by Base.rand(rng::AbstractRNG, ::SamplerType{<:AbstractTensor}), which has the advantage of supporting

  • Using a different generators, e.g. rand(MersenneTwister(1), Tensor{2,3})
  • Support rand!(::Array{<:AbstractTensor}).
  • Support creating an array of random tensors by e.g. rand(Vec{2}, 2) (However, specific overload is added to get, e.g. Vector{Vec{2,Float64}} in this case instead of Vector{Vec{2}}.)
  • Combinations thereof, e.g. rand(MersenneTwister(2), Vec{2}, 2)

AFAIU the same API doesn't work for randn, so this is kept as is.

Julia 1.6: For some reason, the type for apply_all with f(i) = rand(rng, T) (where T<:Number) is not typestable on julia 1.6, but works at least on 1.8 and later. Old implementation is therefore kept to have fast performance for e.g. rand(Tensor{2,3}), but the new functionality in the list above is slow (but typestable output via typeassert) on julia 1.6.

@codecov
Copy link

codecov bot commented Mar 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.77%. Comparing base (258540f) to head (7b4e1ae).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #216      +/-   ##
==========================================
- Coverage   96.91%   96.77%   -0.14%     
==========================================
  Files          17       17              
  Lines        1490     1521      +31     
==========================================
+ Hits         1444     1472      +28     
- Misses         46       49       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@KnutAM
Copy link
Member Author

KnutAM commented Mar 16, 2024

Ready for review @fredrikekre or @KristofferC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants