MCPcopy
hub / github.com/tensorflow/tfjs / randomNormal_

Function randomNormal_

tfjs-core/src/ops/random_normal.ts:41–55  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

39 * @doc {heading: 'Tensors', subheading: 'Random'}
40 */
41function 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
57export const randomNormal = /* @__PURE__ */ op({randomNormal_});

Callers

nothing calls this directly

Calls 4

nextValueMethod · 0.95
bufferFunction · 0.90
toTensorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…