Skip to content

Commit

Permalink
TensorFlowTests: adjust a few cases of type conversion (tensorflow#1148)
Browse files Browse the repository at this point in the history
When building the tests with SPM, these would fail to build due to type
differences (i.e. expecting `Tensor<Float>` or `Float` instead of
`Double`).  Explicitly convert the types.
  • Loading branch information
compnerd authored Dec 15, 2020
1 parent 5296951 commit 798dab8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Tests/TensorFlowTests/LayerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6846,7 +6846,7 @@ final class LayerTests: XCTestCase {
let epsilon: Float = 0.001
let bnLayer = BatchNorm<Float>(featureCount: 5, axis: 1, epsilon: epsilon)
// Test inference before any training.
assertEqual(bnLayer.inferring(from: x), x / TensorFlow.sqrt(1 + epsilon), accuracy: 1e-5)
assertEqual(bnLayer.inferring(from: x), x / TensorFlow.sqrt(Tensor<Float>(1 + epsilon)), accuracy: 1e-5)
// Perform one training step, updating the running mean and variance.
Context.local.learningPhase = .training
_ = bnLayer(x) // This line is important and cannot be removed.
Expand Down
4 changes: 2 additions & 2 deletions Tests/TensorFlowTests/OperatorTests/MathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ final class MathOperatorTests: XCTestCase {
}

func testIsInfinite() {
let x = Tensor<Float>([1, 2, 3, 4, log(0.0)])
let x = Tensor<Float>([1, 2, 3, 4, Float(log(0.0))])
let y = x.isInfinite
XCTAssertEqual(y, Tensor([false, false, false, false, true]))
}

func testIsNaN() {
let x = Tensor<Float>([1, 2, 3, 4, log(-5.0)])
let x = Tensor<Float>([1, 2, 3, 4, Float(log(-5.0))])
let y = x.isNaN
XCTAssertEqual(y, Tensor([false, false, false, false, true]))
}
Expand Down

0 comments on commit 798dab8

Please sign in to comment.