Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c601cd87
提交
c601cd87
authored
9月 25, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cleanup
上级
a2c41283
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
0 行增加
和
228 行删除
+0
-228
compile.py
compile.py
+0
-45
tensor_random.py
tensor_random.py
+0
-183
没有找到文件。
compile.py
浏览文件 @
c601cd87
...
@@ -512,13 +512,6 @@ import copy_reg
...
@@ -512,13 +512,6 @@ import copy_reg
import
cPickle
import
cPickle
def
_pickle_FunctionMaker
(
fm
):
def
_pickle_FunctionMaker
(
fm
):
# print "aaaaaaaaaaaaa"
# print '1', repr(cPickle.dumps(fm.inputs))
# print '2', repr(cPickle.dumps(fm.outputs))
# print fm.mode
# print '3', repr(cPickle.dumps(fm.mode))
# print '4', repr(cPickle.dumps(fm.accept_inplace))
# print "bbbbbbbbbbbbb"
return
(
_constructor_FunctionMaker
,
(
fm
.
inputs
,
fm
.
outputs
,
fm
.
mode
,
fm
.
accept_inplace
))
return
(
_constructor_FunctionMaker
,
(
fm
.
inputs
,
fm
.
outputs
,
fm
.
mode
,
fm
.
accept_inplace
))
def
_constructor_FunctionMaker
(
*
args
):
def
_constructor_FunctionMaker
(
*
args
):
...
@@ -674,14 +667,6 @@ class Function(object):
...
@@ -674,14 +667,6 @@ class Function(object):
def
__setitem__
(
self
,
item
,
value
):
def
__setitem__
(
self
,
item
,
value
):
self
.
value
[
item
]
=
value
self
.
value
[
item
]
=
value
# def __getstate__(self):
# d = dict(maker = self.maker,
# defaults = self.defaults,
# state = [x.data for x in self.input_storage])
# return d
# def __setstate__(self, d):
def
__copy__
(
self
):
def
__copy__
(
self
):
...
@@ -840,32 +825,6 @@ def function(inputs, outputs, mode='FAST_RUN', accept_inplace = False):
...
@@ -840,32 +825,6 @@ def function(inputs, outputs, mode='FAST_RUN', accept_inplace = False):
fn
=
FunctionMaker
(
inputs
,
outputs
,
mode
,
accept_inplace
=
accept_inplace
)
.
create
([
getattr
(
input
,
'value'
,
None
)
for
input
in
inputs
])
fn
=
FunctionMaker
(
inputs
,
outputs
,
mode
,
accept_inplace
=
accept_inplace
)
.
create
([
getattr
(
input
,
'value'
,
None
)
for
input
in
inputs
])
# # create a subclass of Function for the given arguments.
# class F(Function):
# pass
# # add all input names as properties of F
# def _get(name, self):
# return self[name]
# def _set(name, self, value):
# self[name] = value
# def _err(name, self):
# raise TypeError("Ambiguous name: %s - please check the names of the inputs of your function for duplicates." % name)
# seen = set()
# for input in inputs:
# name = input.name
# if name:
# if name in seen:
# f = property(partial(_err, input.name), partial(_err, input.name))
# setattr(F, input.name, f)
# elif not hasattr(F, name):
# f = property(partial(_get, input.name), partial(_set, input.name))
# setattr(F, input.name, f)
# seen.add(input.name)
# else:
# pass
# fn.__class__ = F
return
fn
return
fn
...
@@ -904,10 +863,6 @@ class OpFromGraph(gof.Op):
...
@@ -904,10 +863,6 @@ class OpFromGraph(gof.Op):
"""
"""
def
__init__
(
self
,
inputs
,
outputs
,
grad_depth
=
1
,
**
kwargs
):
def
__init__
(
self
,
inputs
,
outputs
,
grad_depth
=
1
,
**
kwargs
):
# if kwargs.get('borrow_outputs') or kwargs.get('unpack_single'):
# raise ValueError('The borrow_outputs and unpack_single options cannot be True')
# kwargs['unpack_single'] = False
# kwargs['borrow_outputs'] = False
self
.
fn
=
function
(
inputs
,
outputs
,
**
kwargs
)
self
.
fn
=
function
(
inputs
,
outputs
,
**
kwargs
)
self
.
inputs
=
inputs
self
.
inputs
=
inputs
self
.
outputs
=
outputs
self
.
outputs
=
outputs
...
...
tensor_random.py
浏览文件 @
c601cd87
...
@@ -154,186 +154,3 @@ class RandomKit(SymbolicInputKit):
...
@@ -154,186 +154,3 @@ class RandomKit(SymbolicInputKit):
rk
=
RandomKit
(
'rk'
,
0xBAD5EED
)
rk
=
RandomKit
(
'rk'
,
0xBAD5EED
)
# class RandomState(object):
# """The Theano version of numpy.RandomState
# This class generates a sequence of L{Op} instances via the gen() and
# gen_like() methods.
# @ivar seed: an integer which determines the initial state of the L{Op}
# instances returned by gen(), gen_like()
# @type seed: int
# """
# def __init__(self, seed):
# self.seed = seed
# def gen(self, dist, shape=(), ndim=None):
# """
# @param dist: identifier of a sampling distribution. See L{_fn_from_dist}.
# @param shape: tuple
# @return: A tensor of random numbers, with given shape.
# @rtype: L{Result} (output of L{Apply} of L{NumpyGenerator} instance)
# """
# self.seed += 1
# fn = RandomState._fn_from_dist(dist)
# if isinstance(shape, tuple):
# return NumpyGenerator(self.seed-1, len(shape),fn) (shape)
# return NumpyGenerator(self.seed - 1, ndim, fn)(shape)
# def gen_like(self, dist, x):
# """
# @param dist: identifier of a sampling distribution. See L{_fn_from_dist}.
# @param x: L{Result} of type L{Tensor}
# @return: A tensor of random numbers, with the same shape as x.
# @rtype: L{Result} (output of L{Apply} of L{NumpyGenerator} instance)
# """
# self.seed += 1
# fn = RandomState._fn_from_dist(dist)
# return NumpyGenerator(self.seed-1, x.type.ndim, fn)(tensor.shape(x))
# def uniform_like(self, template, low=0.,high=1.):
# """
# Return a multivariate uniform(low,high)
# random variable in a tensor of the same shape as template
# (template can either be a tensor or a shape tuple). Each element of the
# resulting tensor is sampled independently. low and high can
# be scalars or have the same shape as the template (or broadcastable
# to it).
# """
# return self.gen_like(('uniform',{'low':low,'high':high}),template)
# def binomial_like(self, template, n=1, p=0.5):
# """
# Return a multivariate binomial(n,p) random variable in a tensor of the same shape as template
# (template can either be a tensor or a shape tuple). Each element of the
# resulting tensor is sampled independently. low and high can
# be scalars or have the same shape as the template (or broadcastable
# to it).
# """
# return self.gen_like(('binomial',{'n':n,'p':p}),template)
# @staticmethod
# def _fn_from_dist(dist, cache={}):
# """Return a function from a distribution description
# @param dist: identifier of a sampling distribution.
# @type dist: callable or str or tuple(str, dict)
# @param cache: The optional cache argument implements a closure, which ensures that
# multiple requests for the same sampling function will get the same
# sampling function. L{NumpyGenerator}.__hash__ depends on this.
# @type cache: dict
# """
# if callable(dist):
# return dist
# if isinstance(dist, str):
# return getattr(numpy.random.RandomState, dist)
# name, kwargs = dist
# key = (name, tuple(kwargs.items()))
# if key not in cache:
# fn = getattr(numpy.random.RandomState, name)
# fn = functools.partial(fn, **kwargs)
# cache[key] = fn
# return cache[key]
# class NumpyGenerator(gof.op.Op):
# """Supply a sequence of random tensors of a given shape, from a given
# distribution.
# @param seed: initial state for instances of this L{Op}.
# @type seed: anything that numpy.random.RandomState accepts.
# @param ndim: the rank of random tensors produced by this op.
# @type ndim: non-negative integer
# @param fn: a sampling function
# @type fn: a callable that can reply to fn(numpy.RandomState(), size=<tuple>)
# """
# destroy_map = {0: [0]}
# def __init__(self, seed, ndim, fn, **kwargs):
# gof.op.Op.__init__(self, **kwargs)
# self.seed = seed
# self.ndim = ndim
# self.fn = fn
# assert numpy.random.RandomState(seed) #test the seed
# assert 'int' in str(type(ndim))
# assert callable(self.fn)
# def __eq__(self, other):
# return (type(self) is type(other))\
# and self.__class__ is NumpyGenerator \
# and self.seed == other.seed \
# and self.ndim == other.ndim \
# and self.fn == other.fn
# def __hash__(self):
# return self.seed ^ self.ndim ^ hash(self.fn)
# def make_node(self, _shape):
# #TODO: check for constant shape, and guess the broadcastable bits
# shape = tensor.convert_to_int64(_shape)
# if shape.type.ndim != 1:
# raise TypeError('shape argument was not converted to 1-d tensor', _shape)
# # we generate one random number with the distribution to determine what dtype to expect
# output_dtype = str(self.fn(numpy.random.RandomState(18), size=(1,)).dtype)
# inputs = [gof.Value(gof.type.generic, numpy.random.RandomState(self.seed)), shape]
# outputs = [tensor.Tensor(dtype=output_dtype, broadcastable = [False]*self.ndim).make_result()]
# return gof.Apply(op = self, inputs = inputs, outputs = outputs)
# def grad(self, inputs, grad_outputs):
# return [None, None]
# def perform(self, node, input_storage, output_storage):
# rng = input_storage[0]
# shape = input_storage[1]
# if self.ndim != len(shape):
# raise ValueError('shape argument %s had the wrong length (!=%i)' %
# (shape, self.ndim) )
# output_storage[0][0] = self.fn(rng, size=shape)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论