Skip to content

Commit 6611f45

Browse files
committed
[vecops] Increase size of long RVec instances in RVec test
For the tests to make sense, some vectors need to be longer than the maximum small vector size. This maximum size is compiler and architecture dependent. For `RVec<int>` on ARM64 with gcc 14, the small vector capacity turns out to be 60, which is larger than the current test vector size of 18. Therefore, the test is refactored to easily adapt the vector size, which is increased to at least 64 or 72. A `static_assert` is also added, to make sure there is an early compilation error if the vectors are not long enough.
1 parent cc9e693 commit 6611f45

File tree

1 file changed

+69
-18
lines changed

1 file changed

+69
-18
lines changed

math/vecops/test/vecops_rvec.cxx

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,15 +1672,37 @@ TEST_P(VecOpsSwap, BothSmallVectors)
16721672

16731673
TEST_P(VecOpsSwap, BothRegularVectors)
16741674
{
1675-
RVec<int> fixed_vreg1{1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3};
1676-
RVec<int> fixed_vreg2{4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6};
1677-
RVec<int> fixed_vreg3{7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7};
1675+
constexpr std::size_t smallVecSize = ROOT::Internal::VecOps::RVecInlineStorageSize<int>::value;
1676+
1677+
constexpr std::size_t nElems = 72;
1678+
static_assert(nElems > smallVecSize,
1679+
"The RVec instances in this test should be larger than the maximum small vector size!");
1680+
1681+
constexpr int nCycle = 3;
1682+
1683+
RVec<int> fixed_vreg1(nElems);
1684+
RVec<int> fixed_vreg2(nElems);
1685+
RVec<int> fixed_vreg3(nElems + 1);
16781686
RVec<int> fixed_vmocksmall{0, 7};
16791687

1680-
RVec<int> vreg1{1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3};
1681-
RVec<int> vreg2{4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6};
1682-
RVec<int> vreg3{7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7};
1683-
RVec<int> vmocksmall{0, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 7, 8, 9, 7, 8, 9};
1688+
RVec<int> vreg1(nElems);
1689+
RVec<int> vreg2(nElems);
1690+
RVec<int> vreg3(nElems + 1);
1691+
RVec<int> vmocksmall(nElems + 1);
1692+
std::cout << vmocksmall[0] << std::endl;
1693+
1694+
for (std::size_t i = 0; i < nElems; ++i) {
1695+
vreg1[i] = (i % nCycle) + 1;
1696+
vreg2[i] = vreg1[i] + nCycle;
1697+
vreg3[i] = vreg2[i] + nCycle;
1698+
fixed_vreg1[i] = vreg1[i];
1699+
fixed_vreg2[i] = vreg2[i];
1700+
fixed_vreg3[i] = vreg3[i];
1701+
vmocksmall[i + 1] = vreg3[i];
1702+
}
1703+
fixed_vreg3[nElems] = fixed_vreg3[0];
1704+
vreg3[nElems] = vreg3[0];
1705+
16841706
vmocksmall.erase(vmocksmall.begin() + 2, vmocksmall.end());
16851707
// vmocksmall is a regular vector of size 2
16861708

@@ -1798,11 +1820,26 @@ TEST_P(VecOpsSwap, BothAdoptingVectors)
17981820
// in cases where ROOT::VecOps::swap produces 1 regular and 1 adopting vector
17991821
TEST_P(VecOpsSwap, SmallRegularVectors)
18001822
{
1823+
constexpr std::size_t smallVecSize = ROOT::Internal::VecOps::RVecInlineStorageSize<int>::value;
1824+
1825+
constexpr std::size_t nElems1 = 64;
1826+
static_assert(nElems1 > smallVecSize,
1827+
"The RVec instances in this test should be larger than the maximum small vector size!");
1828+
1829+
constexpr std::size_t nElems2 = 72;
1830+
static_assert(nElems2 > smallVecSize,
1831+
"The RVec instances in this test should be larger than the maximum small vector size!");
1832+
1833+
constexpr int nCycle = 3;
1834+
18011835
RVec<int> fixed_vsmall{1, 2, 3};
18021836
RVec<int> fixed_vreg1{4, 5, 6};
18031837
RVec<int> fixed_vreg2{7, 8};
18041838
RVec<int> fixed_vreg3{9, 10, 11, 12, 13, 14};
1805-
RVec<int> fixed_vreg4{15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
1839+
RVec<int> fixed_vreg4(nElems1);
1840+
for (std::size_t i = 0; i < nElems1; ++i) {
1841+
fixed_vreg4[i] = i + 15;
1842+
}
18061843

18071844
// need multiple hard copies since after swap of a small and a regular,
18081845
// there is no fixed policy whether 2 regular vectors are produced or 1 small and 1 regular
@@ -1815,19 +1852,33 @@ TEST_P(VecOpsSwap, SmallRegularVectors)
18151852
RVec<int> vsmall7{1, 2, 3};
18161853
RVec<int> vsmall8{1, 2, 3};
18171854

1818-
RVec<int> vreg1{4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6};
1819-
vreg1.erase(vreg1.begin() + 3, vreg1.end()); // regular vector of size 3
1820-
RVec<int> vreg10{4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6};
1855+
RVec<int> vreg1;
1856+
RVec<int> vreg10;
1857+
RVec<int> vreg2{7, 8};
1858+
RVec<int> vreg20{7, 8};
1859+
RVec<int> vreg3{9, 10, 11, 12, 13, 14};
1860+
RVec<int> vreg30{9, 10, 11, 12, 13, 14};
1861+
RVec<int> vreg4(nElems1);
1862+
1863+
for (std::size_t i = 0; i < nElems2; ++i) {
1864+
double val = (i % nCycle) + 4;
1865+
vreg1.push_back(val);
1866+
vreg10.push_back(vreg1.back());
1867+
vreg2.push_back(val);
1868+
vreg20.push_back(vreg2.back());
1869+
vreg3.push_back(val);
1870+
vreg30.push_back(vreg3.back());
1871+
}
1872+
for (std::size_t i = 0; i < nElems1; ++i) {
1873+
vreg4[i] = i + 15;
1874+
}
1875+
1876+
vreg1.erase(vreg1.begin() + 3, vreg1.end()); // regular vector of size 3
18211877
vreg10.erase(vreg10.begin() + 3, vreg10.end()); // regular vector of size 3
1822-
RVec<int> vreg2{7, 8, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6};
1823-
vreg2.erase(vreg2.begin() + 2, vreg2.end()); // regular vector of size 2
1824-
RVec<int> vreg20{7, 8, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6};
1878+
vreg2.erase(vreg2.begin() + 2, vreg2.end()); // regular vector of size 2
18251879
vreg20.erase(vreg20.begin() + 2, vreg20.end()); // regular vector of size 2
1826-
RVec<int> vreg3{9, 10, 11, 12, 13, 14, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6};
1827-
vreg3.erase(vreg3.begin() + 6, vreg3.end()); // regular vector of size 6
1828-
RVec<int> vreg30{9, 10, 11, 12, 13, 14, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6};
1880+
vreg3.erase(vreg3.begin() + 6, vreg3.end()); // regular vector of size 6
18291881
vreg30.erase(vreg30.begin() + 6, vreg30.end()); // regular vector of size 6
1830-
RVec<int> vreg4{15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
18311882
// vreg4 is a regular vector that cannot "fit" to small vector
18321883

18331884
// verify that initially vectors are not small

0 commit comments

Comments
 (0)