| 665 | |
| 666 | |
| 667 | extern "C" void setDiagMatrFromMultiVarFunc(DiagMatr out, qcomp (*callbackFunc)(qindex*), int* numQubitsPerVar, int numVars, int areSigned) { |
| 668 | validate_matrixFields(out, __func__); |
| 669 | validate_multiVarFuncQubits(out.numQubits, numQubitsPerVar, numVars, __func__); |
| 670 | validate_funcVarSignedFlag(areSigned, __func__); |
| 671 | |
| 672 | vector<qindex> varValues(numVars); |
| 673 | |
| 674 | // set each element of the diagonal in-turn; user's callback might not be thread-safe |
| 675 | for (qindex elemInd=0; elemInd<out.numElems; elemInd++) { |
| 676 | fast_getSubQuregValues(elemInd, numQubitsPerVar, numVars, areSigned, varValues.data()); |
| 677 | |
| 678 | // call user function, and update only the CPU elems |
| 679 | out.cpuElems[elemInd] = callbackFunc(varValues.data()); |
| 680 | } |
| 681 | |
| 682 | // overwrite all GPU elems |
| 683 | syncDiagMatr(out); |
| 684 | } |
| 685 | |
| 686 | |
| 687 | extern "C" void setFullStateDiagMatrFromMultiVarFunc(FullStateDiagMatr out, qcomp (*callbackFunc)(qindex*), int* numQubitsPerVar, int numVars, int areSigned) { |
nothing calls this directly
no test coverage detected