以下是代码:
import pycuda.autoinit
import pycuda.gpuarray as gpuarray
import pycuda.driver as drv
import numpy as np
import scikits.cuda.linalg as culinalg
import scikits.cuda.misc as cumisc
culinalg.init()
ag = gpuarray.to_gpu(np.random.rand(1000,1000))
bg = gpuarray.to_gpu(np.zeros((1000,1000))
bg[:,:] = ag
我收到以下错误:
TypeError: 'GPUArray' object does not support item assignment
那么有什么方法可以将矩阵分配给pycuda / scikits.cuda中的另一个现有矩阵?
答案 0 :(得分:1)
好的,这不是一种优雅的方式,而是一种解决方案:使用pycuda的ElementwiseKernel:
import from pycuda.elementwise import ElementwiseKernel
ele_assign = ElementwiseKernel("double *a,double *b","a[i] = b[i]","ele_assign")
ele_assign(bg,ag)