Generic Type Method

linearInterpolate(_:_:using:result:)

Calculates the linear interpolation between the supplied single-precision vectors.

Declaration

static func linearInterpolate<T, U, V>(_ vectorA: T, _ vectorB: U, using interpolationConstant: Float, result: inout V) where T : AccelerateBuffer, U : AccelerateBuffer, V : AccelerateMutableBuffer, T.Element == Float, U.Element == Float, V.Element == Float

Discussion

Single-precision and double-precision linearInterpolate(_:_:using:result:) functions calculate a vector that's the elementwise linear interpolation between the two supplied vectors.

For example, the following code creates two arrays, vectorA and vectorB, that contain sine waves:

let n = 1024

let vectorA: [Float] = (0 ... n).map {
    return 2 + sin(Float($0) * 0.07)
}

let vectorB: [Float] = (0 ... n).map {
    return -2 + sin(Float($0) * 0.03)
}

Use linearInterpolate(_:_:using:) with an interpolation constant of 0.5 to generate a new vector that's the average of the two sine waves:

let result = vDSP.linearInterpolate(vectorA, vectorB,
                                    using: 0.5)

The following figure visualizes the two source vectors: the blue lines at the top and bottom, and the interpolation result: the red line in the center:

Graphic illustrating two sine waves and a third vector that's the linear interpolation between them.

See Also

Vector-to-Vector Linear Interpolation

static func linearInterpolate<T, U>(T, U, using: Double) -> [Double]

Returns the linear interpolation between the supplied double-precision vectors.

static func linearInterpolate<T, U>(T, U, using: Float) -> [Float]

Returns the linear interpolation between the supplied single-precision vectors.

static func linearInterpolate<T, U, V>(T, U, using: Double, result: inout V)

Calculates the linear interpolation between the supplied double-precision vectors.

func vDSP_vintb(UnsafePointer<Float>, vDSP_Stride, UnsafePointer<Float>, vDSP_Stride, UnsafePointer<Float>, UnsafeMutablePointer<Float>, vDSP_Stride, vDSP_Length)

Calculates the linear interpolation between the supplied single-precision vectors using the specified stride.