theano中 founction的用法

代码说明:

import theano
import theano.tensor as T
print 'theano.scan_module.until:'
class GRU:
    def __init__(self,word_dim):
        self.word_dim = word_dim
        self.theano = {}
        self.__Thea_build__()

    def __Thea_build__(self):

        def prod_2(pre_value, max_value):
            print "what-what"
            return pre_value*2, theano.scan_module.until(pre_value*2 > max_value)

        max_value = T.iscalar('max_value')
        result, update = theano.scan(prod_2, outputs_info=T.constant(1.),
                                     non_sequences=[max_value], n_steps=100)

        self.prod_fn = theano.function([max_value], result, updates=update)


mode = GRU(3)
print "-----------------------------"
for i in range(100,500,100):
    print mode.prod_fn(i)


执行前需要先编译一下

输出:

[@104_27 theano_test]$ python theano_function.py
Using gpu device 0
theano.scan_module.until:
what-what
-----------------------------
[   2.    4.    8.   16.   32.   64.  128.]
[   2.    4.    8.   16.   32.   64.  128.  256.]
[   2.    4.    8.   16.   32.   64.  128.  256.  512.]
[   2.    4.    8.   16.   32.   64.  128.  256.  512.]



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值