Quote:
Originally Posted by TurboPascal7
Range in python3 only creates an iterator which is extremely cheap (both cpu and memory-wise). Also considering that there are no cyclic references, the created iterator (and memoryview objects for that matter) will be collected at the end of the outer loop after every iteration so I'm not sure where that memory consumption reduction would come from.
|
This is very true it's definitely a lot better in python 3 than it is in python 2. To be honest I didn't get around to profiling the optimisations properly, however there should still be some performance benefit with [y,x] over [y][x] as you only have a single lookup call vs 2 + view creation. (Although that's not really the main bottleneck in this case, which is the conversion to and from python ints when doing the calculations).
Quote:
Originally Posted by Limit64
Wouldn't it make sense to use numpy. It has highly optimized and parallelized methods for calculations with matrices. It should make it more readable, too.
|
Yes it would! The way get_read/write_array is written it conforms to
PEP 3118 which means you can use it's output as the input to another function in python that also supports the buffer interface and it won't incur a memorycopy! So a basic numpy filter would start like:
Code:
import numpy as np
import vapoursynth as vs
from scipy import ndimage
c = vs.get_core()
def removegrain_mode19(n, f):
fout = f.copy()
for p in range(fout.format.num_planes):
plane = np.asarray(fout.get_write_array(p))
inplane = np.asarray(f.get_read_array(p))
#Implement filter below using numpy methods
return fout