@@ -21,15 +21,15 @@ func strictSum<T: Real>(_ array: [T]) -> T {
21
21
}
22
22
23
23
func relaxedSum< T: Real > ( _ array: [ T ] ) -> T {
24
- array. reduce ( 0 , T . _relaxedAdd )
24
+ array. reduce ( 0 , Relaxed . sum )
25
25
}
26
26
27
27
func strictSumOfSquares< T: Real > ( _ array: [ T ] ) -> T {
28
28
array. reduce ( 0 ) { $0 + $1* $1 }
29
29
}
30
30
31
31
func relaxedSumOfSquares< T: Real > ( _ array: [ T ] ) -> T {
32
- array. reduce ( 0 ) { . _relaxedAdd ( $0 , . _relaxedMul ( $1, $1 ) ) }
32
+ array. reduce ( 0 ) { Relaxed . multiplyAdd ( $1 , $1, $0 ) }
33
33
}
34
34
35
35
// TODO: not a great harness, but making it better bumps up against the
@@ -61,6 +61,8 @@ final class RelaxedArithmeticTests: XCTestCase {
61
61
}
62
62
63
63
func testRelaxedSumPerformance( ) {
64
+ // Performance of this should be closer to vDSP.sum than to
65
+ // strict sum
64
66
measure { benchmarkReduction ( floatData, relaxedSum) }
65
67
}
66
68
@@ -75,6 +77,8 @@ final class RelaxedArithmeticTests: XCTestCase {
75
77
}
76
78
77
79
func testRelaxedDotPerformance( ) {
80
+ // Performance of this should be closer to vDSP.sumOfSquares than to
81
+ // strict sumOfSquares
78
82
measure { benchmarkReduction ( floatData, relaxedSumOfSquares) }
79
83
}
80
84
@@ -90,13 +94,13 @@ final class RelaxedArithmeticTests: XCTestCase {
90
94
// produce the same result as a normal addition.
91
95
let a = T . random ( in: - 1 ... 1 )
92
96
let b = T . random ( in: - 1 ... 1 )
93
- XCTAssertEqual ( a + b, . _relaxedAdd ( a, b) )
97
+ XCTAssertEqual ( a + b, Relaxed . sum ( a, b) )
94
98
// Same is true for mul.
95
- XCTAssertEqual ( a * b, . _relaxedMul ( a, b) )
99
+ XCTAssertEqual ( a * b, Relaxed . product ( a, b) )
96
100
// add + mul must be either two operations or an FMA:
97
101
let unfused = a + 1.5 * b
98
102
let fused = a. addingProduct ( 1.5 , b)
99
- let relaxed = T . _relaxedAdd ( a , . _relaxedMul ( 1.5 , b) )
103
+ let relaxed = Relaxed . multiplyAdd ( 1.5 , b, a )
100
104
XCTAssert ( relaxed == unfused || relaxed == fused)
101
105
// Summing all values in an array can be associated however we want, but
102
106
// has to satisfy the usual error bound of 0.5 * sum.ulp * numberOfElements.
0 commit comments