Skip to content

Commit a79d9ab

Browse files
authored
[testing] Add a runnable regression test for vector arguments. (#2708)
This test is intended to fail if passing vectors of different lengths stops working correctly. Vectors used as state initializers must be a power of 2 in length. Signed-off-by: Eric Schweitz <[email protected]>
1 parent 50066dd commit a79d9ab

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

targettests/execution/vector-1.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 - 2025 NVIDIA Corporation & Affiliates. *
3+
* All rights reserved. *
4+
* *
5+
* This source code and the accompanying materials are made available under *
6+
* the terms of the Apache License 2.0 which accompanies this distribution. *
7+
******************************************************************************/
8+
9+
// Test for std::vector support
10+
11+
// RUN: nvq++ %cpp_std %s -o %t && %t | FileCheck %s
12+
13+
#include <cstdio>
14+
#include <cudaq.h>
15+
16+
struct vector3 {
17+
bool operator()(std::vector<double> theta) __qpu__ {
18+
return theta.size() == 3;
19+
}
20+
};
21+
22+
struct vector5 {
23+
bool operator()(std::vector<double> theta) __qpu__ {
24+
return theta.size() == 5;
25+
}
26+
};
27+
28+
struct vectorPow2a {
29+
bool operator()(std::vector<double> init) __qpu__ {
30+
cudaq::qvector q(init);
31+
return true;
32+
}
33+
};
34+
35+
struct vectorPow2b {
36+
bool operator()(std::vector<double> init) __qpu__ {
37+
cudaq::qvector q(init);
38+
return true;
39+
}
40+
};
41+
42+
int main() {
43+
bool b = true;
44+
std::vector<double> v = {1.0, 2.0, 3.0};
45+
b &= vector3{}(v);
46+
v.push_back(4.0);
47+
v.push_back(5.0);
48+
b &= vector5{}(v);
49+
v.pop_back();
50+
b &= vectorPow2a{}(v);
51+
std::vector<double> w{v};
52+
v.insert(v.end(), w.begin(), w.end());
53+
w.clear();
54+
b &= vectorPow2b{}(v);
55+
if (b)
56+
printf("success\n");
57+
return b ? 0 : ~0;
58+
}
59+
60+
// CHECK: success

test/AST-Quake/vector.cpp test/AST-Quake/vector-0.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// Test for std::vector support
1010

11-
// RUN: cudaq-quake %cpp_std %s | FileCheck %s
11+
// RUN: cudaq-quake %cpp_std %s | FileCheck %s
1212

1313
#include <cudaq.h>
1414
#include <cudaq/algorithm.h>

0 commit comments

Comments
 (0)