The Quantum Exact Simulation Toolkit v4.0.0
Loading...
Searching...
No Matches

Testing utilities which generate lists of integers. More...

Typedefs

template<class T >
using CatchGen = Catch::Generators::GeneratorWrapper<T>
 
using listpair = std::tuple<vector<int>,vector<int>>
 
using listtrio = std::tuple<vector<int>,vector<int>,vector<int>>
 

Functions

CatchGen< listpair > disjointsublists (CatchGen< int > &&gen, int sublen1, int sublen2)
 
listpair GENERATE_CTRLS_AND_TARGS (int numQubits, int numCtrls, int numTargs)
 
vector< int > GENERATE_TARGS (int numQubits, int numTargs)
 
vector< int > getComplement (vector< int > listA, vector< int > listB)
 
vector< int > getRange (int endExcl)
 
vector< int > getRange (int start, int endExcl)
 
vector< int > getSublist (vector< int > list, int start, int len)
 
vector< qcomp > getSublist (vector< qcomp > list, int start, int len)
 
CatchGen< vector< int > > sublists (CatchGen< int > &&gen, int sublen)
 

Detailed Description

Testing utilities which generate lists of integers.

Typedef Documentation

◆ CatchGen

template<class T >
using CatchGen = Catch::Generators::GeneratorWrapper<T>

Definition at line 34 of file lists.hpp.

◆ listpair

using listpair = std::tuple<vector<int>,vector<int>>

Definition at line 23 of file lists.hpp.

◆ listtrio

using listtrio = std::tuple<vector<int>,vector<int>,vector<int>>

Definition at line 24 of file lists.hpp.

Function Documentation

◆ GENERATE_CTRLS_AND_TARGS()

listpair GENERATE_CTRLS_AND_TARGS ( int numQubits,
int numCtrls,
int numTargs )

Definition at line 262 of file lists.cpp.

262 {
263 DEMAND( numQubits >= numCtrls + numTargs );
264
265 // impose a limit on the number of {ctrls,targs} to generate (max-int if none set)
266 int numPerms = getNumPermutations(numQubits, numCtrls + numTargs);
267 int maxPerms = TEST_MAX_NUM_QUBIT_PERMUTATIONS;
268 if (maxPerms == 0)
269 maxPerms = std::numeric_limits<int>::max();
270
271 // if all permutations are permitted, determinstically generate each in turn.
272 // note this wastefully generates all orderings of ctrl qubits, despite that
273 // this has no effect on all API operations, but we carefully check anyway!
274 if (numPerms < maxPerms)
275 return GENERATE_COPY( disjointsublists(range(0,numQubits), numCtrls, numTargs) );
276
277 // otherwise generate as many random {ctrls,targs} as permitted
278 GENERATE_COPY( range(0,maxPerms) );
279 return getRandomFixedNumCtrlsTargs(numQubits, numCtrls, numTargs);
280}
const int TEST_MAX_NUM_QUBIT_PERMUTATIONS
Definition macros.hpp:54

◆ GENERATE_TARGS()

vector< int > GENERATE_TARGS ( int numQubits,
int numTargs )

Definition at line 283 of file lists.cpp.

283 {
284 DEMAND( numQubits >= numTargs );
285
286 auto [ctrls, targs] = GENERATE_CTRLS_AND_TARGS(numQubits, 0, numTargs);
287 return targs;
288}

◆ getComplement()

vector< int > getComplement ( vector< int > listA,
vector< int > listB )

Definition at line 92 of file lists.cpp.

92 {
93
94 std::sort(listA.begin(), listA.end());
95 std::sort(listB.begin(), listB.end());
96
97 vector<int> out;
98 std::set_difference(
99 listA.begin(), listA.end(),
100 listB.begin(), listB.end(),
101 std::back_inserter(out));
102
103 return out;
104}

◆ getRange() [1/2]

vector< int > getRange ( int endExcl)

Definition at line 81 of file lists.cpp.

81 {
82 return getRange(0, endExcl);
83}

◆ getRange() [2/2]

vector< int > getRange ( int start,
int endExcl )

Definition at line 69 of file lists.cpp.

69 {
70 DEMAND( endExcl >= start );
71
72 vector<int> out(endExcl - start);
73
74 for (size_t i=0; i<out.size(); i++)
75 out[i] = start + i;
76
77 return out;
78}

◆ getSublist() [1/2]

vector< int > getSublist ( vector< int > list,
int start,
int len )

Definition at line 51 of file lists.cpp.

51 {
52
53 return vector<int>(list.begin() + start, list.begin() + start + len);
54}

◆ getSublist() [2/2]

vector< qcomp > getSublist ( vector< qcomp > list,
int start,
int len )

Definition at line 57 of file lists.cpp.

57 {
58
59 return vector<qcomp>(list.begin() + start, list.begin() + start + len);
60}