Skip to content

Commit 740cc50

Browse files
committed
Some cleanups to relaxed arithmetic.
1 parent f6b0aeb commit 740cc50

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ let package = Package(
5353
.target(
5454
name: "_NumericsShims",
5555
exclude: excludedFilenames,
56-
linkerSettings: [.linkedLibrary("m", .when(platforms: [.linux, .android]))]
56+
linkerSettings: [
57+
.linkedLibrary("m", .when(platforms: [.linux, .android]))
58+
]
5759
),
5860

5961
.target(

Tests/RealTests/RelaxedArithmeticTests.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ func strictSum<T: Real>(_ array: [T]) -> T {
2121
}
2222

2323
func relaxedSum<T: Real>(_ array: [T]) -> T {
24-
array.reduce(0, T._relaxedAdd)
24+
array.reduce(0, Relaxed.sum)
2525
}
2626

2727
func strictSumOfSquares<T: Real>(_ array: [T]) -> T {
2828
array.reduce(0) { $0 + $1*$1 }
2929
}
3030

3131
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) }
3333
}
3434

3535
// TODO: not a great harness, but making it better bumps up against the
@@ -61,6 +61,8 @@ final class RelaxedArithmeticTests: XCTestCase {
6161
}
6262

6363
func testRelaxedSumPerformance() {
64+
// Performance of this should be closer to vDSP.sum than to
65+
// strict sum
6466
measure { benchmarkReduction(floatData, relaxedSum) }
6567
}
6668

@@ -75,6 +77,8 @@ final class RelaxedArithmeticTests: XCTestCase {
7577
}
7678

7779
func testRelaxedDotPerformance() {
80+
// Performance of this should be closer to vDSP.sumOfSquares than to
81+
// strict sumOfSquares
7882
measure { benchmarkReduction(floatData, relaxedSumOfSquares) }
7983
}
8084

@@ -90,13 +94,13 @@ final class RelaxedArithmeticTests: XCTestCase {
9094
// produce the same result as a normal addition.
9195
let a = T.random(in: -1 ... 1)
9296
let b = T.random(in: -1 ... 1)
93-
XCTAssertEqual(a + b, ._relaxedAdd(a, b))
97+
XCTAssertEqual(a + b, Relaxed.sum(a, b))
9498
// Same is true for mul.
95-
XCTAssertEqual(a * b, ._relaxedMul(a, b))
99+
XCTAssertEqual(a * b, Relaxed.product(a, b))
96100
// add + mul must be either two operations or an FMA:
97101
let unfused = a + 1.5 * b
98102
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)
100104
XCTAssert(relaxed == unfused || relaxed == fused)
101105
// Summing all values in an array can be associated however we want, but
102106
// has to satisfy the usual error bound of 0.5 * sum.ulp * numberOfElements.

0 commit comments

Comments
 (0)