The Quantum Exact Simulation Toolkit v4.2.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 263 of file lists.cpp.

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

◆ GENERATE_TARGS()

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

Definition at line 284 of file lists.cpp.

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

◆ getComplement()

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

Definition at line 93 of file lists.cpp.

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

◆ getRange() [1/2]

vector< int > getRange ( int endExcl)

Definition at line 82 of file lists.cpp.

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

◆ getRange() [2/2]

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

Definition at line 70 of file lists.cpp.

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

◆ getSublist() [1/2]

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

Definition at line 52 of file lists.cpp.

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

◆ getSublist() [2/2]

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

Definition at line 58 of file lists.cpp.

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