Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Commit 1ca372f

Browse files
authored
Adjusting or adding tolerances on tests. (#1125)
1 parent 2c53dc4 commit 1ca372f

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

Tests/TensorFlowTests/LayerTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ final class LayerTests: XCTestCase {
13771377
let input = Tensor<Float>(ones: [1, 2]) * Tensor<Float>([0.3, 0.7])
13781378
let output = cell(input: input, state: state).state
13791379
let expected = Tensor<Float>([[0.9921227, 0.9999934, 0.9921227, 0.9999934, 0.9921227]])
1380-
XCTAssertEqual(output, expected)
1380+
assertEqual(output, expected, accuracy: 1e-6)
13811381
}
13821382

13831383
func testDense() {
@@ -6769,7 +6769,7 @@ final class LayerTests: XCTestCase {
67696769
let input = Tensor(shape: [5, 1], scalars: (0..<5).map(Float.init))
67706770
let output = tanhLayer.inferring(from: input)
67716771
let expected = Tensor<Float>([[0.0], [0.7615942], [0.9640276], [0.9950547], [0.9993292]])
6772-
XCTAssertEqual(output, expected)
6772+
assertEqual(output, expected, accuracy: 1e-6)
67736773
}
67746774

67756775
func testBatchNorm() {

Tests/TensorFlowTests/LossTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ final class LossTests: XCTestCase {
4040
scalars: [0.1, 0.2, 0.3, 0.4, 0.4, 0.3, 0.2, 0.1])
4141

4242
let loss = meanSquaredError(predicted: predicted, expected: expected)
43-
let expectedLoss: Float = 23.324999
44-
assertEqual(loss, Tensor(expectedLoss), accuracy: 1e-6)
43+
let expectedLoss: Float = 23.325
44+
assertEqual(loss, Tensor(expectedLoss), accuracy: 2e-6)
4545
}
4646

4747
func testMeanSquaredLogarithmicError() {

Tests/TensorFlowTests/OperatorTests/LinearAlgebraTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ final class LinearAlgebraTests: XCTestCase {
136136
matrix = Tensor<Float>(shape: [2, 2, 2, 2], scalars: (0..<16).map(Float.init))
137137
computedDet = det(matrix)
138138
expectedDet = Tensor<Float>([[-2.0, -2.0], [-2.0, -2.0]])
139-
assertEqual(computedDet, expectedDet, accuracy: 1e-5)
139+
assertEqual(computedDet, expectedDet, accuracy: 2e-5)
140140
}
141141

142142
func testSlogdet() {
@@ -151,8 +151,8 @@ final class LinearAlgebraTests: XCTestCase {
151151
expectedSigns = Tensor<Float>([[-1.0, -1.0], [-1.0, -1.0]])
152152
expectedLogs = Tensor<Float>([[0.6931472, 0.6931462], [0.6931462, 0.6931435]])
153153
(computedSigns, computedLogs) = slogdet(input)
154-
XCTAssertEqual(computedSigns, expectedSigns)
155-
XCTAssertEqual(computedLogs, expectedLogs)
154+
assertEqual(computedSigns, expectedSigns, accuracy: 1e-5)
155+
assertEqual(computedLogs, expectedLogs, accuracy: 1e-5)
156156
}
157157

158158
func testLogdet() {

Tests/TensorFlowTests/OperatorTests/MathTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ final class MathOperatorTests: XCTestCase {
226226
let x = Tensor<Float>([-1.0, 2.0, 3.0])
227227
let y = elu(x)
228228
let expectedY = Tensor<Float>([-0.63212055, 2, 3])
229-
XCTAssertEqual(y, expectedY)
229+
assertEqual(y, expectedY, accuracy: 1e-6)
230230
}
231231

232232
func testGelu() {

Tests/TensorFlowTests/TensorAutoDiffTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ final class TensorAutoDiffTests: XCTestCase {
178178
let grad = gradient(at: Tensor<Float>([3.0, 4.0])) { x in
179179
logSoftmax(x).mean().scalarized()
180180
}
181-
XCTAssertEqual(grad, Tensor([0.23105857, -0.2310586]))
181+
assertEqual(grad, Tensor([0.23105857, -0.2310586]), accuracy: 1e-6)
182182
}
183183

184184
func testScalars() {

0 commit comments

Comments
 (0)