Skip to main content
added 18 characters in body
Source Link
AlexV
  • 7.3k
  • 2
  • 24
  • 47

I working on optimizing some code for speed in a python module. I have pinned down the bottleneck and is a code snippet which calculates 3 np.ndarraythree np.ndarrays. Namely the following code:

xh = np.multiply(K_Rinv[0, 0], x )
xh += np.multiply(K_Rinv[0, 1],  y) 
xh += np.multiply(K_Rinv[0, 2],  h)
yh = np.multiply(K_Rinv[1, 0],  x) 
yh += np.multiply(K_Rinv[1, 1],  y) 
yh += np.multiply(K_Rinv[1, 2],  h)
q = np.multiply(K_Rinv[2, 0],  x) 
q += np.multiply(K_Rinv[2, 1],  y) 
q += np.multiply(K_Rinv[2, 2],  h)

where xx,y y and hh are np.ndarraynp.ndarrays with shape (4206,5749 5749) and K_RinvK_Rinv is a np.ndarraynp.ndarray witch shape (3,3 3). This code snippet is called multiple times and takes more than 50% of the time of the whole code. Is there a way to speed this up ? Or is it just as it is and can't be speed up.

Every idea and critismcriticism is welcome. Thanks

I working on optimizing some code for speed in a python module. I have pinned down the bottleneck and is a code snippet which calculates 3 np.ndarray. Namely the following code:

xh = np.multiply(K_Rinv[0, 0], x )
xh += np.multiply(K_Rinv[0, 1],  y) 
xh += np.multiply(K_Rinv[0, 2],  h)
yh = np.multiply(K_Rinv[1, 0],  x) 
yh += np.multiply(K_Rinv[1, 1],  y) 
yh += np.multiply(K_Rinv[1, 2],  h)
q = np.multiply(K_Rinv[2, 0],  x) 
q += np.multiply(K_Rinv[2, 1],  y) 
q += np.multiply(K_Rinv[2, 2],  h)

where x,y and h are np.ndarray with shape (4206,5749) and K_Rinv is a np.ndarray witch shape (3,3). This code snippet is called multiple times and takes more than 50% of the time of the whole code. Is there a way to speed this up ? Or is it just as it is and can't be speed up.

Every idea and critism is welcome. Thanks

I working on optimizing some code for speed in a python module. I have pinned down the bottleneck and is a code snippet which calculates three np.ndarrays. Namely the following code:

xh = np.multiply(K_Rinv[0, 0], x )
xh += np.multiply(K_Rinv[0, 1],  y) 
xh += np.multiply(K_Rinv[0, 2],  h)
yh = np.multiply(K_Rinv[1, 0],  x) 
yh += np.multiply(K_Rinv[1, 1],  y) 
yh += np.multiply(K_Rinv[1, 2],  h)
q = np.multiply(K_Rinv[2, 0],  x) 
q += np.multiply(K_Rinv[2, 1],  y) 
q += np.multiply(K_Rinv[2, 2],  h)

where x, y and h are np.ndarrays with shape (4206, 5749) and K_Rinv is a np.ndarray witch shape (3, 3). This code snippet is called multiple times and takes more than 50% of the time of the whole code. Is there a way to speed this up ? Or is it just as it is and can't be speed up.

Every idea and criticism is welcome.

Source Link
niodo
  • 19
  • 1

Optimization fo code snippet including multiple np.multipy statements

I working on optimizing some code for speed in a python module. I have pinned down the bottleneck and is a code snippet which calculates 3 np.ndarray. Namely the following code:

xh = np.multiply(K_Rinv[0, 0], x )
xh += np.multiply(K_Rinv[0, 1],  y) 
xh += np.multiply(K_Rinv[0, 2],  h)
yh = np.multiply(K_Rinv[1, 0],  x) 
yh += np.multiply(K_Rinv[1, 1],  y) 
yh += np.multiply(K_Rinv[1, 2],  h)
q = np.multiply(K_Rinv[2, 0],  x) 
q += np.multiply(K_Rinv[2, 1],  y) 
q += np.multiply(K_Rinv[2, 2],  h)

where x,y and h are np.ndarray with shape (4206,5749) and K_Rinv is a np.ndarray witch shape (3,3). This code snippet is called multiple times and takes more than 50% of the time of the whole code. Is there a way to speed this up ? Or is it just as it is and can't be speed up.

Every idea and critism is welcome. Thanks