code: def chunkify(chunksize):
      
  
      def chunkifier(func):
  
          def wrap(*args):
  
              assert len(args) > 0
              assert all(len(a.flat) == len(args[0].flat) for a in args)
  
              nelements = len(args[0].flat)
              nchunks, remain = divmod(nelements, chunksize)
  
              out = np.ndarray(args[0].shape)
  
              for start in range(0, nelements, chunksize):
                  #print(start)
                  stop = start+chunksize
                  if start+chunksize > nelements:
                      stop = nelements-start
                  iargs = tuple(a.flat[start:stop] for a in args)
                  out.flat[start:stop] = func(*iargs)
              return out
  
          return wrap
  
      return chunkifier
docs: Very stupid "chunk vectorizer" which keeps memory use down.
          This version requires all inputs to have the same number of elements,
          although it shouldn't be that hard to implement simple broadcasting.