Contents

vDSP_vgen

Generates a single-precision vector that contains monotonically incrementing or decrementing values within a range.

Declaration

extern void vDSP_vgen(const float *__A, const float *__B, float *__C, vDSP_Stride __IC, vDSP_Length __N);

Parameters

  • __A:

    The start value of the ramp.

  • __B:

    The end value of the ramp.

  • __C:

    The output vector.

  • __IC:

    The distance between the elements in the output vector.

  • __N:

    The number of elements that the function processes.

Mentioned in

Discussion

Use this function to generate and return a vector populated with ramped values.

The following code generates a ramped vector with values in the range 0 ... 7:

    let n = 8
    let stride = 1
    
    var start: Float = 0
    var end: Float = 7
    
    let ramp = [Float](unsafeUninitializedCapacity: n) {
        buffer, initializedCount in
        
        vDSP_vgen(&start,
                   &end,
                   buffer.baseAddress!,
                   stride,
                   vDSP_Length(n))
        
        initializedCount = n
    }
    
    // Prints "[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]".
    print(ramp)

See Also

Vector generation with ramps using a range