Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
17f1b0fa
提交
17f1b0fa
authored
6月 09, 2014
作者:
Hengjean
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed all bugs.
上级
2774de58
隐藏空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
59 行增加
和
51 行删除
+59
-51
cc.py
theano/gof/cc.py
+4
-1
multinomial.py
theano/sandbox/multinomial.py
+9
-2
neighbours.py
theano/sandbox/neighbours.py
+1
-1
basic.py
theano/scalar/basic.py
+4
-4
basic.py
theano/tensor/basic.py
+1
-1
blas.py
theano/tensor/blas.py
+2
-2
blas_c.py
theano/tensor/blas_c.py
+1
-1
elemwise_cgen.py
theano/tensor/elemwise_cgen.py
+5
-4
extra_ops.py
theano/tensor/extra_ops.py
+8
-8
nnet.py
theano/tensor/nnet/nnet.py
+6
-6
type.py
theano/tensor/type.py
+6
-13
type.py
theano/typed_list/type.py
+12
-8
没有找到文件。
theano/gof/cc.py
浏览文件 @
17f1b0fa
...
...
@@ -308,7 +308,10 @@ def get_nothing(r, name, sub):
def
get_c_declare
(
r
,
name
,
sub
):
"""Wrapper around c_declare that declares py_name"""
if
any
([
c
==
'output'
or
getattr
(
c
.
op
,
'check_input'
,
True
)
for
(
c
,
_
)
class
helper
:
check_input
=
False
if
any
([
getattr
(
getattr
(
c
,
'op'
,
helper
),
'check_input'
,
True
)
for
(
c
,
_
)
in
r
.
clients
])
or
(
r
.
owner
and
getattr
(
r
.
owner
.
op
,
'check_input'
,
True
)):
...
...
theano/sandbox/multinomial.py
浏览文件 @
17f1b0fa
...
...
@@ -59,7 +59,14 @@ class MultinomialFromUniform(Op):
def
c_code
(
self
,
node
,
name
,
ins
,
outs
,
sub
):
(
pvals
,
unis
)
=
ins
(
z
,)
=
outs
if
self
.
odtype
==
'auto'
:
t
=
"PyArray_TYPE((PyArrayObject*) py_
%(pvals)
s)"
%
locals
()
else
:
t
=
theano
.
scalar
.
Scalar
(
self
.
odtype
)
.
dtype_specs
()[
1
]
if
t
.
startswith
(
'theano_complex'
):
t
=
t
.
replace
(
'theano_complex'
,
'NPY_COMPLEX'
)
else
:
t
=
t
.
upper
()
fail
=
sub
[
'fail'
]
return
"""
if (PyArray_NDIM(
%(pvals)
s) != 2)
...
...
@@ -87,7 +94,7 @@ class MultinomialFromUniform(Op):
Py_XDECREF(
%(z)
s);
%(z)
s = (PyArrayObject*) PyArray_ZEROS(2,
PyArray_DIMS(
%(pvals)
s),
type_num_
%(z
)
s,
%(t
)
s,
0);
if (!
%(z)
s)
{
...
...
theano/sandbox/neighbours.py
浏览文件 @
17f1b0fa
...
...
@@ -335,7 +335,7 @@ class Images2Neibs(Op):
%(z)
s = (PyArrayObject*) PyArray_EMPTY(2,
dims,
type_num_
%(ten4)
s
,
PyArray_TYPE((PyArrayObject*) py_
%(ten4)
s)
,
0);
if (!
%(z)
s)
...
...
theano/scalar/basic.py
浏览文件 @
17f1b0fa
...
...
@@ -257,13 +257,13 @@ class Scalar(Type):
def
c_declare
(
self
,
name
,
sub
,
check_input
=
True
):
if
(
check_input
):
pre
=
"""
%(dtype)
s
%(name)
s;
typedef
%(dtype)
s
%(name)
s_dtype; // Deprecated use dtype_
%(name)
s instead.
typedef
%(dtype)
s dtype_
%(name)
s;
"""
%
dict
(
name
=
name
,
dtype
=
self
.
dtype_specs
()[
1
])
else
:
pre
=
""
return
pre
+
"""
typedef
%(dtype)
s
%(name)
s_dtype; // Deprecated use dtype_
%(name)
s instead.
typedef
%(dtype)
s dtype_
%(name)
s;
%(dtype)
s
%(name)
s;
"""
%
dict
(
name
=
name
,
dtype
=
self
.
dtype_specs
()[
1
])
def
c_init
(
self
,
name
,
sub
):
...
...
@@ -462,7 +462,7 @@ class Scalar(Type):
return
[
"import_array();"
]
def
c_code_cache_version
(
self
):
return
(
1
2
,
numpy
.
__version__
)
return
(
1
3
,
numpy
.
__version__
)
def
get_shape_info
(
self
,
obj
):
return
obj
.
itemsize
...
...
theano/tensor/basic.py
浏览文件 @
17f1b0fa
...
...
@@ -2425,7 +2425,7 @@ class Alloc(gof.Op):
{
Py_XDECREF(
%(zz)
s);
%(zz)
s = (PyArrayObject*) PyArray_SimpleNew(
%(ndim)
s,
shape,
type_num_
%(vv)
s
);
shape,
PyArray_TYPE((PyArrayObject*) py_
%(vv)
s)
);
if (!
%(zz)
s)
{
PyErr_SetString(PyExc_MemoryError, "alloc failed");
...
...
theano/tensor/blas.py
浏览文件 @
17f1b0fa
...
...
@@ -1026,7 +1026,7 @@ class Gemm(GemmRelated):
dims[0] = PyArray_DIMS(
%(_z)
s)[0];
dims[1] = PyArray_DIMS(
%(_z)
s)[1];
%(_zout)
s = (PyArrayObject*)PyArray_SimpleNew(2, dims,
type_num_
%(_z)
s
);
PyArray_TYPE((PyArrayObject*) py_
%(_z)
s)
);
//fprintf(stderr, "Gemm Allocating
%%
i
%%
i
\\
n", dims[0], dims[1]);
if(!
%(_zout)
s) {
PyErr_SetString(PyExc_MemoryError,
...
...
@@ -1627,7 +1627,7 @@ class Dot22(GemmRelated):
dims[0] = PyArray_DIMS(
%(_x)
s)[0];
dims[1] = PyArray_DIMS(
%(_y)
s)[1];
%(_zout)
s = (PyArrayObject*)PyArray_SimpleNew(2, dims,
type_num_
%(_x)
s
);
PyArray_TYPE((PyArrayObject*) py_
%(_x)
s)
);
//fprintf(stderr, "Dot Allocating
%%
i
%%
i
\\
n", dims[0], dims[1]);
if(!
%(_zout)
s) {
PyErr_SetString(PyExc_MemoryError,
...
...
theano/tensor/blas_c.py
浏览文件 @
17f1b0fa
...
...
@@ -353,7 +353,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
{
if (
%(zz)
s) Py_XDECREF(
%(zz)
s);
%(zz)
s = (PyArrayObject*)PyArray_SimpleNew(1,
PyArray_DIMS(
%(aa)
s),
type_num_
%(aa)
s
);
PyArray_DIMS(
%(aa)
s),
PyArray_TYPE((PyArrayObject*) py_
%(aa)
s)
);
if(!
%(zz)
s) {
PyErr_SetString(PyExc_MemoryError,
"failed to alloc gemv output");
...
...
theano/tensor/elemwise_cgen.py
浏览文件 @
17f1b0fa
...
...
@@ -121,7 +121,9 @@ def make_alloc(loop_orders, dtype, sub, fortran='0'):
created, otherwise it will be c order.
"""
type
=
dtype
.
upper
()
if
type
.
startswith
(
'THEANO_COMPLEX'
):
type
=
type
.
replace
(
'THEANO_COMPLEX'
,
'NPY_COMPLEX'
)
nd
=
len
(
loop_orders
[
0
])
init_dims
=
""
# For each dimension, the tensors are either all broadcasted, in
...
...
@@ -142,7 +144,6 @@ def make_alloc(loop_orders, dtype, sub, fortran='0'):
# way that its contiguous dimensions match one of the input's
# contiguous dimensions, or the dimension with the smallest
# stride. Right now, it is allocated to be C_CONTIGUOUS.
return
"""
{
npy_intp dims[
%(nd)
s];
...
...
@@ -150,7 +151,7 @@ def make_alloc(loop_orders, dtype, sub, fortran='0'):
%(init_dims)
s
if (!
%(olv)
s) {
%(olv)
s = (PyArrayObject*)PyArray_EMPTY(
%(nd)
s, dims,
type_num_
%(olv
)
s,
%(type
)
s,
%(fortran)
s);
}
else {
...
...
@@ -162,7 +163,7 @@ def make_alloc(loop_orders, dtype, sub, fortran='0'):
// If we can't resize the ndarray we have we can allocate a new one.
PyErr_Clear();
Py_XDECREF(
%(olv)
s);
%(olv)
s = (PyArrayObject*)PyArray_EMPTY(
%(nd)
s, dims,
type_num_
%(olv
)
s, 0);
%(olv)
s = (PyArrayObject*)PyArray_EMPTY(
%(nd)
s, dims,
%(type
)
s, 0);
}
}
if (!
%(olv)
s) {
...
...
theano/tensor/extra_ops.py
浏览文件 @
17f1b0fa
...
...
@@ -68,13 +68,13 @@ class CumsumOp(theano.Op):
if(!(
%(z)
s && PyArray_DIMS(
%(z)
s)[0] == shape[0]))
{
Py_XDECREF(
%(z)
s);
%(z)
s = (PyArrayObject*) PyArray_SimpleNew(1, shape,
type_num_
%(x)
s
);
%(z)
s = (PyArrayObject*) PyArray_SimpleNew(1, shape,
PyArray_TYPE((PyArrayObject*) py_
%(x)
s)
);
}
if (!
%(z)
s)
%(fail)
s;
{
PyArray_CumSum(
%(x)
s, NPY_MAXDIMS,
type_num_
%(x)
s
,
%(z)
s);
PyArray_CumSum(
%(x)
s, NPY_MAXDIMS,
PyArray_TYPE((PyArrayObject*) py_
%(x)
s)
,
%(z)
s);
Py_XDECREF(
%(z)
s); // Because PyArray_CumSum returns a newly created reference on
%(z)
s.
}
"""
%
locals
()
...
...
@@ -83,13 +83,13 @@ class CumsumOp(theano.Op):
if(!(
%(z)
s && PyArray_CompareLists(PyArray_DIMS(
%(z)
s), PyArray_DIMS(
%(x)
s), PyArray_NDIM(
%(x)
s)) ))
{
Py_XDECREF(
%(z)
s);
%(z)
s = (PyArrayObject*) PyArray_SimpleNew(PyArray_NDIM(
%(x)
s), PyArray_DIMS(
%(x)
s),
type_num_
%(x)
s
);
%(z)
s = (PyArrayObject*) PyArray_SimpleNew(PyArray_NDIM(
%(x)
s), PyArray_DIMS(
%(x)
s),
PyArray_TYPE((PyArrayObject*) py_
%(x)
s)
);
}
if (!
%(z)
s)
%(fail)
s;
{
PyArray_CumSum(
%(x)
s,
%(axis)
s,
type_num_
%(x)
s
,
%(z)
s);
PyArray_CumSum(
%(x)
s,
%(axis)
s,
PyArray_TYPE((PyArrayObject*) py_
%(x)
s)
,
%(z)
s);
Py_XDECREF(
%(z)
s); // Because PyArray_CumSum returns a newly created reference on
%(z)
s.
}
"""
%
locals
()
...
...
@@ -177,13 +177,13 @@ class CumprodOp(theano.Op):
if(!(
%(z)
s && PyArray_DIMS(
%(z)
s)[0] == shape[0]))
{
Py_XDECREF(
%(z)
s);
%(z)
s = (PyArrayObject*) PyArray_SimpleNew(1, shape,
type_num_
%(x)
s
);
%(z)
s = (PyArrayObject*) PyArray_SimpleNew(1, shape,
PyArray_TYPE((PyArrayObject*) py_
%(x)
s)
);
}
if (!
%(z)
s)
%(fail)
s;
{
PyArray_CumProd(
%(x)
s, NPY_MAXDIMS,
type_num_
%(x)
s
,
%(z)
s);
PyArray_CumProd(
%(x)
s, NPY_MAXDIMS,
PyArray_TYPE((PyArrayObject*) py_
%(x)
s)
,
%(z)
s);
Py_XDECREF(
%(z)
s); // Because PyArray_CumSum returns a newly created reference on
%(z)
s.
}
"""
%
locals
()
...
...
@@ -192,13 +192,13 @@ class CumprodOp(theano.Op):
if(!(
%(z)
s && PyArray_CompareLists(PyArray_DIMS(
%(z)
s), PyArray_DIMS(
%(x)
s), PyArray_NDIM(
%(x)
s)) ))
{
Py_XDECREF(
%(z)
s);
%(z)
s = (PyArrayObject*) PyArray_SimpleNew(PyArray_NDIM(
%(x)
s), PyArray_DIMS(
%(x)
s),
type_num_
%(x)
s
);
%(z)
s = (PyArrayObject*) PyArray_SimpleNew(PyArray_NDIM(
%(x)
s), PyArray_DIMS(
%(x)
s),
PyArray_TYPE((PyArrayObject*) py_
%(x)
s)
);
}
if (!
%(z)
s)
%(fail)
s;
{
PyArray_CumProd(
%(x)
s,
%(axis)
s,
type_num_
%(x)
s
,
%(z)
s);
PyArray_CumProd(
%(x)
s,
%(axis)
s,
PyArray_TYPE((PyArrayObject*) py_
%(x)
s)
,
%(z)
s);
Py_XDECREF(
%(z)
s); // Because PyArray_CumSum returns a newly created reference on
%(z)
s.
}
"""
%
locals
()
...
...
theano/tensor/nnet/nnet.py
浏览文件 @
17f1b0fa
...
...
@@ -148,7 +148,7 @@ class SoftmaxWithBias(gof.Op):
{
if (NULL !=
%(sm)
s) Py_XDECREF(
%(sm)
s);
%(sm)
s = (PyArrayObject*)PyArray_SimpleNew(2, PyArray_DIMS(
%(x)
s),
type_num_
%(x)
s
);
PyArray_TYPE((PyArrayObject*) py_
%(x)
s)
);
if(!
%(sm)
s) {
PyErr_SetString(PyExc_MemoryError,
"failed to alloc sm output");
...
...
@@ -342,7 +342,7 @@ class SoftmaxGrad(gof.Op):
Py_XDECREF(
%(dx)
s);
%(dx)
s = (PyArrayObject*) PyArray_SimpleNew(2,
PyArray_DIMS(
%(sm)
s),
type_num_
%(sm)
s
);
PyArray_TYPE((PyArrayObject*) py_
%(sm)
s)
);
if (!
%(dx)
s)
{
PyErr_SetString(PyExc_MemoryError,
...
...
@@ -463,7 +463,7 @@ class Softmax(gof.Op):
{
Py_XDECREF(
%(sm)
s);
%(sm)
s = (PyArrayObject*)PyArray_SimpleNew(2, PyArray_DIMS(
%(x)
s),
type_num_
%(x)
s
);
PyArray_TYPE((PyArrayObject*) py_
%(x)
s)
);
if(!
%(sm)
s) {
PyErr_SetString(PyExc_MemoryError,
"failed to alloc sm output");
...
...
@@ -977,7 +977,7 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
{
if (NULL !=
%(nll)
s) Py_XDECREF(
%(nll)
s);
%(nll)
s = (PyArrayObject*)PyArray_SimpleNew(1,
PyArray_DIMS(
%(y_idx)
s),
type_num_
%(x)
s
);
PyArray_DIMS(
%(y_idx)
s),
PyArray_TYPE((PyArrayObject*) py_
%(x)
s)
);
if(!
%(nll)
s)
{
PyErr_SetString(PyExc_MemoryError,
...
...
@@ -990,7 +990,7 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
{
Py_XDECREF(
%(am)
s);
%(am)
s = (PyArrayObject*) PyArray_SimpleNew(1,
PyArray_DIMS(
%(y_idx)
s),
type_num_
%(y_idx)
s
);
PyArray_DIMS(
%(y_idx)
s),
PyArray_TYPE((PyArrayObject*) py_
%(y_idx)
s)
);
if(!
%(am)
s)
{
PyErr_SetString(PyExc_MemoryError,
...
...
@@ -1144,7 +1144,7 @@ class CrossentropySoftmax1HotWithBiasDx (gof.Op):
if (NULL !=
%(dx)
s) Py_XDECREF(
%(dx)
s);
%(dx)
s = (PyArrayObject*) PyArray_SimpleNew(2,
PyArray_DIMS(
%(sm)
s),
type_num_
%(sm)
s
);
PyArray_TYPE((PyArrayObject*) py_
%(sm)
s)
);
if(!
%(dx)
s) {
PyErr_SetString(PyExc_MemoryError,
"failed to alloc dx output");
...
...
theano/tensor/type.py
浏览文件 @
17f1b0fa
...
...
@@ -426,7 +426,6 @@ class TensorType(Type):
check
=
""
declaration
=
"""
PyArrayObject*
%(name)
s;
int type_num_
%(name)
s;
"""
%
dict
(
sub
,
name
=
name
,
dtype
=
self
.
dtype_specs
()[
1
])
return
declaration
+
check
...
...
@@ -435,7 +434,6 @@ class TensorType(Type):
"""Override `CLinkerType.c_init` """
return
"""
%(name)
s = NULL;
type_num_
%(name)
s =
%(type_num)
s;
"""
%
dict
(
sub
,
name
=
name
,
type_num
=
self
.
dtype_specs
()[
2
])
def
c_extract
(
self
,
name
,
sub
,
check_input
=
True
):
...
...
@@ -455,7 +453,6 @@ class TensorType(Type):
%(fail)
s
}
// We expect
%(type_num)
s
type_num_
%(name)
s = PyArray_TYPE((PyArrayObject*) py_
%(name)
s);
if (!PyArray_ISALIGNED((PyArrayObject*) py_
%(name)
s)) {
PyArrayObject * tmp = (PyArrayObject*) py_
%(name)
s;
PyErr_Format(PyExc_NotImplementedError,
...
...
@@ -465,7 +462,7 @@ class TensorType(Type):
"
%%
ld,
%%
ld,
%%
ld"
" and 3 last strides
%%
ld
%%
ld,
%%
ld.",
(long int)
%(type_num)
s,
(long int)
type_num_
%(name)
s
,
(long int)
PyArray_TYPE((PyArrayObject*) py_
%(name)
s)
,
(long int) PyArray_NDIM(tmp),
(long int) PyArray_NDIM(tmp) >= 3 ?
PyArray_DIMS(tmp)[PyArray_NDIM(tmp)-3] : -1,
...
...
@@ -484,17 +481,15 @@ class TensorType(Type):
}
// This is a TypeError to be consistent with DEBUG_MODE
// Note: DEBUG_MODE also tells the name of the container
if (
type_num_
%(name)
s
!=
%(type_num)
s) {
if (
PyArray_TYPE((PyArrayObject*) py_
%(name)
s)
!=
%(type_num)
s) {
PyErr_Format(PyExc_TypeError,
"expected type_num
%%
d (
%(type_num)
s) got
%%
d",
%(type_num)
s,
type_num_
%(name)
s
);
%(type_num)
s,
PyArray_TYPE((PyArrayObject*) py_
%(name)
s)
);
%(fail)
s
}
"""
%
dict
(
sub
,
name
=
name
,
type_num
=
self
.
dtype_specs
()[
2
])
else
:
check
=
"""
type_num_
%(name)
s = PyArray_TYPE((PyArrayObject*) py_
%(name)
s);
"""
%
dict
(
sub
,
name
=
name
,
type_num
=
self
.
dtype_specs
()[
2
])
check
=
""
return
check
+
"""
%(name)
s = (PyArrayObject*)(py_
%(name)
s);
Py_XINCREF(
%(name)
s);
...
...
@@ -526,13 +521,11 @@ class TensorType(Type):
if (
%(name)
s && !PyArray_ISALIGNED((PyArrayObject*) py_
%(name)
s)) {
PyErr_Format(PyExc_NotImplementedError,
"c_sync: expected an aligned array of type
%%
ld "
"(
%(type_num)
s), got non-aligned array of type
%%
ld"
"c_sync: expected an aligned array, got non-aligned array of type
%%
ld"
" with
%%
ld dimensions, with 3 last dims "
"
%%
ld,
%%
ld,
%%
ld"
" and 3 last strides
%%
ld
%%
ld,
%%
ld.",
(long int)
%(type_num)
s,
(long int) type_num_
%(name)
s,
(long int) PyArray_TYPE((PyArrayObject*) py_
%(name)
s),
(long int) PyArray_NDIM(
%(name)
s),
(long int) PyArray_NDIM(
%(name)
s) >= 3 ?
PyArray_DIMS(
%(name)
s)[PyArray_NDIM(
%(name)
s)-3] : -1,
...
...
theano/typed_list/type.py
浏览文件 @
17f1b0fa
...
...
@@ -76,7 +76,7 @@ class TypedListType(gof.Type):
return
True
def
c_declare
(
self
,
name
,
sub
):
def
c_declare
(
self
,
name
,
sub
,
check_input
=
True
):
return
"""
PyListObject*
%(name)
s;
"""
%
dict
(
name
=
name
)
...
...
@@ -86,12 +86,16 @@ class TypedListType(gof.Type):
%(name)
s = NULL;
"""
%
dict
(
name
=
name
)
def
c_extract
(
self
,
name
,
sub
):
return
"""
if (!PyList_Check(py_
%(name)
s)) {
PyErr_SetString(PyExc_TypeError, "expected a list");
%(fail)
s
}
def
c_extract
(
self
,
name
,
sub
,
check_input
=
True
):
if
check_input
:
pre
=
"""
if (!PyList_Check(py_
%(name)
s)) {
PyErr_SetString(PyExc_TypeError, "expected a list");
%(fail)
s
}"""
else
:
pre
=
""
return
pre
+
"""
%(name)
s = (PyListObject*) (py_
%(name)
s);
"""
%
dict
(
name
=
name
,
fail
=
sub
[
'fail'
])
...
...
@@ -107,4 +111,4 @@ class TypedListType(gof.Type):
return
""
def
c_code_cache_version
(
self
):
return
(
1
,)
return
(
2
,)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论