swift - “编译器无法在合理的时间内对该表达式进行类型检查”以获得一个简单的公式
问题描述
我有一个看起来相当简单的算术表达式:
let N = 2048
// var c = (0..<N).map{ sin( 2.0 * .pi * Float($0) / (Float(N)/2.0)) }
let sinout = (0..<N * 10).map { x in
sin(2 * .pi * Float(x) / Float(N / 2))
}
但这正在生成:
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
为什么 Swift 编译器无法解析这样一个简单的方程?我们如何编写 Swift 可以实际解析的方程?对于编写和/或线性代数库的人来说,这一定是一个头疼的问题DSP
:您使用什么解决方法或模式?
解决方案
您只需要显式设置地图表达式的返回类型:
map { x -> Float in
推荐阅读
- android - Android Studio 无法导入模块
- wordpress - Docker Compose WordPress 卷显示为空
- c# - 访问链接到主键的第二列外键值
- python-3.x - Python Requets 不返回最后一个重定向 url
- c++ - 图层不绘制另一个
- scheme - 在树中创建一个列表
- angular - Angular 6 升级:debounceTime 不是 Subject 的属性
- c++ - C ++使用迭代器访问向量的指针元素
- javascript - P5JS 声音仅在我离开活动选项卡时播放
- node.js - NodeJS:向 npmrc 添加选项