create a wrapper for cblas_sgemm in swift

Here's a code snippet that shows how to create a wrapper for cblas_sgemm in Swift:

main.swift
import Accelerate

func matrixMultiply(_ A: [Float], _ B: [Float], m: Int, n: Int, k: Int) -> [Float] {
    let C = [Float](repeatElement(0.0, count: m*n))
    cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
                Int32(m), Int32(n), Int32(k),
                1.0, A, Int32(k), B, Int32(n), 0.0, &C, Int32(n))
    return C
}
342 chars
10 lines

This function takes two matrices A and B as flat arrays of floats, along with their dimensions m, n, and k, and returns their product as a flat array of floats C. The cblas_sgemm call is the core of the function: it performs the matrix multiplication by passing in the matrices, their dimensions, scaling values, and pointers to the output matrix. The CblasRowMajor and CblasNoTrans arguments indicate that the matrices are in row-major order and should not be transposed.

gistlibby LogSnag