Я столкнулся с проблемой, которую не понимаю при использовании пакета numba python. Ошибка говорит:
TypingError: Invalid use of Function(<built-in function setitem>) with argument(s) of type(s): (array(float64, 3d, C), array(bool, 3d, C), Literal[int](0))
* parameterized
In definition 0:
All templates rejected with literals.
In definition 1:
All templates rejected without literals.
In definition 2:
All templates rejected with literals.
In definition 3:
All templates rejected without literals.
In definition 4:
TypeError: unsupported array index type array(bool, 3d, C) in [array(bool, 3d, C)]
raised from C:\Users\sw14928\AppData\Local\Continuum\anaconda3\lib\site-packages\numba\typing\arraydecl.py:71
In definition 5:
TypeError: unsupported array index type array(bool, 3d, C) in [array(bool, 3d, C)]
raised from C:\Users\sw14928\AppData\Local\Continuum\anaconda3\lib\site-packages\numba\typing\arraydecl.py:71
In definition 6:
All templates rejected with literals.
In definition 7:
All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
Мой код выглядит так:
@njit
def kaczmarz(finalArray,responseArray):
#KaczResult = np.zeros_like(finalArray)#convolve(sourceOntable, response, method = 'direct', mode='same')
solution = np.zeros_like(finalArray)
#solution = finalArray
#remnants = np.zeros_like(finalArray)
widthFinalArray = finalArray.shape[0]
depthFinalArray = finalArray.shape[1]
widthRes = responseArray.shape[0]
depthRes = responseArray.shape[1]
xRad = int(widthRes/ 2)
yRad = int(depthRes/ 2)
#usefulResponseIndicies = response>0
rawValues = widthFinalArray * depthFinalArray * finalArray.shape[2]
damping = 0.01
for i in range(5000):
print(i)
update = np.zeros_like(solution)
count = 0
for x in range(finalArray.shape[0]):
for y in range(finalArray.shape[1]):
#randomPoint = np.random.randint(rawValues)
#coords = np.unravel_index(randomPoint, finalArray.shape)
#x = coords[0]
#y = coords[1]
x = np.random.randint(finalArray.shape[0])
y = np.random.randint(finalArray.shape[1])
#print(x,y,z)
x1 = x-xRad
if x1 < 0: x1 = 0
if x1 > widthFinalArray: x1 = widthFinalArray
x2 = xRad+x
if x2 < 0: x2 = 0
if x2 > widthFinalArray: x2 = widthFinalArray
x3 = xRad-x
if x3 < 0: x3 = 0
if x3 > widthRes: x3 = widthRes
x4 = xRad-x+widthFinalArray
if x4 < 0: x4 = 0
if x4 > widthRes: x4 = widthRes
y1 = y-yRad
if y1 < 0: y1 = 0
if y1 > depthFinalArray: y1 = depthFinalArray
y2 = yRad+y
if y2 < 0: y2 = 0
if y2 > depthFinalArray: y2 = depthFinalArray
y3 = yRad-y
if y3 < 0: y3 = 0
if y3 > depthRes: y3 = depthRes
y4 = yRad-y+depthFinalArray
if y4 < 0: y4 = 0
if y4 > depthRes: y4 = depthRes
subSection = solution[x1:x2+1, y1:y2,0]
#shape = np.shape(subSection)
#test = np.sum(subSection)
subResponse = responseArray[x3:x4,y3:y4]
KaczResult = np.sum(subResponse * subSection)
remnant = finalArray[x,y,0]-KaczResult
subUpdate = subResponse*remnant
#print(np.max(subResponse))
#print(np.max(subResponse))
update[x1:x2+1, y1:y2,0] += subUpdate
count += 1
solution[solution < 0] = 0
solution += damping*update/count
return solution