Пример #1
0
    def render(self, name, value, attrs=None, choices=()):
        """
        Renders this widget. HTML and JS code blocks all are rendered by this.

        :return: The rendered markup.
        :rtype: :py:obj:`unicode`
        """
        if logger.isEnabledFor(logging.DEBUG):
            t1 = util.timer_start('Select2Mixin.render')

        args = [name, value, attrs]
        if choices:
            args.append(choices)

        s = unicode(super(Select2Mixin, self).render(*args))  # Thanks to @ouhouhsami Issue#1
        if RENDER_SELECT2_STATICS:
            s += self.media.render()
        final_attrs = self.build_attrs(attrs)
        id_ = final_attrs.get('id', None)
        s += self.render_js_code(id_, name, value, attrs, choices)

        if logger.isEnabledFor(logging.DEBUG):
            util.timer_end(t1)
            logger.debug("Generated widget code:-\n%s", s)

        return mark_safe(s)
Пример #2
0
    def render(self, name, value, attrs=None, choices=()):
        """
        Renders this widget. Html and JS code blocks all are rendered by this.

        :return: The rendered markup.
        :rtype: :py:obj:`unicode`
        """
        if logger.isEnabledFor(logging.DEBUG):
            t1 = util.timer_start('Select2Mixin.render')

        args = [name, value, attrs]
        if choices:
            args.append(choices)

        s = unicode(super(Select2Mixin, self).render(*args))  # Thanks to @ouhouhsami Issue#1
        if RENDER_SELECT2_STATICS:
            s += self.media.render()
        final_attrs = self.build_attrs(attrs)
        id_ = final_attrs.get('id', None)
        s += self.render_js_code(id_, name, value, attrs, choices)

        if logger.isEnabledFor(logging.DEBUG):
            util.timer_end(t1)
            logger.debug("Generated widget code:-\n%s", s)

        return mark_safe(s)
def test_dist():
    """Testing function for the dist methods within the calc core module

    Creates two arrays of random nth dimensional vectors and uses the
    calc.dist_batch method to calculate and get the distances between
    all the points"""
    quantity = 1000000
    rand_min = -100
    rand_max = 100
    dim = 3

    print('Quantity: '+str(quantity))
    print('Constructing random vector list...')
    util.timer_start()
    # u_vectors = []
    # v_vectors = []
    u_vectors = calc.doubleArray(quantity * dim)
    v_vectors = calc.doubleArray(quantity * dim)
    for i in range(quantity):
        if i % 1000 == 0:
            util.print_progress_bar(i, quantity)
        # u_vectors.append(util.doubleArray(np.random.random_integers(rand_min, rand_max, (dim,)).astype(dtype=np.float64)))
        # v_vectors.append(util.doubleArray(np.random.random_integers(rand_min, rand_max, (dim,)).astype(dtype=np.float64)))
        u_tmp = np.random.random_integers(rand_min, rand_max, (dim,)).astype(dtype=np.float64)
        v_tmp = np.random.random_integers(rand_min, rand_max, (dim,)).astype(dtype=np.float64)
        for j in range(dim):
            u_vectors[i * dim + j] = u_tmp[j]
            v_vectors[i * dim + j] = v_tmp[j]

    util.timer_stop('Completed random vector list construction', progress_bar=True)

    # for i in range(quantity):
    #     v = calc.dist(u_vectors[i], v_vectors[i], dim)
    print('Vector u[0]: '+str(u_vectors[0])+','+str(u_vectors[1])+','+str(u_vectors[2]))
    print('Vector v[0]: '+str(v_vectors[0])+','+str(v_vectors[1])+','+str(v_vectors[2]))

    util.timer_start()
    batch = calc.dist_batch(u_vectors, v_vectors, dim, quantity * dim)
    batch = calc.doubleArray_frompointer(batch)
    util.timer_stop('M5')

    print('Result: '+str(batch[0]))
    c = a - b
    return np.dot(c, c)**(1 / 2)


def dist5(a, b):
    return calc.dist(doubleArray(a), doubleArray(b), len(a))


rand_min = -100
rand_max = 100
dim = 3

u_vectors = []
v_vectors = []
print('Constructing random vector list...')
timer_start()
for i in range(1000000):
    u_vectors.append(np.random.random_integers(rand_min, rand_max, (dim, )))
    v_vectors.append(np.random.random_integers(rand_min, rand_max, (dim, )))
timer_stop('Completed random vector list construction')

print('sample: u=' + str(u_vectors[0]) + ',v=' + str(v_vectors[0]))

# # M1
# timer_start()
# for n in range(len(u_vectors)):
#     v = dist(u_vectors[n], v_vectors[n])
# timer_stop('M1')
#
# # M2
# timer_start()