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

Commit c767471

Browse files
Shashi456saeta
authored andcommitted
Correcting argument order in assertEqual and XCTAssertEqual (#392)
And fixes extra whitespace.
1 parent 4d03f1f commit c767471

File tree

6 files changed

+90
-89
lines changed

6 files changed

+90
-89
lines changed

Tests/TensorFlowTests/LayerTests.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ final class LayerTests: XCTestCase {
373373

374374
let weightBatched = Tensor<Float>(shape: [2, 2, 3], scalars: (0..<12).map(Float.init))
375375
let biasBatched = Tensor<Float>([[1.0, 2.0, 3.0]])
376-
let layerBatched = Dense<Float>(weight: weightBatched,
377-
bias: biasBatched,
376+
let layerBatched = Dense<Float>(weight: weightBatched,
377+
bias: biasBatched,
378378
activation: identity)
379379
let inputBatched = Tensor<Float>(shape: [2, 2], scalars: (0..<4).map(Float.init))
380380
let outputBatched = layerBatched.inferring(from: inputBatched)
@@ -420,7 +420,7 @@ final class LayerTests: XCTestCase {
420420
let expected = Tensor<Float>([[0.0], [0.7615942], [0.9640276], [0.9950547], [0.9993292]])
421421
XCTAssertEqual(output, expected)
422422
}
423-
423+
424424
func testBatchNorm() {
425425
let x = Tensor<Float>([
426426
[ -1.0474433, -0.11914538, -0.08634827, 0.15446888, 1.0572497],
@@ -474,7 +474,7 @@ final class LayerTests: XCTestCase {
474474
accuracy: 1e-5)
475475
}
476476
}
477-
477+
478478
func testLayerNorm() {
479479
let x = Tensor<Float>([
480480
[ -1.0474433, -0.11914538, -0.08634827, 0.15446888, 1.0572497],
@@ -485,6 +485,7 @@ final class LayerTests: XCTestCase {
485485
let lnLayer = LayerNorm<Float>(featureCount: 5, axis: 1)
486486
let value = lnLayer(x)
487487
let grad = gradient(at: x, lnLayer) { $1($0).squared().sum() }
488+
488489
// Uses the same values as `testBatchNorm()` above because `LayerNorm` with features on axis
489490
// `1` is equivalent to `BatchNorm` with features on axis `0`.
490491
assertEqual(

Tests/TensorFlowTests/LazyTensorTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ final class LazyTensorTests: XCTestCase {
6161
let expectedLiveOps = Set<LazyTensorOperationRef>(
6262
expectedLive.map { LazyTensorOperationRef($0) }
6363
)
64-
XCTAssertEqual(expectedLiveOps, actualLiveOps)
64+
XCTAssertEqual(actualLiveOps, expectedLiveOps)
6565
}
6666

6767
func assertAll(_ expectedAll: [LazyTensorOperation]) {
@@ -72,7 +72,7 @@ final class LazyTensorTests: XCTestCase {
7272
let expectedAllOps = Set<LazyTensorOperationRef>(
7373
expectedAll.map { LazyTensorOperationRef($0) }
7474
)
75-
XCTAssertEqual(expectedAllOps, actualAllOps)
75+
XCTAssertEqual(actualAllOps, expectedAllOps)
7676
}
7777

7878
let op0 = LazyTensorOperation(

Tests/TensorFlowTests/OperatorTests/BasicTests.swift

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ final class BasicOperatorTests: XCTestCase {
289289
XCTAssertEqual(array3D.scalars, Array(stride(from: 40.0, to: 60, by: 1)))
290290
XCTAssertEqual(
291291
array2D.scalars,
292-
Array(stride(from: 20.0, to: 25, by: 1)) +
292+
Array(stride(from: 20.0, to: 25, by: 1)) +
293293
Array(stride(from: 30.0, to: 35, by: 1)))
294294
XCTAssertEqual(array1D.scalars, Array(stride(from: 1.0, to: 5, by: 2)))
295295
}
@@ -310,7 +310,7 @@ final class BasicOperatorTests: XCTestCase {
310310
let array3D = slice3D.array
311311
let array2D = slice2D.array
312312
let array1D = slice1D.array
313-
313+
314314
/// Test shapes
315315
XCTAssertEqual(array3D.shape, [1, 4, 5])
316316
XCTAssertEqual(array2D.shape, [2, 5])
@@ -362,7 +362,7 @@ final class BasicOperatorTests: XCTestCase {
362362
XCTAssertEqual(concatenated.array, ShapedArray(shape: [4, 3], scalars: Array(0..<12)))
363363
XCTAssertEqual(concatenated0.array, ShapedArray(shape: [4, 3], scalars: Array(0..<12)))
364364
XCTAssertEqual(
365-
concatenated1.array,
365+
concatenated1.array,
366366
ShapedArray(shape: [2, 6], scalars: [0, 1, 2, 6, 7, 8, 3, 4, 5, 9, 10, 11]))
367367
}
368368

@@ -457,12 +457,12 @@ final class BasicOperatorTests: XCTestCase {
457457
let z = x.unbroadcasted(like: y)
458458
XCTAssertEqual(z.array, ShapedArray<Float>(repeating: 8, shape: [3, 1, 5]))
459459
}
460-
460+
461461
func testUnbroadcast3x3To1x3() {
462462
func foo(tensor: Tensor<Float>, shape: Tensor<Int32>) -> Tensor<Float> {
463463
tensor.unbroadcasted(toShape: shape)
464464
}
465-
465+
466466
// [3,3] -> [1,3]
467467
let atTensor: Tensor<Float> = [
468468
[1, 2, 3],
@@ -471,26 +471,26 @@ final class BasicOperatorTests: XCTestCase {
471471
let pb: (Tensor<Float>) -> Tensor<Float> = pullback(at: atTensor) { x in
472472
foo(tensor: x, shape: [1, 3])
473473
}
474-
474+
475475
// Same shape as parameter of pullback
476476
var inputTensor: Tensor<Float> = [[1, 2, 3]]
477477
var expected: Tensor<Float> = atTensor
478-
XCTAssertEqual(expected, pb(inputTensor))
478+
XCTAssertEqual(pb(inputTensor), expected)
479479
// Different shape than parameter of pullback
480480
inputTensor = [2]
481481
expected = [
482482
[2, 2, 2],
483483
[2, 2, 2],
484484
[2, 2, 2]]
485-
XCTAssertEqual(expected, pb(inputTensor))
486-
485+
XCTAssertEqual(pb(inputTensor), expected)
486+
487487
// Same shape as tensor we are differentiating at
488488
inputTensor = [
489489
[8, 1, 3],
490490
[8, 1, 3],
491491
[8, 1, 3]]
492492
expected = inputTensor
493-
XCTAssertEqual(expected, pb(inputTensor))
493+
XCTAssertEqual(pb(inputTensor), expected)
494494
}
495495

496496
func testSliceUpdate() {
@@ -518,81 +518,81 @@ final class BasicOperatorTests: XCTestCase {
518518
target .= Tensor(repeating: 1, shape: [1, 3, 1])
519519
XCTAssertEqual(target, Tensor(repeating: 1, shape: [2, 3, 4]))
520520
}
521-
521+
522522
func testBroadcast3x0To3x3() {
523523
func foo(tensor: Tensor<Float>, shape: Tensor<Int32>) -> Tensor<Float> {
524524
tensor.broadcasted(toShape: shape)
525525
}
526-
526+
527527
// [3,] -> [3,3]
528528
let pb: (Tensor<Float>) -> Tensor<Float> = pullback(at: [99, 33, 55]) { x in
529529
foo(tensor: x, shape: [3, 3])
530530
}
531-
531+
532532
// Same shape as parameter of pullback
533533
var inputTensor: Tensor<Float> = [
534534
[1, 2, 3],
535535
[1, 2, 3],
536536
[1, 2, 3]]
537537
var expected: Tensor<Float> = [3, 6, 9]
538-
XCTAssertEqual(expected, pb(inputTensor))
539-
538+
XCTAssertEqual(pb(inputTensor), expected)
539+
540540
// Different shape than parameter of pullback
541541
inputTensor = [
542542
[1, 2, 3],
543543
[1, 2, 3],
544544
[1, 2, 3],
545545
[1, 2, 3]]
546546
expected = [4, 8, 12]
547-
XCTAssertEqual(expected, pb(inputTensor))
548-
547+
XCTAssertEqual(pb(inputTensor), expected)
548+
549549
// Same shape as tensor we are differentiating at
550550
inputTensor = [1, 2, 3]
551551
expected = [1, 2, 3]
552-
XCTAssertEqual(expected, pb(inputTensor))
553-
552+
XCTAssertEqual(pb(inputTensor), expected)
553+
554554
// Extremely padded shape as tensor we are differentiating at
555555
inputTensor = [[[[[[1, 2, 3]]]]]]
556556
expected = [1, 2, 3]
557-
XCTAssertEqual(expected, pb(inputTensor))
557+
XCTAssertEqual(pb(inputTensor), expected)
558558
}
559-
559+
560560
func testBroadcast3x1To3x3() {
561561
func foo(tensor: Tensor<Float>, shape: Tensor<Int32>) -> Tensor<Float> {
562562
tensor.broadcasted(toShape: shape)
563563
}
564-
564+
565565
// [3,1] -> [3x3]
566566
let pb: (Tensor<Float>) -> Tensor<Float> = pullback(at: [[99, 33, 55]]) { x in
567567
foo(tensor: x, shape: [3, 3])
568568
}
569-
569+
570570
// Same shape as parameter of pullback
571571
var inputTensor: Tensor<Float> = [
572572
[1, 2, 3],
573573
[1, 2, 3],
574574
[1, 2, 3]]
575575
var expected: Tensor<Float> = [[3, 6, 9]]
576-
XCTAssertEqual(expected, pb(inputTensor))
577-
576+
XCTAssertEqual(pb(inputTensor), expected)
577+
578578
// Different shape than parameter of pullback
579579
inputTensor = [
580580
[1, 2, 3],
581581
[1, 2, 3],
582582
[1, 2, 3],
583583
[1, 2, 3]]
584584
expected = [[4, 8, 12]]
585-
XCTAssertEqual(expected, pb(inputTensor))
586-
585+
XCTAssertEqual(pb(inputTensor), expected)
586+
587587
// Same shape as tensor we are differentiating at
588588
inputTensor = [[1, 2, 3]]
589589
expected = [[1, 2, 3]]
590-
XCTAssertEqual(expected, pb(inputTensor))
591-
590+
XCTAssertEqual(pb(inputTensor), expected)
591+
592592
// Extremely padded shape of tensor we are differentiating at
593593
inputTensor = [[[[[[1, 2, 3]]]]]]
594594
expected = [[1, 2, 3]]
595-
XCTAssertEqual(expected, pb(inputTensor))
595+
XCTAssertEqual(pb(inputTensor), expected)
596596
}
597597

598598
static var allTests = [

Tests/TensorFlowTests/OperatorTests/MathTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ final class MathOperatorTests: XCTestCase {
8181
let target = Tensor<Double>([1, 2, 3, 4, 5]).sum()
8282
let gradTarget = Tensor<Double>([-0.5, -4.0, -13.5, -32.0, -62.5])
8383
let (value, grad) = valueWithGradient(at: x) { rsqrt($0).sum() }
84-
XCTAssertEqual(target, value)
85-
XCTAssertEqual(gradTarget, grad)
84+
XCTAssertEqual(value, target)
85+
XCTAssertEqual(grad, gradTarget)
8686
}
8787

8888
func testLog1p() {
@@ -463,19 +463,19 @@ final class MathOperatorTests: XCTestCase {
463463
let a = Tensor<Float>(randomNormal: TensorShape(shape))
464464
let (q, r) = a.qrDecomposition()
465465
let aReconstituted = matmul(q,r)
466-
assertEqual(a, aReconstituted, accuracy: 1e-5)
466+
assertEqual(aReconstituted, a, accuracy: 1e-5)
467467

468468
let (qFull, rFull) = a.qrDecomposition(fullMatrices: true)
469469
let aReconstitutedFull = matmul(qFull, rFull)
470-
assertEqual(a, aReconstitutedFull, accuracy: 1e-5)
470+
assertEqual(aReconstitutedFull, a, accuracy: 1e-5)
471471
}
472472
}
473473

474474
func testDiagonalPart() {
475475
// Test on 2-D matrix.
476476
let t1 = Tensor<Float>(shape: [4, 4], scalars: (1...16).map(Float.init))
477477
let target1 = Tensor<Float>([1, 6, 11, 16])
478-
XCTAssertEqual(target1, t1.diagonalPart())
478+
XCTAssertEqual(t1.diagonalPart(), target1)
479479

480480
// Test on 4-D tensor.
481481
let t2 = Tensor<Float>([[[[1.0, 0.0, 0.0, 0.0],
@@ -495,7 +495,7 @@ final class MathOperatorTests: XCTestCase {
495495
[[0.0, 0.0, 0.0, 0.0],
496496
[0.0, 0.0, 0.0, 8.0]]]])
497497
let target2 = Tensor<Float>([[1, 2, 3, 4], [5, 6, 7, 8]])
498-
XCTAssertEqual(target2, t2.diagonalPart())
498+
XCTAssertEqual(t2.diagonalPart(), target2)
499499
}
500500

501501
func testBroadcastedAddGradient() {

0 commit comments

Comments
 (0)