Generates a single-precision vector by extrapolation and interpolation.


func vDSP_vgenp(_ __A: UnsafePointer<Float>, _ __IA: vDSP_Stride, _ __B: UnsafePointer<Float>, _ __IB: vDSP_Stride, _ __C: UnsafeMutablePointer<Float>, _ __IC: vDSP_Stride, _ __N: vDSP_Length, _ __M: vDSP_Length)



Single-precision real input vector.


Address stride for A.


Single-precision real input vector.


Address stride for B.


Single-precision real output vector.


Address stride for C.


Element count for C.


Element count for A and B.


The vDSP_vgenp(_:_:_:_:_:_:_:_:) and vDSP_vgenpD(_:_:_:_:_:_:_:_:) functions populate a vector, by linearly interpolating between a series of index-value pairs. The following pseudocode describes the calculation:

for (n = 0; n < N; ++n)
    If n <= B[0],  then C[n] = A[0].
    If B[M-1] < n, then C[n] = A[M-1].
        Let m be such that B[m] < n <= B[m+1].
        C[n] = A[m] + (A[m+1]-A[m]) * (n-B[m]) / (B[m+1]-B[m]).

The input vector A provides a series of values, and the input vector B provides the indices in the output vector, C, for the corresponding value in A. The indices must increase monotonically.

For example, the following code defines five value-index pairs:

let a: [Float] = [0, 0.25, 1, 0.25, 0]
let b: [Float] = [0, 256, 512, 768, 1024]

Passing these arrays to vDSP_vgenp(_:_:_:_:_:_:_:_:) populates the output array, c, with the linearly interpolated values:

let n = vDSP_Length(1024)

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

let stride = vDSP_Stride(1)

vDSP_vgenp(a, stride,
           b, stride,
           &c, stride,

The following illustrates the values of c:

Visualization of generated vector.

See Also

Vector Generation by Extrapolation and Interpolation