首页 > 解决方案 > “编译器无法在合理的时间内对该表达式进行类型检查”以获得一个简单的公式

问题描述

我有一个看起来相当简单的算术表达式:

       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:您使用什么解决方法或模式?

标签: swiftcompiler-errors

解决方案


您只需要显式设置地图表达式的返回类型:

map { x -> Float in

推荐阅读