Function

vDSP_vtabiD(_:_:_:_:_:_:_:_:_:)

Generates a double-precision vector, by interpolating values from a lookup table.

Declaration

func vDSP_vtabiD(_ __A: UnsafePointer<Double>, _ __IA: vDSP_Stride, _ __S1: UnsafePointer<Double>, _ __S2: UnsafePointer<Double>, _ __C: UnsafePointer<Double>, _ __M: vDSP_Length, _ __D: UnsafeMutablePointer<Double>, _ __ID: vDSP_Stride, _ __N: vDSP_Length)

Parameters

__A

Single-precision real input vector.

__IA

Address stride for A.

__S1

Pointer to double-precision real input scalar: scale factor.

__S2

Pointer to double-precision real input scalar: base offset.

__C

Double-precision real input vector: lookup table.

__M

Lookup table size.

__D

Double-precision real output vector.

__ID

Stride for D

__N

The number of elements to write to D.

Discussion

The vDSP_vtabi(_:_:_:_:_:_:_:_:_:) and vDSP_vtabiD(_:_:_:_:_:_:_:_:_:) functions populate a vector, using values from the lookup table, C, based on the offsets from vector A. The functions use linear interpolation to compute output values when an offset isn’t an integer. The following code describes the calculation:

for (n = 0; n < N; ++n)
{
    p = S1[0] * A[n] + S2[0];
    if (p < 0)
        D[n] = C[0];
    else if (p < M-1)
    {
        q = trunc(p);
        r = p-q;
        D[n] = (1-r)*C[q] + r*C[q+1];
    }
    else
        D[n] = C[M-1];
}

Parameters S1 and S2 map the anticipated range of input values to the range of the lookup table and are typically assigned values such that:

floor(S1 * minimum input value + S2) = 0
floor(S1 * maximum input value + S2) = M-1

The following code shows a simple lookup table that contains a series of nine square numbers:

let c: [Float] = [1, 4, 9,
                  16, 25, 36,
                  49, 64, 81]

In this example, vDSP_vgen(_:_:_:_:_:) populates the offsets array. The offsets are a ramp of 1024 values, starting at zero and ending at the lookup table’s count minus one:

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

var a =  [Float](repeating: 0,
                 count: Int(n))
var base: Float = 0
var end = Float(c.count) - 1
vDSP_vgen(&base,
          &end,
          &a,
          stride,
          n)

Calling vDSP_vtabi(_:_:_:_:_:_:_:_:_:) populates the output array, d, with the interpolated values from the lookup table:

var s1: Float = 1.0             // Scale.
var s2: Float = 0.0             // Offset.

let m = vDSP_Length(c.count)    // Lookup table size.
var d = [Float](repeating: 0,
                count: Int(n))  // Destination

vDSP_vtabi(a,
           stride,
           &s1,
           &s2,
           c,
           m,
           &d,
           stride,
           n)

The following illustrates the values of d:

Visualization of generated vector.

See Also

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software