Skip to content

Commit ec21e28

Browse files
authored
[AutoDiff] NFC: Add tests for 'AutoDiffIndexSubset' initializers. (#27556)
* Add tests for 'AutoDiffIndexSubset' initializers. * Unify file headers with #27555.
1 parent 684fc9b commit ec21e28

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

include/swift/AST/AutoDiff.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- AutoDiff.h - Swift Automatic Differentiation ---------------------===//
1+
//===--- AutoDiff.h - Swift Differentiable Programming --------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -11,7 +11,8 @@
1111
//===----------------------------------------------------------------------===//
1212
//
1313
// SWIFT_ENABLE_TENSORFLOW
14-
// This file defines AST support for automatic differentiation.
14+
// This file defines AST support for the experimental differentiable
15+
// programming feature.
1516
//
1617
//===----------------------------------------------------------------------===//
1718

lib/AST/AutoDiff.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- AutoDiff.cpp - Swift Automatic Differentiation -------------------===//
1+
//===--- AutoDiff.cpp - Swift Differentiable Programming ------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//

unittests/AST/AutoDiffIndexSubsetTests.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,50 @@ TEST(AutoDiffIndexSubset, Equality) {
7171
/*indices*/ {}));
7272
}
7373

74+
TEST(AutoDiffIndexSubset, Initializers) {
75+
TestContext ctx;
76+
// Default init.
77+
EXPECT_EQ(AutoDiffIndexSubset::getDefault(ctx.Ctx, /*capacity*/ 5,
78+
/*includeAll*/ true),
79+
AutoDiffIndexSubset::get(ctx.Ctx, /*capacity*/ 5,
80+
/*indices*/ {0, 1, 2, 3, 4}));
81+
EXPECT_EQ(AutoDiffIndexSubset::getDefault(ctx.Ctx, /*capacity*/ 5,
82+
/*includeAll*/ false),
83+
AutoDiffIndexSubset::get(ctx.Ctx, /*capacity*/ 5, /*indices*/ {}));
84+
EXPECT_EQ(AutoDiffIndexSubset::getDefault(ctx.Ctx, /*capacity*/ 0,
85+
/*includeAll*/ true),
86+
AutoDiffIndexSubset::get(ctx.Ctx, /*capacity*/ 0,
87+
/*indices*/ {}));
88+
EXPECT_EQ(AutoDiffIndexSubset::getDefault(ctx.Ctx, /*capacity*/ 0,
89+
/*includeAll*/ false),
90+
AutoDiffIndexSubset::get(ctx.Ctx, /*capacity*/ 0, /*indices*/ {}));
91+
// Bit vector init.
92+
{
93+
llvm::SmallBitVector bitVec(6);
94+
bitVec.set(1, 4);
95+
EXPECT_EQ(AutoDiffIndexSubset::get(ctx.Ctx, bitVec),
96+
AutoDiffIndexSubset::get(ctx.Ctx, /*capacity*/ 6,
97+
/*indices*/ {1, 2, 3}));
98+
}
99+
{
100+
llvm::SmallBitVector bitVec(0);
101+
EXPECT_EQ(AutoDiffIndexSubset::get(ctx.Ctx, bitVec),
102+
AutoDiffIndexSubset::get(ctx.Ctx, /*capacity*/ 0,
103+
/*indices*/ {}));
104+
}
105+
// String init.
106+
EXPECT_EQ(AutoDiffIndexSubset::getFromString(ctx.Ctx, "SSSSS"),
107+
AutoDiffIndexSubset::get(ctx.Ctx, /*capacity*/ 5,
108+
/*indices*/ {0, 1, 2, 3, 4}));
109+
EXPECT_EQ(AutoDiffIndexSubset::getFromString(ctx.Ctx, "UUUUU"),
110+
AutoDiffIndexSubset::get(ctx.Ctx, /*capacity*/ 5, /*indices*/ {}));
111+
EXPECT_EQ(AutoDiffIndexSubset::getFromString(ctx.Ctx, "SUSUS"),
112+
AutoDiffIndexSubset::get(ctx.Ctx, /*capacity*/ 5,
113+
/*indices*/ {0, 2, 4}));
114+
EXPECT_EQ(AutoDiffIndexSubset::getFromString(ctx.Ctx, ""),
115+
AutoDiffIndexSubset::get(ctx.Ctx, /*capacity*/ 0, /*indices*/ {}));
116+
}
117+
74118
TEST(AutoDiffIndexSubset, Bits) {
75119
TestContext ctx;
76120
auto *indices1 = AutoDiffIndexSubset::get(ctx.Ctx, /*capacity*/ 5,

0 commit comments

Comments
 (0)