Skip to content

Commit

Permalink
Add snippet and explain seeding.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Oct 7, 2024
1 parent 217e5e1 commit b6f0741
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions post/2024-10-07-metal-1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b6f0741

Please sign in to comment.