Function

vDSP_vgen(_:_:_:_:_:)

Generates a single-precision, tapered-ramped vector.

Declaration

func vDSP_vgen(_ __A: UnsafePointer<Float>, _ __B: UnsafePointer<Float>, _ __C: UnsafeMutablePointer<Float>, _ __IC: vDSP_Stride, _ __N: vDSP_Length)

Parameters

__A

Pointer to single-precision real input scalar: base value.

__B

Pointer to single-precision real input scalar: end value.

__C

Single-precision real output vector.

__IC

Address stride for C.

__N

The number of elements to process.

Discussion

The vDSP_vgenp(_:_:_:_:_:_:_:_:) and vDSP_vgenD(_:_:_:_:_:) functions populate a vector by linearly interpolating between the base and end-value parameters, using the following operation:

 for (n = 0; n < N; ++n)
    C[n] = A[0] + (B[0] - A[0]) * n/(N-1);

For example, the following code fills an array with the ramped values from 0 to 1024:

let n = vDSP_Length(1024)
let stride = vDSP_Stride(1)

var a: Float = 0
var b: Float = 1024

var c = [Float](repeating: 0,
                count: Int(n))

vDSP_vgen(&a,
          &b,
          &c,
          stride,
          n)

The following illustrates the values of c:

Visualization of generated vector.

See Also

Vector Generation with Tapered Ramps

static func ramp(in: ClosedRange<Double>, count: Int) -> [Double]

Returns a double-precision vector that contains monotonically incrementing or decrementing values within a specified range.

static func ramp(in: ClosedRange<Float>, count: Int) -> [Float]

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

static func formRamp<V>(in: ClosedRange<Double>, result: inout V)

Populates a double-precision vector with monotonically incrementing or decrementing values within a specified range.

static func formRamp<V>(in: ClosedRange<Float>, result: inout V)

Populates a single-precision vector with monotonically incrementing or decrementing values within a specified range.