在 Swift 中使用 Accelerate 框架
Using Accelerate framework in Swift
来自苹果文档
根据文档
func vvlog10f(_ _: UnsafeMutablePointer<Float>,
_ _: UnsafePointer<Float>,
_ _: UnsafePointer<Int32>)
/* y */ /* x */ /* n */
那我做错了什么?
这是我的代码
import Accelerate
var input:[Float] = [0.124,0.5,0.0056]
var output:[Float] = []
var i:Int32 = Int32(input.count)
vvlog10f(&output,&input,&i)
println("output is \(output)")
输出为[]
示例来自 Apple's Swift Blog:
import Accelerate
let a: [Float] = [1, 2, 3, 4]
let b: [Float] = [0.5, 0.25, 0.125, 0.0625]
var result: [Float] = [0, 0, 0, 0]
vDSP_vadd(a, 1, b, 1, &result, 1, 4)
看来您只需要 & 作为可变指针。
这就是这个例子的最终效果
import Accelerate
var input:[Float] = [0.124,0.5,0.0006]
var output:[Float] = [Float](count: input.count, repeatedValue: 0.0)
var temp:Int32 = Int32(input.count)
var i:[Int32] = [temp]
vvlog10f(&output,input,i)
println("output is \(output)")
来自苹果文档
根据文档
func vvlog10f(_ _: UnsafeMutablePointer<Float>,
_ _: UnsafePointer<Float>,
_ _: UnsafePointer<Int32>)
/* y */ /* x */ /* n */
那我做错了什么?
这是我的代码
import Accelerate
var input:[Float] = [0.124,0.5,0.0056]
var output:[Float] = []
var i:Int32 = Int32(input.count)
vvlog10f(&output,&input,&i)
println("output is \(output)")
输出为[]
示例来自 Apple's Swift Blog:
import Accelerate
let a: [Float] = [1, 2, 3, 4]
let b: [Float] = [0.5, 0.25, 0.125, 0.0625]
var result: [Float] = [0, 0, 0, 0]
vDSP_vadd(a, 1, b, 1, &result, 1, 4)
看来您只需要 & 作为可变指针。
这就是这个例子的最终效果
import Accelerate
var input:[Float] = [0.124,0.5,0.0006]
var output:[Float] = [Float](count: input.count, repeatedValue: 0.0)
var temp:Int32 = Int32(input.count)
var i:[Int32] = [temp]
vvlog10f(&output,input,i)
println("output is \(output)")