Swift - Convolution with Accelerate Framework -


i'm trying 1d convolution accelerate framework.

i can make work seems goes wrong after few experiments.

here code:

import accelerate  var n = 10000 var m = 10 var convn = n + m - 1  var xf = [float](count:n, repeatedvalue:0.0) var yf = [float](count:m, repeatedvalue:0.0)  in 0..<n {     xf[i] = float(i+1) } in 0..<m {     yf[i] = float(i+1) }  var outputf = [float](count:convn, repeatedvalue:0.0)  // padding 0 xf = [float](count:convn-n, repeatedvalue:0.0) + xf  var ptr_xf = unsafepointer<float>(xf) var ptr_yf = unsafepointer<float>(yf).advancedby(yf.count-1)  vdsp_conv(ptr_xf, 1, ptr_yf, -1, &outputf, 1, vdsp_length(convn), vdsp_length(m)) print("[float]: \(outputf)") 

i compile , run different n , m.

then check result result python package numpy.

sometime looks great sometime give me weird result like:

(n=6, m=3)

correct: [1.0, 4.0, 10.0, 16.0, 22.0, 28.0, 27.0, 18.0]

result get: [1.0, 4.0, 10.0, 16.0, 22.0, 28.0, 2.23692e+08, 4.47384e+08]

do miss here? can not figure out i've done wrong.

does have swift version ? using v 3.0.2 , following code works me.

import accelerate  var n = 6 var m = 3  var convn = n + m - 1  var xf = [float](repeating:0.0, count:n) var yf = [float](repeating:0.0, count:m)  in 0..<n {     xf[i] = float(i+1) } in 0..<m {     yf[i] = float(i+1) }  var outputf = [float](repeating:0.0, count:convn)  // padding 0 xf = [float](repeating:0.0, count:convn-n) + xf  var ptr_xf = unsafepointer<float>(xf) var ptr_yf = unsafepointer<float>(yf).advanced(by: yf.count-1)   vdsp_conv(ptr_xf, 1, ptr_yf, -1, &outputf, 1, vdsp_length(convn), vdsp_length(m))  print("[float]: \(outputf)") // [float]: [1.0, 4.0, 10.0, 16.0, 22.0, 28.0, 27.0, 18.0] 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -