當前位置: 首頁>>代碼示例>>Python>>正文


Python tensor.dvector方法代碼示例

本文整理匯總了Python中theano.tensor.dvector方法的典型用法代碼示例。如果您正苦於以下問題:Python tensor.dvector方法的具體用法?Python tensor.dvector怎麽用?Python tensor.dvector使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在theano.tensor的用法示例。


在下文中一共展示了tensor.dvector方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: timeit_2vector_theano

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def timeit_2vector_theano(init, nb_element=1e6, nb_repeat=3, nb_call=int(1e2), expr="a**2 + b**2 + 2*a*b"):
    t3 = timeit.Timer("tf(av,bv)",
                      """
import theano
import theano.tensor as T
import numexpr as ne
from theano.tensor import exp
%(init)s
av=a
bv=b
a=T.dvector()
b=T.dvector()
tf= theano.function([a,b],%(expr)s)
"""%locals()
)
    ret=t3.repeat(nb_repeat,nb_call)
    return np.asarray(ret) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:19,代碼來源:gen_graph.py

示例2: test_infer_shape

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_infer_shape(self):
        a = tensor.dvector()
        self._compile_and_check([a], [self.op(a, 16, 0)],
                                [numpy.random.rand(12)],
                               self.op_class)
        a = tensor.dmatrix()
        for var in [self.op(a, 16, 1), self.op(a, None, 1),
                     self.op(a, 16, None), self.op(a, None, None)]:
            self._compile_and_check([a], [var],
                                    [numpy.random.rand(12, 4)],
                                    self.op_class)
        b = tensor.iscalar()
        for var in [self.op(a, 16, b), self.op(a, None, b)]:
            self._compile_and_check([a, b], [var],
                                    [numpy.random.rand(12, 4), 0],
                                    self.op_class) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:18,代碼來源:test_fourier.py

示例3: test_merge_opt_runtime

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_merge_opt_runtime():
    """In the original merge optimization, the following graph took
    like caused the MERGE optimizer to exhibit really bad performance
    (quadratic? exponential?)

    Ironically, there is actually no merging to do in this graph.

    """
    x = T.dvector()
    for i in xrange(50):
        if i:
            r = r + r/10
        else:
            r = x
    t = time.time()
    f = theano.function([x], r, mode='FAST_COMPILE')
    # FAST_RUN does in-place optimizer which requires a lot of
    # toposorting, which is actually pretty slow at the moment.  This
    # test was designed to test MergeOptimizer... so I'm leaving
    # toposort optimizations for a later date.
    dt = time.time() - t

    # it should never take longer than 5 seconds to compile this graph
    assert dt < 5.0, dt 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:26,代碼來源:test_gc.py

示例4: test_broadcast_arguments

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_broadcast_arguments(self):
        random = RandomStreams(utt.fetch_seed())
        low = tensor.dvector()
        high = tensor.dcol()
        out = random.uniform(low=low, high=high)
        assert out.ndim == 2
        f = function([low, high], out)

        rng_seed = numpy.random.RandomState(utt.fetch_seed()).randint(2**30)
        numpy_rng = numpy.random.RandomState(int(rng_seed))
        val0 = f([-5, .5, 0, 1], [[1.]])
        val1 = f([.9], [[1.], [1.1], [1.5]])
        val2 = f([-5, .5, 0, 1], [[1.], [1.1], [1.5]])

        numpy_val0 = numpy_rng.uniform(low=[-5, .5, 0, 1], high=[1.])
        numpy_val1 = numpy_rng.uniform(low=[.9], high=[[1.], [1.1], [1.5]])
        numpy_val2 = numpy_rng.uniform(low=[-5, .5, 0, 1], high=[[1.], [1.1], [1.5]])

        assert numpy.all(val0 == numpy_val0)
        assert numpy.all(val1 == numpy_val1)
        assert numpy.all(val2 == numpy_val2) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:23,代碼來源:test_shared_randomstreams.py

示例5: test_basic_usage

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_basic_usage(self):
        rf = RandomFunction(numpy.random.RandomState.uniform, tensor.dvector)
        assert not rf.inplace
        assert getattr(rf, 'destroy_map', {}) == {}

        rng_R = random_state_type()

        # If calling RandomFunction directly, all args have to be specified,
        # because shape will have to be moved to the end
        post_r, out = rf(rng_R, (4,), 0., 1.)

        assert out.type == tensor.dvector

        f = compile.function([rng_R], out)

        rng_state0 = numpy.random.RandomState(utt.fetch_seed())

        f_0 = f(rng_state0)
        f_1 = f(rng_state0)

        assert numpy.all(f_0 == f_1) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:23,代碼來源:test_raw_random.py

示例6: test_broadcast_arguments

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_broadcast_arguments(self):
        rng_R = random_state_type()
        low = tensor.dvector()
        high = tensor.dcol()
        post_r, out = uniform(rng_R, low=low, high=high)
        assert out.ndim == 2
        f = compile.function([rng_R, low, high], [post_r, out],
                             accept_inplace=True)

        rng_state0 = numpy.random.RandomState(utt.fetch_seed())
        numpy_rng = numpy.random.RandomState(utt.fetch_seed())
        post0, val0 = f(rng_state0, [-5, .5, 0, 1], [[1.]])
        post1, val1 = f(post0, [.9], [[1.], [1.1], [1.5]])
        post2, val2 = f(post1, [-5, .5, 0, 1], [[1.], [1.1], [1.5]])

        numpy_val0 = numpy_rng.uniform(low=[-5, .5, 0, 1], high=[1.])
        numpy_val1 = numpy_rng.uniform(low=[.9], high=[[1.], [1.1], [1.5]])
        numpy_val2 = numpy_rng.uniform(low=[-5, .5, 0, 1],
                                       high=[[1.], [1.1], [1.5]])

        assert numpy.all(val0 == numpy_val0), (val0, numpy_val0)
        assert numpy.all(val1 == numpy_val1)
        assert numpy.all(val2 == numpy_val2) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:25,代碼來源:test_raw_random.py

示例7: test_param_strict

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_param_strict(self):

        a = tensor.dvector()
        b = shared(7)
        out = a + b

        f = pfunc([In(a, strict=False)], [out])
        # works, rand generates float64 by default
        f(numpy.random.rand(8))
        # works, casting is allowed
        f(numpy.array([1, 2, 3, 4], dtype='int32'))

        f = pfunc([In(a, strict=True)], [out])
        try:
            # fails, f expects float64
            f(numpy.array([1, 2, 3, 4], dtype='int32'))
        except TypeError:
            pass 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:20,代碼來源:test_pfunc.py

示例8: test_param_mutable

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_param_mutable(self):
        a = tensor.dvector()
        a_out = a * 2  # assuming the op which makes this "in place" triggers

        # using mutable=True will let fip change the value in aval
        fip = pfunc([In(a, mutable=True)], [a_out], mode='FAST_RUN')
        aval = numpy.random.rand(10)
        aval2 = aval.copy()
        assert numpy.all(fip(aval) == (aval2 * 2))
        assert not numpy.all(aval == aval2)

        # using mutable=False should leave the input untouched
        f = pfunc([In(a, mutable=False)], [a_out], mode='FAST_RUN')
        aval = numpy.random.rand(10)
        aval2 = aval.copy()
        assert numpy.all(f(aval) == (aval2 * 2))
        assert numpy.all(aval == aval2) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:19,代碼來源:test_pfunc.py

示例9: test_infer_shape

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_infer_shape(self):
        x = dmatrix('x')
        x.tag.test_value = np.zeros((2, 2))
        y = dvector('y')
        y.tag.test_value = [0, 0]

        def infer_shape(node, shapes):
            x, y = shapes
            return [y]

        @as_op([dmatrix, dvector], dvector, infer_shape)
        def cumprod_plus(x, y):
            return np.cumprod(x) + y

        self._compile_and_check([x, y], [cumprod_plus(x, y)],
                                [[[1.5, 5], [2, 2]], [1, 100, 2, 200]],
                                cumprod_plus.__class__, warn=False) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:19,代碼來源:test_ops.py

示例10: test_pydotprint_long_name

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_pydotprint_long_name():
    """This is a REALLY PARTIAL TEST.

    It prints a graph where there are variable and apply nodes whose long
    names are different, but not the shortened names.
    We should not merge those nodes in the dot graph.

    """

    # Skip test if pydot is not available.
    if not theano.printing.pydot_imported:
        raise SkipTest('pydot not available')

    x = tensor.dvector()
    mode = theano.compile.mode.get_default_mode().excluding("fusion")
    f = theano.function([x], [x * 2, x + x], mode=mode)
    f([1, 2, 3, 4])

    theano.printing.pydotprint(f, max_label_size=5,
                               print_output_file=False)
    theano.printing.pydotprint([x * 2, x + x],
                               max_label_size=5,
                               print_output_file=False) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:25,代碼來源:test_printing.py

示例11: test_wrong_input

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_wrong_input(self):
        """
        Make sure errors are raised when image and kernel are not 4D tensors
        """
        self.assertRaises(Exception, self.validate, (3, 2, 8, 8), (4, 2, 5, 5),
                          'valid', input=T.dmatrix())
        self.assertRaises(Exception, self.validate, (3, 2, 8, 8), (4, 2, 5, 5),
                          'valid', filters=T.dvector())
        self.assertRaises(Exception, self.validate, (3, 2, 8, 8), (4, 2, 5, 5),
                          'valid', input=T.dtensor3()) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:12,代碼來源:test_corr.py

示例12: test_fail

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_fail(self):
        """
        Test that conv2d fails for dimensions other than 2 or 3.
        """
        self.assertRaises(Exception, conv.conv2d, T.dtensor4(), T.dtensor3())
        self.assertRaises(Exception, conv.conv2d, T.dtensor3(), T.dvector()) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:8,代碼來源:test_conv.py

示例13: test3

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test3(self):
        a = tensor.dvector()
        w2 = sort(a)
        f = theano.function([a], w2)
        gv = f(self.v_val)
        gt = np.sort(self.v_val)
        assert np.allclose(gv, gt) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:9,代碼來源:test_sort.py

示例14: test_multiple_inplace

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_multiple_inplace(self):
        x = tensor.dmatrix('x')
        y = tensor.dvector('y')
        z = tensor.dvector('z')
        f = theano.function([x, y, z],
                            [tensor.dot(y, x), tensor.dot(z,x)],
                            mode=mode_blas_opt)
        vx = numpy.random.rand(3, 3)
        vy = numpy.random.rand(3)
        vz = numpy.random.rand(3)
        out = f(vx, vy, vz)
        assert numpy.allclose(out[0], numpy.dot(vy, vx))
        assert numpy.allclose(out[1], numpy.dot(vz, vx))
        assert len([n for n in f.maker.fgraph.apply_nodes
                    if isinstance(n.op, tensor.AllocEmpty)]) == 2 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:17,代碼來源:test_blas_c.py

示例15: test_uniform_vector

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dvector [as 別名]
def test_uniform_vector(self):
        random = RandomStreams(utt.fetch_seed())
        low = tensor.dvector()
        high = tensor.dvector()
        out = random.uniform(low=low, high=high)
        assert out.ndim == 1
        f = function([low, high], out)

        low_val = [.1, .2, .3]
        high_val = [1.1, 2.2, 3.3]
        seed_gen = numpy.random.RandomState(utt.fetch_seed())
        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))

        # Arguments of size (3,)
        val0 = f(low_val, high_val)
        numpy_val0 = numpy_rng.uniform(low=low_val, high=high_val)
        print('THEANO', val0)
        print('NUMPY', numpy_val0)
        assert numpy.all(val0 == numpy_val0)

        # arguments of size (2,)
        val1 = f(low_val[:-1], high_val[:-1])
        numpy_val1 = numpy_rng.uniform(low=low_val[:-1], high=high_val[:-1])
        print('THEANO', val1)
        print('NUMPY', numpy_val1)
        assert numpy.all(val1 == numpy_val1)

        # Specifying the size explicitly
        g = function([low, high], random.uniform(low=low, high=high, size=(3,)))
        val2 = g(low_val, high_val)
        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))
        numpy_val2 = numpy_rng.uniform(low=low_val, high=high_val, size=(3,))
        assert numpy.all(val2 == numpy_val2)
        self.assertRaises(ValueError, g, low_val[:-1], high_val[:-1]) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:36,代碼來源:test_shared_randomstreams.py


注:本文中的theano.tensor.dvector方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。