Function

vDSP_minvi(_:_:_:_:_:)

Calculates the minimum value and corresponding index in a single-precision vector.

Declaration

func vDSP_minvi(_ __A: UnsafePointer<Float>, _ __IA: vDSP_Stride, _ __C: UnsafeMutablePointer<Float>, _ __I: UnsafeMutablePointer<vDSP_Length>, _ __N: vDSP_Length)

Parameters

__A

Single-precision real input vector.

__I

Stride for A.

__C

Output scalar.

__IC

Output scalar index.

__N

The number of elements to process. If N is zero (0), this function returns -INFINITY in C, and the value in IC is undefined.

Discussion

This function calculates the minimum value and its corresponding index of the first N elements of A and writes the results to C and IC respectively:

A diagram showing the operation of the vDSP_minvi function. There are three rows. The top row represents the input, vector A. The second row represents the minimum value operation. The bottom row represents the output, vector C. The diagram has connecting lines from the input vectors to the operation and from the operation to the output vector indicating the relationships between the input and output.

The index is the actual array index, not the pre-stride index. If vector A contains more than one instance of the minimum value, IC contains the index of the first instance.

The operation is:

*C = INFINITY;
for (n = 0; n < N; ++n)
{
    if (*C > A[n * I])
    {
        *C = A[n * I];
        *IC = n * I;
    }
}

The following code shows an example of using vDSP_minvi(_:_:_:_:_:):

let stride = vDSP_Stride(1)

let a: [Float] = [-1.5, 2.25, 3.6,
                  0.2, -0.1, -4.3]
let n = vDSP_Length(a.count)

var c: Float = .nan
var i: vDSP_Length = 0

vDSP_minvi(a,
           stride,
           &c,
           &i,
           n)

print("min", c,
      "index", i) // Prints "min -4.3 index 5"

See Also

Minimum Calculation

static func minimum<U>(U) -> Double

Returns the minimum element in a double-precision vector.

static func minimum<U>(U) -> Float

Returns the minimum element in a single-precision vector.

static func indexOfMinimum<U>(U) -> (UInt, Double)

Returns the minimum element, and its index, in a double-precision vector.

static func indexOfMinimum<U>(U) -> (UInt, Float)

Returns the minimum element, and its index, in a single-precision vector.

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

Calculates the minimum magnitude in a single-precision vector.

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

Calculates the minimum magnitude and corresponding index in a single-precision vector.

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