diff --git a/post/2024-10-07-metal-1.4.md b/post/2024-10-07-metal-1.4.md index 47e3a53..f7612be 100644 --- a/post/2024-10-07-metal-1.4.md +++ b/post/2024-10-07-metal-1.4.md @@ -22,9 +22,37 @@ values can be generated for with `Metal.randn` and `Metal.randn!`, while `Float1 supported by the MPS library and will always fall back to the GPUArrays implementation. The easiest way to use these is to use the Metal convenience functions `Metal.rand[n][!]` as -you would the usual functions from the Random.jl standard library. However, the Random.jl -methods can also be used by providing the appropriate `RNG` either from `MPS.default_rng()` -or `MPS.RNG()` to the standard `Random.rand[n][!]` functions. +you would the usual functions from the Random.jl standard library: + +```julia-repl +julia> a = Metal.rand(Float32, 2) +2-element MtlVector{Float32, Metal.PrivateStorage}: + 0.95755994 + 0.7110207 + +julia> Metal.randn!(a) +2-element MtlVector{Float32, Metal.PrivateStorage}: + 1.7230463 + 0.55636907 +``` + +However, the Random.jl methods can also be used by providing the appropriate `RNG` either +from `MPS.default_rng()` or `MPS.RNG()` to the standard `Random.rand[n][!]` functions: + + +```julia-repl +julia> using Random + +julia> rng = MPS.RNG(); + +julia> Random.rand(rng, 2) +2-element MtlVector{Float32, Metal.PrivateStorage}: + 0.8941469 + 0.67628527 +``` + +Seeding is done by calling `Metal.seed!` for the global RNG, or `Random.seed!` when working +with an explicit `RNG` object. ## Other improvements since the last blog post