* Creates a `tf.Tensor` with values sampled from a normal distribution. * * ```js * tf.randomNormal([2, 2]).print(); * ``` * * @param shape An array of integers defining the output tensor shape. * @param mean The mean of the normal distribution. * @param stdDev The standard deviation of the
(
shape: ShapeMap[R], mean = 0, stdDev = 1, dtype?: 'float32'|'int32',
seed?: number)
| 39 | * @doc {heading: 'Tensors', subheading: 'Random'} |
| 40 | */ |
| 41 | function randomNormal_<R extends Rank>( |
| 42 | shape: ShapeMap[R], mean = 0, stdDev = 1, dtype?: 'float32'|'int32', |
| 43 | seed?: number): Tensor<R> { |
| 44 | assertNonNegativeIntegerDimensions(shape); |
| 45 | if (dtype != null && (dtype as DataType) === 'bool') { |
| 46 | throw new Error(`Unsupported data type ${dtype}`); |
| 47 | } |
| 48 | const randGauss = |
| 49 | new MPRandGauss(mean, stdDev, dtype, false /* truncated */, seed); |
| 50 | const res = buffer(shape, dtype); |
| 51 | for (let i = 0; i < res.values.length; i++) { |
| 52 | res.values[i] = randGauss.nextValue(); |
| 53 | } |
| 54 | return res.toTensor(); |
| 55 | } |
| 56 | |
| 57 | export const randomNormal = /* @__PURE__ */ op({randomNormal_}); |
nothing calls this directly
no test coverage detected
searching dependent graphs…