<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def subsample(self, factor):
 """ Downsample images by an integer factor. Parameters factor : positive int or tuple of positive ints Stride to use in subsampling. If a single int is passed, each dimension of the image will be downsampled by this factor. If a tuple is passed, each dimension will be downsampled by the given factor. """

        value_shape = self.value_shape
        ndims = len(value_shape)
        if not hasattr(factor, '__len__'):
            factor = [factor] * ndims
        factor = [int(sf) for sf in factor]

        if any((sf <= 0 for sf in factor)):
            raise ValueError('All sampling factors must be positive; got ' + str(factor))

        def roundup(a, b):
            return (a + b - 1) // b

        slices = [slice(0, value_shape[i], factor[i]) for i in range(ndims)]
        new_value_shape = tuple([roundup(value_shape[i], factor[i]) for i in range(ndims)])

        return self.map(lambda v: v[slices], value_shape=new_value_shape)