Esempio n. 1
0
def merge(q1, q2):
    ''' merge an n dimensional query and an m dimensional query into an (n+m) dimensional query '''
    ans = ndRangeUnion()
    for (lb1, ub1, wgt1) in q1.ranges:
        for (lb2, ub2, wgt2) in q2.ranges:
            ans.addRange(lb1 + lb2, ub1 + ub2, wgt1 * wgt2)
    return ans
Esempio n. 2
0
    def __init__(self,
                 shape_list,
                 domain_shape,
                 size,
                 seed=9001,
                 pretty_name='random range'):
        self.init_params = util.init_params_from_locals(locals())

        self.shape_list = copy.deepcopy(shape_list)
        self.seed = seed
        self.pretty_name = pretty_name
        self._size = size

        prng = numpy.random.RandomState(seed)
        if shape_list == None:
            shapes = randomQueryShapes(domain_shape, prng)
        else:
            prng.shuffle(self.shape_list)
            shapes = itertools.cycle(
                self.shape_list)  # infinite iterable over shapes in shape_list
        queries = []
        for i in range(size):
            lb, ub = placeRandomly(next(shapes), domain_shape,
                                   prng)  # seed must be None or repeats
            queries.append(ndRangeUnion().addRange(lb, ub, 1.0))
        super(RandomRange, self).__init__(queries, domain_shape)
Esempio n. 3
0
 def __init__(self, domain_shape, pretty_name='total'):
     self.pretty_name = pretty_name
     if type(domain_shape) is int:
         domain_shape = (domain_shape, )
     lb = tuple(0 for _ in domain_shape)
     ub = tuple(x - 1 for x in domain_shape)
     q = ndRangeUnion().addRange(lb, ub, 1.0)
     super(self.__class__, self).__init__([q], domain_shape)
Esempio n. 4
0
 def __init__(self, domain_shape, weight=1.0, pretty_name='identity'):
     self.init_params = util.init_params_from_locals(locals())
     self.weight = weight
     self.pretty_name = pretty_name
     if type(domain_shape) is int:
         domain_shape = (domain_shape, )
     indexes = itertools.product(*[list(range(i)) for i in domain_shape
                                   ])  # generate index tuples
     queries = [ndRangeUnion().addRange(i, i, weight) for i in indexes]
     super(self.__class__, self).__init__(queries, domain_shape)
Esempio n. 5
0
    def __init__(self, domain_shape_int, pretty_name='prefix 1D'):
        self.init_params = util.init_params_from_locals(locals())

        self.pretty_name = pretty_name

        queries = [
            ndRangeUnion().add1DRange(0, c, 1.0)
            for c in range(domain_shape_int)
        ]
        super(self.__class__, self).__init__(queries, (domain_shape_int, ))
Esempio n. 6
0
def kronecker(workloads):
    ''' merge a list of low dimensional workloads into a single high dimensional workload '''
    zq = ndRangeUnion().addRange(tuple(), tuple(), 1.0)
    zero = Workload([zq], tuple())
    return reduce(kron, workloads, zero)