Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6736be29
提交
6736be29
authored
3月 19, 2010
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
差异文件
Merged
上级
0832b113
e4bb7837
全部展开
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
69 行增加
和
14 行删除
+69
-14
mode.py
theano/compile/mode.py
+1
-1
cuda_ndarray.cu
theano/sandbox/cuda/cuda_ndarray.cu
+28
-12
rng_mrg.py
theano/sandbox/rng_mrg.py
+0
-0
nnet.py
theano/tensor/nnet/nnet.py
+1
-1
opt.py
theano/tensor/opt.py
+39
-0
没有找到文件。
theano/compile/mode.py
浏览文件 @
6736be29
...
@@ -131,7 +131,7 @@ optdb.register('merge1', gof.MergeOptimizer(),
...
@@ -131,7 +131,7 @@ optdb.register('merge1', gof.MergeOptimizer(),
0
,
'fast_run'
,
'fast_compile'
)
0
,
'fast_run'
,
'fast_compile'
)
optdb
.
register
(
'canonicalize'
,
gof
.
EquilibriumDB
(),
# rearranges elemwise expressions
optdb
.
register
(
'canonicalize'
,
gof
.
EquilibriumDB
(),
# rearranges elemwise expressions
1
,
'fast_run'
)
1
,
'fast_run'
)
optdb
.
register
(
'merge1.2'
,
gof
.
MergeOptimizer
(
skip_const_merge
=
Tru
e
),
optdb
.
register
(
'merge1.2'
,
gof
.
MergeOptimizer
(
skip_const_merge
=
Fals
e
),
1.2
,
'fast_run'
,
'fast_compile'
)
1.2
,
'fast_run'
,
'fast_compile'
)
optdb
.
register
(
'stabilize'
,
gof
.
EquilibriumDB
(),
# replace unstable subgraphs
optdb
.
register
(
'stabilize'
,
gof
.
EquilibriumDB
(),
# replace unstable subgraphs
1.5
,
'fast_run'
)
1.5
,
'fast_run'
)
...
...
theano/sandbox/cuda/cuda_ndarray.cu
浏览文件 @
6736be29
...
@@ -956,21 +956,26 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
...
@@ -956,21 +956,26 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
CudaNdarray * self = (CudaNdarray*) py_self;
CudaNdarray * self = (CudaNdarray*) py_self;
PyObject * py_rval = NULL;
PyObject * py_rval = NULL;
CudaNdarray * rval = NULL;
CudaNdarray * rval = NULL;
PyObject * intobj = NULL;
//PyObject_Print(key, stderr, 0);
if (key == Py_Ellipsis)
if (key == Py_Ellipsis)
{
{
Py_INCREF(py_self);
Py_INCREF(py_self);
return py_self;
return py_self;
}
}
else if (PyInt_Check(key)) //INDEXING BY INTEGER
if ((intobj=PyNumber_Int(key))) //INDEXING BY INTEGER
//else if (PyInt_Check(key)) //INDEXING BY INTEGER
{
{
int d_idx = PyInt_AsLong(intobj);
Py_DECREF(intobj); intobj=NULL;
//int d_idx = PyInt_AsLong(key);
if (self->nd == 0)
if (self->nd == 0)
{
{
PyErr_SetString(PyExc_NotImplementedError, "index into 0-d array");
PyErr_SetString(PyExc_NotImplementedError, "index into 0-d array");
return NULL;
return NULL;
}
}
int d_idx = PyInt_AsLong(key);
int d_dim = CudaNdarray_HOST_DIMS(self)[0];
int d_dim = CudaNdarray_HOST_DIMS(self)[0];
int offset = 0;
int offset = 0;
...
@@ -1009,7 +1014,11 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
...
@@ -1009,7 +1014,11 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
CudaNdarray_set_dim(rval, d-1, CudaNdarray_HOST_DIMS(self)[d]);
CudaNdarray_set_dim(rval, d-1, CudaNdarray_HOST_DIMS(self)[d]);
}
}
}
}
else if (PySlice_Check(key)) //INDEXING BY SLICE
else
{
PyErr_Clear();
}
if (PySlice_Check(key)) //INDEXING BY SLICE
{
{
if (self->nd == 0)
if (self->nd == 0)
{
{
...
@@ -1057,7 +1066,7 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
...
@@ -1057,7 +1066,7 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
CudaNdarray_set_dim(rval, d, CudaNdarray_HOST_DIMS(self)[d]);
CudaNdarray_set_dim(rval, d, CudaNdarray_HOST_DIMS(self)[d]);
}
}
}
}
else
if (PyTuple_Check(key)) //INDEXING BY TUPLE
if (PyTuple_Check(key)) //INDEXING BY TUPLE
{
{
//elements of the tuple can be either integers or slices
//elements of the tuple can be either integers or slices
//the dimensionality of the view we will return is diminished for each slice in the tuple
//the dimensionality of the view we will return is diminished for each slice in the tuple
...
@@ -1127,9 +1136,11 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
...
@@ -1127,9 +1136,11 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
}
}
++rval_d;
++rval_d;
}
}
else if (
PyInt_Check(key_d
))
else if (
(intobj=PyNumber_Int(key_d)
))
{
{
int d_idx = PyInt_AsLong(key_d);
int d_idx = PyInt_AsLong(intobj);
Py_DECREF(intobj);
intobj = NULL;
int d_dim = CudaNdarray_HOST_DIMS(self)[d];
int d_dim = CudaNdarray_HOST_DIMS(self)[d];
if ((d_idx >= 0) && (d_idx < d_dim))
if ((d_idx >= 0) && (d_idx < d_dim))
...
@@ -1151,6 +1162,7 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
...
@@ -1151,6 +1162,7 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
}
}
else
else
{
{
PyErr_Clear(); // clear the error set by PyNumber_Int
PyErr_SetString(PyExc_IndexError, "index must be either int or slice");
PyErr_SetString(PyExc_IndexError, "index must be either int or slice");
Py_DECREF(rval);
Py_DECREF(rval);
return NULL;
return NULL;
...
@@ -1158,16 +1170,16 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
...
@@ -1158,16 +1170,16 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
}
}
}
}
}
}
else
{
PyErr_SetString(PyExc_NotImplementedError, "Unknown key type");
return NULL;
}
if (py_rval)
if (py_rval)
{
{
if (verbose) fprint_CudaNdarray(stderr, self);
if (verbose) fprint_CudaNdarray(stderr, self);
if (verbose) fprint_CudaNdarray(stderr, rval);
if (verbose) fprint_CudaNdarray(stderr, rval);
}
}
else
{
PyErr_SetString(PyExc_NotImplementedError, "Unknown key type");
return NULL;
}
return py_rval;
return py_rval;
}
}
...
@@ -1776,6 +1788,10 @@ int CudaNdarray_CopyFromCudaNdarray(CudaNdarray * self, CudaNdarray * other)
...
@@ -1776,6 +1788,10 @@ int CudaNdarray_CopyFromCudaNdarray(CudaNdarray * self, CudaNdarray * other)
}
}
size *= (unsigned int) CudaNdarray_HOST_DIMS(self)[i];
size *= (unsigned int) CudaNdarray_HOST_DIMS(self)[i];
}
}
if (0 == size)
{
return 0; //nothing to copy, we're done.
}
if (CudaNdarray_is_c_contiguous(self) && CudaNdarray_is_c_contiguous(other))
if (CudaNdarray_is_c_contiguous(self) && CudaNdarray_is_c_contiguous(other))
{
{
cublasScopy(size, CudaNdarray_DEV_DATA(other), 1, CudaNdarray_DEV_DATA(self), 1);
cublasScopy(size, CudaNdarray_DEV_DATA(other), 1, CudaNdarray_DEV_DATA(self), 1);
...
...
theano/sandbox/rng_mrg.py
浏览文件 @
6736be29
差异被折叠。
点击展开。
theano/tensor/nnet/nnet.py
浏览文件 @
6736be29
...
@@ -1257,7 +1257,7 @@ class Prepend_scalar_constant_to_each_row(gof.Op):
...
@@ -1257,7 +1257,7 @@ class Prepend_scalar_constant_to_each_row(gof.Op):
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
))
and
(
self
.
val
==
other
.
val
)
return
(
type
(
self
)
==
type
(
other
))
and
(
self
.
val
==
other
.
val
)
def
__hash__
(
self
):
def
__hash__
(
self
):
return
tensor
.
hashtype
(
self
)
^
hash
(
self
.
val
.
value
)
return
tensor
.
hashtype
(
self
)
^
hash
(
self
.
val
.
data
)
def
__str__
(
self
):
def
__str__
(
self
):
return
'
%
s{
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
val
)
return
'
%
s{
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
val
)
...
...
theano/tensor/opt.py
浏览文件 @
6736be29
...
@@ -610,6 +610,43 @@ def local_alloc_unary(node):
...
@@ -610,6 +610,43 @@ def local_alloc_unary(node):
return
[
T
.
alloc
(
T
.
cast
(
v
,
node
.
outputs
[
0
]
.
dtype
),
*
shp
)]
return
[
T
.
alloc
(
T
.
cast
(
v
,
node
.
outputs
[
0
]
.
dtype
),
*
shp
)]
############################
# Constant Canonicalization
############################
@register_canonicalize
@gof.local_optimizer
([])
def
local_upcast_elemwise_constant_inputs
(
node
):
"""This explicitly upcasts constant inputs to elemwise Ops, when those Ops do implicit upcasting anyway.
Rationale: it helps merge things like (1-x) and (1.0 - x).
"""
if
isinstance
(
node
.
op
,
T
.
Elemwise
):
scalar_op
=
node
.
op
.
scalar_op
#print "aa", scalar_op.output_types_preference
if
scalar_op
.
output_types_preference
in
(
T
.
scal
.
upgrade_to_float
,
T
.
scal
.
upcast_out
):
# this is the kind of op that we can screw with the input dtypes by upcasting
# explicitly
#print "HELLO??"
output_dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
new_inputs
=
[]
for
i
in
node
.
inputs
:
if
i
.
type
.
dtype
==
output_dtype
:
new_inputs
.
append
(
i
)
else
:
try
:
cval_i
=
get_constant_value
(
i
)
# works only for scalars I think
new_inputs
.
append
(
T
.
cast
(
cval_i
,
output_dtype
))
except
:
if
isinstance
(
i
,
T
.
TensorConstant
):
#for the case of a non-scalar
new_inputs
.
append
(
T
.
cast
(
i
,
output_dtype
))
else
:
new_inputs
.
append
(
i
)
if
new_inputs
!=
node
.
inputs
:
return
[
node
.
op
(
*
new_inputs
)]
##################
##################
# Subtensor opts #
# Subtensor opts #
##################
##################
...
@@ -1717,6 +1754,7 @@ def local_greedy_distributor(node):
...
@@ -1717,6 +1754,7 @@ def local_greedy_distributor(node):
return
[
rval
]
return
[
rval
]
register_canonicalize
(
local_greedy_distributor
)
register_canonicalize
(
local_greedy_distributor
)
register_stabilize
(
local_greedy_distributor
)
...
@@ -1748,6 +1786,7 @@ def constant_folding(node):
...
@@ -1748,6 +1786,7 @@ def constant_folding(node):
return
msg
return
msg
register_canonicalize
(
constant_folding
)
register_canonicalize
(
constant_folding
)
register_stabilize
(
constant_folding
)
# because
register_specialize
(
constant_folding
)
register_specialize
(
constant_folding
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论