n2s = calculate_gradient_contribution(offsets_2, gi2s, grad3)
    n3s = calculate_gradient_contribution(offsets_3, gi3s, grad3)
    return 23.0 * (n0s + n1s + n2s + n3s)


if __name__ == "__main__":
    theano.config.mode = 'FAST_RUN'
    theano.config.floatX = 'float32'
    theano.config.openmp = True
    theano.config.openmp_elemwise_minsize = 2000
    # theano.config.compute_test_value = 'warn'
    perm = T.vector('perm', dtype='int32')
    # perm.tag.test_value = np_perm
    grad3 = T.matrix('grad3', dtype='float32')
    # grad3.tag.test_value = np_grad3
    vertex_table = T.tensor4('vertex_table', dtype='int32')
    # vertex_table.tag.test_value = np_vertex_table
    vl = T.matrix('vl', dtype='float32')
    # vl.tag.test_value = np.array([[0.5, 0.1, 1.7], [1.7732, 0.1461, 1.7]], dtype=np.float32)
    output = matrix_noise3d(vl, perm, grad3, vertex_table)
    simplex_noise = theano.function([vl, perm, grad3, vertex_table], output)
    print("Compiled")
    shape = (512, 512)
    phases = 5
    scaling = 200.0
    input_vectors = get_input_vectors(shape, phases, scaling)
    start_time = time()
    raw_noise = simplex_noise(input_vectors, np_perm, np_grad3, np_vertex_table)
    print("The calculation took " + str(time() - start_time) + " seconds.")
    show(raw_noise, phases, shape)
예제 #2
0
        perm[skewed_v_and[0] + perm[skewed_v_and[1] + perm[skewed_v_and[2]]]] %
        12, perm[skewed_v_and[0] + vertices[0][0] +
                 perm[skewed_v_and[1] + vertices[0][1] +
                      perm[skewed_v_and[2] + vertices[0][2]]]] % 12,
        perm[skewed_v_and[0] + vertices[1][0] +
             perm[skewed_v_and[1] + vertices[1][1] +
                  perm[skewed_v_and[2] + vertices[1][2]]]] % 12,
        perm[skewed_v_and[0] + 1 +
             perm[skewed_v_and[1] + 1 + perm[skewed_v_and[2] + 1]]] % 12
    ])
    n = np.zeros(4, dtype=np.float)
    for i in range(4):
        t = 0.5 + np.sum(-1 * offsets[i]**2)
        if t >= 0:
            t *= t
            n[i] = t**2 * np.dot(grad3[gi[i]], offsets[i])
    return 23.0 * np.sum(n)


if __name__ == "__main__":
    shape = (512, 512)
    phases = 5
    scaling = 200.0
    input_vectors = get_input_vectors(shape, phases, scaling)
    raw_noise = np.empty(input_vectors.shape[0], dtype=np.float32)
    start_time = time()
    for i in range(0, input_vectors.shape[0]):
        raw_noise[i] = np_noise3d(input_vectors[i])
    print("The calculation took " + str(time() - start_time) + " seconds.")
    show(raw_noise, phases, shape)
예제 #3
0
    theano.config.openmp_elemwise_minsize = 2000
    # theano.config.compute_test_value = 'warn'
    perm = T.vector('perm', dtype='int32')
    # perm.tag.test_value = np_perm
    grad3 = T.matrix('grad3', dtype='float32')
    # grad3.tag.test_value = np_grad3
    vertex_table = T.tensor4('vertex_table', dtype='int32')
    # vertex_table.tag.test_value = np_vertex_table
    v_shape = T.vector('shape', dtype='int32')
    # v_shape.tag.test_value = shape
    v_phases = T.constant(phases, name='phases', dtype='int32')
    # v_phases.tag.test_value = phases
    v_scaling = T.constant(scaling, name='scaling', dtype='float32')
    # v_scaling.tag.test_value = scaling
    v_offset = T.vector(name='offset', dtype='float32')
    # v_offset.tag.test_value = offset
    vl = get_input_vectors(v_shape, v_phases, v_scaling, v_offset)
    v_noise = matrix_noise3d(vl, perm, grad3, vertex_table)
    v_image_data = calculate_image(v_noise, v_phases, v_shape)
    simplex_noise = theano.function([v_shape, v_offset, perm, grad3, vertex_table], v_image_data)
    print("Compiled")
    num_steps_burn_in = 10
    num_steps_benchmark = 20
    for i in range(num_steps_burn_in):
        image_data = simplex_noise(shape, offset, np_perm, np_grad3, np_vertex_table)
    start_time = time()
    for i in range(num_steps_benchmark):
        image_data = simplex_noise(shape, offset, np_perm, np_grad3, np_vertex_table)
    print("The calculation took %.4f seconds." % ((time() - start_time) / num_steps_benchmark))
    show(image_data)
    grad3 = T.matrix('grad3', dtype='float32')
    # grad3.tag.test_value = np_grad3
    vertex_table = T.tensor4('vertex_table', dtype='int32')
    # vertex_table.tag.test_value = np_vertex_table
    v_shape = T.vector('shape', dtype='int32')
    # v_shape.tag.test_value = shape
    v_phases = T.constant(phases, name='phases', dtype='int32')
    # v_phases.tag.test_value = phases
    v_scaling = T.constant(scaling, name='scaling', dtype='float32')
    # v_scaling.tag.test_value = scaling
    v_offset = T.vector(name='offset', dtype='float32')
    # v_offset.tag.test_value = offset
    vl = get_input_vectors(v_shape, v_phases, v_scaling, v_offset)
    v_noise = matrix_noise3d(vl, perm, grad3, vertex_table)
    v_image_data = calculate_image(v_noise, v_phases, v_shape)
    simplex_noise = theano.function(
        [v_shape, v_offset, perm, grad3, vertex_table], v_image_data)
    print("Compiled")
    num_steps_burn_in = 10
    num_steps_benchmark = 20
    for i in range(num_steps_burn_in):
        image_data = simplex_noise(shape, offset, np_perm, np_grad3,
                                   np_vertex_table)
    start_time = time()
    for i in range(num_steps_benchmark):
        image_data = simplex_noise(shape, offset, np_perm, np_grad3,
                                   np_vertex_table)
    print("The calculation took %.4f seconds." %
          ((time() - start_time) / num_steps_benchmark))
    show(image_data)
예제 #5
0
    offset = (0.0, 0.0, 1.7)
    v_shape = tf.Variable([512, 512], name='shape')
    v_phases = tf.Variable(5, name='phases')
    v_scaling = tf.Variable(200.0, name='scaling')
    v_offset = tf.Variable([0.0, 0.0, 1.7], name='offset')
    v_input_vectors = get_input_vectors(v_shape, v_phases, v_scaling, v_offset)
    perm = tf.Variable(np_perm, name='perm')
    grad3 = tf.Variable(np_grad3, name='grad3')
    num_steps_burn_in = 10
    num_steps_benchmark = 20
    vertex_table = tf.Variable(np_vertex_table, name='vertex_table')
    raw_noise = noise3d(v_input_vectors, perm, grad3, vertex_table,
                        shape[0] * shape[1] * phases)
    raw_image_data = calculate_image(raw_noise, phases, v_shape)
    init = tf.initialize_all_variables()
    input_vectors = get_input_vectors(shape, phases, scaling, offset)
    noise = noise3d(input_vectors, np_perm, np_grad3, np_vertex_table,
                    shape[0] * shape[1] * phases)
    image_data = calculate_image(noise, phases, shape)
    sess = tf.Session()
    sess.run(init)
    for i in range(num_steps_burn_in):
        raw_img = sess.run(image_data)
    start_time = time()
    for i in range(num_steps_benchmark):
        raw_img = sess.run(image_data)
    print("The calculation took %.4f seconds." %
          ((time() - start_time) / num_steps_benchmark))
    # writer = tf.train.SummaryWriter("tf-logs/", sess.graph)  # write logs for TensorBoard
    show(raw_img.astype(np.uint8))
    shape = (512, 512)
    phases = 10
    scaling = 200.0
    offset = (0.0, 0.0, 1.7)
    v_shape = tf.Variable([512, 512], name='shape')
    v_phases = tf.Variable(5, name='phases')
    v_scaling = tf.Variable(200.0, name='scaling')
    v_offset = tf.Variable([0.0, 0.0, 1.7], name='offset')
    v_input_vectors = get_input_vectors(v_shape, v_phases, v_scaling, v_offset)
    perm = tf.Variable(np_perm, name='perm')
    grad3 = tf.Variable(np_grad3, name='grad3')
    num_steps_burn_in = 10
    num_steps_benchmark = 20
    vertex_table = tf.Variable(np_vertex_table, name='vertex_table')
    raw_noise = noise3d(v_input_vectors, perm, grad3, vertex_table, shape[0] * shape[1] * phases)
    raw_image_data = calculate_image(raw_noise, phases, v_shape)
    init = tf.initialize_all_variables()
    input_vectors = get_input_vectors(shape, phases, scaling, offset)
    noise = noise3d(input_vectors, np_perm, np_grad3, np_vertex_table, shape[0] * shape[1] * phases)
    image_data = calculate_image(noise, phases, shape)
    sess = tf.Session()
    sess.run(init)
    for i in range(num_steps_burn_in):
        raw_img = sess.run(image_data)
    start_time = time()
    for i in range(num_steps_benchmark):
        raw_img = sess.run(image_data)
    print("The calculation took %.4f seconds." % ((time() - start_time) / num_steps_benchmark))
    # writer = tf.train.SummaryWriter("tf-logs/", sess.graph)  # write logs for TensorBoard
    show(raw_img.astype(np.uint8))