Contents

BNNSRandomFillNormalFloat(_:_:_:_:)

Fills the specified tensor with random floating-point values mapped to a normal distribution.

Declaration

func BNNSRandomFillNormalFloat(_ generator: BNNSRandomGenerator?, _ desc: UnsafeMutablePointer<BNNSNDArrayDescriptor>, _ mean: Float, _ stddev: Float) -> Int32

Parameters

  • generator:

    The random number generator.

  • desc:

    The descriptor of the destination.

  • mean:

    The mean of the distribution.

  • stddev:

    The standard deviation of the distribution.

Discussion

Use this function to fill an array descriptor with random values mapped to a normal distribution.

If you use the same generator on multiple threads, note that this function serializes the generator through an internal lock. To eliminate this contention, use different generators for each thread.

The following code populates a descriptor with random floating-point values:

let width = 1024
let height = 1024

var descriptor = BNNSNDArrayDescriptor.allocateUninitialized(
    scalarType: Float.self,
    shape: .matrixRowMajor(width,
                           height))

let randomNumberGenerator = BNNSCreateRandomGenerator(
    BNNSRandomGeneratorMethodAES_CTR,
    nil)

BNNSRandomFillNormalFloat(randomNumberGenerator,
                          &descriptor,
                          0,
                          2)

The graph below shows the distribution of values in descriptor.

[Image]

See Also

Random number generation