def funcFindPrfGpu(idxPrc, vecMdlXpos, vecMdlYpos, vecMdlSd, aryFunc,  <EOL>aryPrfTc, varL2reg, queOut, lgcPrint=True):
<EOL>def funcPlcIn():<EOL><INDENT>"""<STR_LIT>"""<EOL>idxCnt = <NUM_LIT:0><EOL>while True:<EOL><INDENT>aryTmp02 = lstPrfTc[idxCnt]<EOL>dicIn = {objPlcHld01: aryTmp02}<EOL>objSess.run(objEnQ, feed_dict=dicIn)<EOL>idxCnt += <NUM_LIT:1><EOL>if objCoord.should_stop():<EOL><INDENT>break<EOL><DEDENT>elif idxCnt == varNumMdls:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>if lgcPrint:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>varNumX = np.shape(vecMdlXpos)[<NUM_LIT:0>]<EOL>varNumY = np.shape(vecMdlYpos)[<NUM_LIT:0>]<EOL>varNumPrfSizes = np.shape(vecMdlSd)[<NUM_LIT:0>]<EOL>varNumBeta = aryPrfTc.shape[<NUM_LIT:3>]<EOL>aryPrfTc = np.reshape(aryPrfTc,<EOL>((aryPrfTc.shape[<NUM_LIT:0>]<EOL>* aryPrfTc.shape[<NUM_LIT:1>]<EOL>* aryPrfTc.shape[<NUM_LIT:2>]),<EOL>aryPrfTc.shape[<NUM_LIT:3>],<EOL>aryPrfTc.shape[<NUM_LIT:4>]))<EOL>varNumMdlsTtl = aryPrfTc.shape[<NUM_LIT:0>]<EOL>aryPrfTc = aryPrfTc.astype(np.float32)<EOL>vecVarPrfTc = np.var(aryPrfTc, axis=<NUM_LIT:2>)<EOL>varZero32 = np.array(([<NUM_LIT:0.0>])).astype(np.float32)[<NUM_LIT:0>]<EOL>vecLgcVar = np.max(<EOL>np.greater(vecVarPrfTc,<EOL>varZero32),<EOL>axis=<NUM_LIT:1><EOL>)<EOL>aryPrfTc = aryPrfTc[vecLgcVar, :, :]<EOL>aryPrfTc = np.swapaxes(aryPrfTc, <NUM_LIT:1>, <NUM_LIT:2>)<EOL>varSzePrf = np.divide(float(aryPrfTc.nbytes),<EOL><NUM_LIT>)<EOL>if lgcPrint:<EOL><INDENT>print(('<STR_LIT>'<EOL>+ str(np.around(varSzePrf))<EOL>+ '<STR_LIT>'))<EOL><DEDENT>lstPrfTc = [None] * aryPrfTc.shape[<NUM_LIT:0>]<EOL>for idxMdl in range(int(aryPrfTc.shape[<NUM_LIT:0>])):<EOL><INDENT>lstPrfTc[idxMdl] = aryPrfTc[idxMdl, :, :]<EOL><DEDENT>del(aryPrfTc)<EOL>varNumMdls = len(lstPrfTc)<EOL>if lgcPrint:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>varNumVox = aryFunc.shape[<NUM_LIT:0>]<EOL>varNumVol = aryFunc.shape[<NUM_LIT:1>]<EOL>aryFunc = aryFunc.T<EOL>aryFunc = aryFunc.astype(np.float32)<EOL>varSzeMax = <NUM_LIT>  <EOL>varSzeFunc = np.divide(float(aryFunc.nbytes),<EOL><NUM_LIT>)<EOL>if lgcPrint:<EOL><INDENT>print(('<STR_LIT>'<EOL>+ str(np.around(varSzeFunc))<EOL>+ '<STR_LIT>'))<EOL><DEDENT>varNumChnk = int(np.ceil(np.divide(varSzeFunc, varSzeMax)))<EOL>if lgcPrint:<EOL><INDENT>print(('<STR_LIT>'<EOL>+ str(varNumChnk)<EOL>+ '<STR_LIT>'))<EOL><DEDENT>vecIdxChnks = np.linspace(<NUM_LIT:0>,<EOL>varNumVox,<EOL>num=varNumChnk,<EOL>endpoint=False)<EOL>vecIdxChnks = np.hstack((vecIdxChnks, varNumVox))<EOL>lstFunc = [None] * varNumChnk<EOL>for idxChnk in range(<NUM_LIT:0>, varNumChnk):<EOL><INDENT>varChnkStr = int(vecIdxChnks[idxChnk])<EOL>varChnkEnd = int(vecIdxChnks[(idxChnk+<NUM_LIT:1>)])<EOL>lstFunc[idxChnk] = aryFunc[:, varChnkStr:varChnkEnd]<EOL><DEDENT>vecFuncMean = np.mean(aryFunc, axis=<NUM_LIT:0>)<EOL>vecFuncDev = np.subtract(aryFunc, vecFuncMean[None, :])<EOL>vecSsTot = np.sum(np.power(vecFuncDev,<EOL><NUM_LIT>),<EOL>axis=<NUM_LIT:0>)<EOL>del(vecFuncDev)<EOL>del(aryFunc)<EOL>vecResSsMin = np.zeros((varNumVox), dtype=np.float32)<EOL>vecResSsMinIdx = np.zeros((varNumVox), dtype=np.int32)<EOL>aryL2reg = np.multiply(np.eye(varNumBeta),<EOL>varL2reg).astype(np.float32)<EOL>os.environ['<STR_LIT>'] = '<STR_LIT:2>'<EOL>varStsStpSze = <NUM_LIT:20><EOL>vecStatPrf = np.linspace(<NUM_LIT:0>,<EOL>(varNumMdls * varNumChnk),<EOL>num=(varStsStpSze+<NUM_LIT:1>),<EOL>endpoint=True)<EOL>vecStatPrf = np.ceil(vecStatPrf)<EOL>vecStatPrf = vecStatPrf.astype(int)<EOL>vecStatPrc = np.linspace(<NUM_LIT:0>,<EOL><NUM_LIT:100>,<EOL>num=(varStsStpSze+<NUM_LIT:1>),<EOL>endpoint=True)<EOL>vecStatPrc = np.ceil(vecStatPrc)<EOL>vecStatPrc = vecStatPrc.astype(int)<EOL>varCntSts01 = <NUM_LIT:0><EOL>varCntSts02 = <NUM_LIT:0><EOL>if lgcPrint:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>for idxChnk in range(varNumChnk):<EOL><INDENT>if lgcPrint:<EOL><INDENT>print(('<STR_LIT>' + str(idxChnk)))<EOL>print('<STR_LIT>')<EOL>print(lstPrfTc[<NUM_LIT:0>].shape)<EOL><DEDENT>with tf.Graph().as_default(), tf.Session() as objSess:<EOL><INDENT>if lgcPrint:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>varCapQ = <NUM_LIT:10><EOL>varDim01 = lstPrfTc[<NUM_LIT:0>].shape[<NUM_LIT:0>]<EOL>varDim02 = lstPrfTc[<NUM_LIT:0>].shape[<NUM_LIT:1>]<EOL>objQ = tf.FIFOQueue(capacity=varCapQ,<EOL>dtypes=[tf.float32],<EOL>shapes=[(varDim01, varDim02)])<EOL>objSzeQ = objQ.size()<EOL>objPlcHld01 = tf.placeholder(tf.float32,<EOL>shape=[varDim01, varDim02])<EOL>objEnQ = objQ.enqueue([objPlcHld01])<EOL>varNumThrd = <NUM_LIT:1><EOL>objRunQ = tf.train.QueueRunner(objQ, [objEnQ] * varNumThrd)<EOL>tf.train.add_queue_runner(objRunQ)<EOL>objDsng = objQ.dequeue()<EOL>objCoord = tf.train.Coordinator()<EOL>varBuff = <NUM_LIT:10><EOL>objThrd = threading.Thread(target=funcPlcIn)<EOL>objThrd.setDaemon(True)<EOL>objThrd.start()<EOL>varTmpSzeQ = <NUM_LIT:0><EOL>while varTmpSzeQ < varBuff:<EOL><INDENT>varTmpSzeQ = objSess.run(objSzeQ)<EOL><DEDENT>aryTmp01 = np.copy(lstFunc[idxChnk])<EOL>with tf.device('<STR_LIT>'):<EOL><INDENT>objFunc = tf.Variable(aryTmp01)<EOL><DEDENT>with tf.device('<STR_LIT>'):<EOL><INDENT>objL2reg = tf.Variable(aryL2reg)<EOL><DEDENT>if np.greater_equal(varNumVol, varNumBeta):<EOL><INDENT>objMatSlve = tf.reduce_sum(<EOL>tf.squared_difference(<EOL>objFunc,<EOL>tf.matmul(<EOL>objDsng,<EOL>tf.matmul(<EOL>tf.matmul(<EOL>tf.matrix_inverse(<EOL>tf.add(<EOL>tf.matmul(<EOL>objDsng,<EOL>objDsng,<EOL>transpose_a=True,<EOL>transpose_b=False<EOL>),<EOL>objL2reg<EOL>)<EOL>),<EOL>objDsng,<EOL>transpose_a=False,<EOL>transpose_b=True<EOL>),<EOL>objFunc<EOL>)<EOL>),<EOL>),<EOL>axis=<NUM_LIT:0><EOL>)<EOL><DEDENT>else:<EOL><INDENT>objMatSlve = tf.reduce_sum(<EOL>tf.squared_difference(<EOL>objFunc,<EOL>tf.matmul(<EOL>objDsng,<EOL>tf.matmul(<EOL>tf.matmul(<EOL>objDsng,<EOL>tf.matrix_inverse(<EOL>tf.add(<EOL>tf.matmul(<EOL>objDsng,<EOL>objDsng,<EOL>transpose_a=False,<EOL>transpose_b=True<EOL>),<EOL>objL2reg<EOL>)<EOL>),<EOL>transpose_a=True,<EOL>transpose_b=False<EOL>),<EOL>objFunc<EOL>)<EOL>),<EOL>),<EOL>axis=<NUM_LIT:0><EOL>)<EOL><DEDENT>objSess.run(tf.global_variables_initializer())<EOL>objSess.graph.finalize()<EOL>varChnkStr = int(vecIdxChnks[idxChnk])<EOL>varChnkEnd = int(vecIdxChnks[(idxChnk+<NUM_LIT:1>)])<EOL>aryTmpRes = np.zeros((varNumMdls,<EOL>lstFunc[idxChnk].shape[<NUM_LIT:1>]),<EOL>dtype=np.float32)<EOL>for idxMdl in range(varNumMdls):<EOL><INDENT>aryTmpRes[idxMdl, :] = objSess.run(objMatSlve)<EOL>if varCntSts02 == vecStatPrf[varCntSts01]:<EOL><INDENT>varTmpSzeQ = objSess.run(objSzeQ)<EOL>strStsMsg = ('<STR_LIT>'<EOL>+ str(vecStatPrc[varCntSts01])<EOL>+ '<STR_LIT>'<EOL>+ str(varTmpSzeQ))<EOL>if lgcPrint:<EOL><INDENT>print(strStsMsg)<EOL><DEDENT>if varCntSts01 < varStsStpSze:<EOL><INDENT>varCntSts01 = varCntSts01 + int(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>varCntSts02 = varCntSts02 + <NUM_LIT:1><EOL><DEDENT>objCoord.request_stop()<EOL><DEDENT>vecResSsMinIdx[varChnkStr:varChnkEnd] = np.argmin(aryTmpRes, axis=<NUM_LIT:0>)<EOL>vecResSsMin[varChnkStr:varChnkEnd] = np.min(aryTmpRes, axis=<NUM_LIT:0>)<EOL><DEDENT>if lgcPrint:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>aryMdl = np.zeros((varNumMdlsTtl, <NUM_LIT:3>), dtype=np.float32)<EOL>vecMdlXpos = vecMdlXpos.astype(np.float32)<EOL>vecMdlYpos = vecMdlYpos.astype(np.float32)<EOL>vecMdlSd = vecMdlSd.astype(np.float32)<EOL>aryMdl[:, <NUM_LIT:0>] = np.repeat(vecMdlXpos, int(varNumY * varNumPrfSizes))<EOL>aryMdl[:, <NUM_LIT:1>] = np.repeat(<EOL>np.tile(vecMdlYpos,<EOL>varNumX),<EOL>varNumPrfSizes<EOL>)<EOL>aryMdl[:, <NUM_LIT:2>] = np.tile(vecMdlSd, int(varNumX * varNumY))<EOL>aryMdl = aryMdl[vecLgcVar]<EOL>vecBstXpos = aryMdl[:, <NUM_LIT:0>][vecResSsMinIdx]<EOL>vecBstYpos = aryMdl[:, <NUM_LIT:1>][vecResSsMinIdx]<EOL>vecBstSd = aryMdl[:, <NUM_LIT:2>][vecResSsMinIdx]<EOL>vecBstR2 = np.subtract(<NUM_LIT:1.0>,<EOL>np.divide(vecResSsMin,<EOL>vecSsTot)<EOL>)<EOL>lstOut = [idxPrc,<EOL>vecBstXpos,<EOL>vecBstYpos,<EOL>vecBstSd,<EOL>vecBstR2,<EOL>np.zeros((varNumVox, (varNumBeta))).astype(np.float32)]<EOL>queOut.put(lstOut)<EOL>
Find best pRF model for voxel time course.

Parameters
----------
idxPrc : int
    Process ID of the process calling this function (for CPU
    multi-threading). In GPU version, this parameter is 0 (just one thread
    on CPU).
vecMdlXpos : np.array
    1D array with pRF model x positions.
vecMdlYpos : np.array
    1D array with pRF model y positions.
vecMdlSd : np.array
    1D array with pRF model sizes (SD of Gaussian).
aryFunc : np.array
    2D array with functional MRI data, with shape aryFunc[voxel, time].
aryPrfTc : np.array
    Array with pRF model time courses, with shape
    aryPrfTc[x-pos, y-pos, SD, motion-direction, time]
varL2reg : float
    L2 regularisation factor for ridge regression.
queOut : multiprocessing.queues.Queue
    Queue to put the results on.
lgcPrint : boolean
    Whether print statements should be executed.

Returns
-------
lstOut : list
    List containing the following objects:
    idxPrc : int
        Process ID of the process calling this function (for CPU
        multi-threading). In GPU version, this parameter is 0.
    vecBstXpos : np.array
        1D array with best fitting x-position for each voxel, with shape
        vecBstXpos[voxel].
    vecBstYpos : np.array
        1D array with best fitting y-position for each voxel, with shape
        vecBstYpos[voxel].
    vecBstSd : np.array
        1D array with best fitting pRF size for each voxel, with shape
        vecBstSd[voxel].
    vecBstR2 : np.array
        1D array with R2 value of 'winning' pRF model for each voxel, with
        shape vecBstR2[voxel].
    dummy : np.array
        2D array that is supposed to contain the beta values of 'winning'
        pRF models for each voxel, with shape aryBeta[voxel, beta]. AT THE
        MOMENT, CONTAINS EMPTY DUMMY ARRAY (np.zeros).

Notes
-----
Uses a queue that runs in a separate thread to put model time courses on
the computational graph.