gpt4 book ai didi

swift - 将 UnsafeMutablePointer 的实部提取为 Float 并将其存储在数组中

转载 作者:行者123 更新时间:2023-11-28 13:50:51 44 4
gpt4 key购买 nike

我有这个功能

func arrayForPointer<T>(_ pointer: UnsafePointer<T>, count: Int) -> [T] {
let buffer = UnsafeBufferPointer<T>(start: pointer, count: count)
return Array(buffer)
}

和这个电话

let arrayComplex = self.arrayForPointer(&output, count: 4)

我想枚举 arrayComplex并将实部提取到常规数组中,例如

var arrayReal: [Float] = []

for item in arrayComplex {
let myFloat = item.realp \\ get the real part of item
arrayReal.append(myFloat)
}

let myFloat = item.realp  \\ get the real part of item

不正确。

itemUnsafeMutablePointer<Float>

天哪,我该怎么做?

谢谢。

=======================

这是 output

var A = [Float](repeating:0, count:samples/2);
var B = [Float](repeating:0, count:samples/2)
var output = DSPSplitComplex(realp: &A, imagp: &B)

最佳答案

试试这个。

修复你的函数调用:

let arrayComplex = arrayForPointer(output.realp, count: 4)

然后在你的循环中修复这一行:

let myFloat = item  \\ get the real part of item

关于swift - 将 UnsafeMutablePointer 的实部提取为 Float 并将其存储在数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54641266/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com