Function setAmps

Source
pub unsafe extern "C" fn setAmps(
    qureg: Qureg,
    startInd: c_longlong,
    reals: *mut f64,
    imags: *mut f64,
    numAmps: c_longlong,
)
Expand description

Overwrites a contiguous subset of the amplitudes in state-vector \p qureg, with those passed in \p reals and \p imags.

Only amplitudes with indices in [\p startInd, \p startInd + \p numAmps] will be changed. The resulting \p qureg may not necessarily be in an L2 normalised state.

In distributed mode, this function assumes the subset \p reals and \p imags exist (at least) on the node containing the ultimately updated elements.\n For example, below is the correct way to modify the full 8 elements of \p qureg when split between 2 nodes.

    Qureg qureg = createQureg(3, env);

    long long int numAmps = 4;
    qreal re[] = {1,2,3,4};
    qreal im[] = {1,2,3,4};
    setAmps(qureg, 0, re, im, numAmps);

    // modify re and im to the next set of elements
    for (int i=0; i<4; i++) {
      re[i] += 4;
      im[i] += 4;
    }
    setAmps(qureg, 4, re, im, numAmps);

\n

@see

  • setDensityAmps()
  • setWeightedQureg()
  • initStateFromAmps()
  • initBlankState()

@ingroup init @param[in,out] qureg the state-vector to modify @param[in] startInd the index of the first amplitude in \p qureg to modify @param[in] reals array of the real components of the new amplitudes @param[in] imags array of the imaginary components of the new amplitudes @param[in] numAmps the length of each of the reals and imags arrays. @throws invalidQuESTInputError()

  • if \p qureg is not a state-vector (i.e. is a density matrix)
  • if \p startInd is outside [0, qureg.numAmpsTotal]
  • if \p numAmps is outside [0, qureg.numAmpsTotal]
  • if \p numAmps + \p startInd >= qureg.numAmpsTotal @author Tyson Jones