You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
expand rand/randn convenience APIs and align docs/tests. Move randn open-interval helpers into utilities.jl and switch naming of internals. Simplify rand!/randn! wrappers and add convenience constructors for omitted rng, backend, or type, with backend-dependent defaults (Float64 on CPU, Float32 otherwise). Add explicit zero-arg guards so rand()/randn() require at least one dimension. Update rand.md with concise convenience semantics and examples, including type-only no-rng calls, plus doc entries for rand/randn. Expand tests to cover default-type dispatch, CPU fallback routes, typed no-rng overloads, and invalid-signature/kwarg throw behavior while preserving deterministic CounterRNG offset progression.
Copy file name to clipboardExpand all lines: docs/src/api/rand.md
+29-2Lines changed: 29 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,10 @@
3
3
Counter-based random generation for CPU and GPU backends with deterministic stream behavior for
4
4
fixed `seed`, algorithm, and call sequence.
5
5
6
+
Both in-place and allocation forms are supported:
7
+
- Uniform: `AK.rand!`, `AK.rand`
8
+
- Standard normal: `AK.randn!`, `AK.randn`
9
+
6
10
`CounterRNG` carries an internal `offset` (starting at `0`) that advances by `length(v)` on each
7
11
`AK.rand!(rng, v)` call. This means chunked fills are stream-consistent:
8
12
- filling `100` then `100` elements yields the same `200` values as one `200`-element fill.
@@ -16,9 +20,16 @@ Use an explicit `CounterRNG` when reproducibility is required. For
16
20
convenience,
17
21
`AK.rand!(v)` creates a fresh `CounterRNG()` on each call using one auto-seeded
18
22
`Base.rand(UInt64)` draw, so repeated calls produce different outputs unless Random.seed!() is used.
23
+
Likewise, `AK.rand(backend, args...)` creates a fresh auto-seeded `CounterRNG()` on each call.
19
24
20
25
`AK.reset!(rng::AK.CounterRNG)` rewinds `rng.offset` to `0x0`.
21
26
27
+
Allocation convenience:
28
+
- Canonical forms are `AK.rand(rng, backend, T, dims...)` and `AK.randn(rng, backend, T, dims...)`.
29
+
- Defaults are shared: omit `rng` -> fresh `CounterRNG()`; omit `backend` -> CPU backend; omit `T` -> `Float64` on CPU backend and `Float32` otherwise.
30
+
- Common shorthands include `AK.rand(dims...)`, `AK.rand(T, dims...)`, `AK.rand(backend, dims...)`, and the corresponding `AK.randn(...)` variants.
31
+
- For explicit `rng`, both `AK.rand` and `AK.randn` advance `rng.offset` by `prod(dims)`.
32
+
22
33
Custom algorithms:
23
34
- Define an algorithm type `MyAlg <: AK.CounterRNGAlgorithm`.
24
35
- Implement typed `rand_uint` methods:
@@ -39,6 +50,9 @@ Supported element types:
39
50
40
51
`AK.randn!` uses Box-Muller with open-interval uniforms in `(0, 1)` from a branch-free midpoint mapping.
41
52
53
+
`AK.randn!(v)` and `AK.randn(backend, args...)` create a fresh auto-seeded `CounterRNG()` on each
54
+
call, so repeated calls produce different outputs unless `Random.seed!()` is used.
55
+
42
56
The core of the random number generation produces either a `UInt32` or `UInt64` depending on the width of the requested element type.
43
57
That `UInt` is then either:
44
58
- Unsigned integers: returned as-is or truncated if necessary.
@@ -72,6 +86,7 @@ Examples:
72
86
```julia
73
87
import AcceleratedKernels as AK
74
88
using oneAPI
89
+
using ROCArray
75
90
76
91
# Reproducible
77
92
rng = AK.CounterRNG(0x12345678; alg=AK.Philox())
@@ -88,15 +103,27 @@ AK.rand!(rng, v2)
88
103
y =oneArray{Float32}(undef, 1024)
89
104
AK.rand!(y)
90
105
91
-
# Standard normal samples
92
-
z =oneArray{Float32}(undef, 1024)
106
+
# Allocation form
107
+
y_cpu_auto = AK.rand(1024) # defaults to CPU, Vector{Float64}
108
+
y_oneArray = AK.rand(oneAPIBackend(), Float32, 1024) # fresh RNG, allocate and fill oneArray
0 commit comments