code: def memoize(method):
      cache = method.cache = collections.OrderedDict()
      _get = cache.get
      _popitem = cache.popitem
      @functools.wraps(method)
      def memoizer(instance, x, *args, **kwargs):
          if not _WITH_MEMOIZATION or isinstance(x, u.Quantity):
              return method(instance, x, *args, **kwargs)
          unique_id = tuple(float(yy.value) for yy in instance.parameters.values()) + (x.size, x.min(), x.max())
          key = hash(unique_id)
          result = _get(key)
          if result is not None:
              return result
          else:
              result = method(instance, x, *args, **kwargs)
              cache[key] = result
              if len(cache) > _CACHE_SIZE:
                  [_popitem(False) for i in range(max(_CACHE_SIZE // 2, 1))]
              return result
      memoizer.input_object = method
      return memoizer