Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3c5882e1
提交
3c5882e1
authored
3月 16, 2009
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
67091013
33724dbe
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
27 行增加
和
27 行删除
+27
-27
ctype.txt
doc/tutorials/advanced/ex1/ctype.txt
+1
-1
module.py
theano/compile/module.py
+6
-6
test_module.py
theano/compile/tests/test_module.py
+5
-0
basic.py
theano/sparse/basic.py
+15
-20
没有找到文件。
doc/tutorials/advanced/ex1/ctype.txt
浏览文件 @
3c5882e1
...
...
@@ -67,7 +67,7 @@ the most important ones:
- When the computations are done, transfer the results from the C
structure we put them in to the destination Python object. This
will only be called for the
in
puts.
will only be called for the
out
puts.
- **c_cleanup(name, sub)**
...
...
theano/compile/module.py
浏览文件 @
3c5882e1
...
...
@@ -1091,7 +1091,11 @@ class Module(ComponentDict):
directly.
"""
InstanceType
=
ModuleInstance
# By default, we use build ModuleInstance
def
__init__
(
self
):
super
(
Module
,
self
)
.
__init__
()
self
.
__dict__
[
"local_attr"
]
=
{}
def
__wrapper__
(
self
,
x
):
"""
This function is called whenever x is set as an attribute of
...
...
@@ -1139,12 +1143,8 @@ class Module(ComponentDict):
# raise NotImplementedError
# print "WARNING: unknow:",v
return
v
value
=
unpack_member_and_external
(
value
)
if
not
hasattr
(
self
,
"local_attr"
):
self
.
__dict__
[
"local_attr"
]
=
{}
self
.
__dict__
[
"local_attr"
][
attr
]
=
value
self
.
__dict__
[
"local_attr"
][
attr
]
=
unpack_member_and_external
(
value
)
def
build
(
self
,
mode
,
memo
):
if
self
in
memo
:
...
...
theano/compile/tests/test_module.py
浏览文件 @
3c5882e1
...
...
@@ -14,6 +14,10 @@ import theano
#TODO: add test for module.make(member=init_value)
class
T_module
(
unittest
.
TestCase
):
def
test_empty_module
(
self
):
m
=
Module
()
m
.
make
()
def
test_whats_up_with_submembers
(
self
):
class
Blah
(
Module
):
def
__init__
(
self
,
stepsize
):
...
...
@@ -504,6 +508,7 @@ def test_tuple_members():
class
Temp
(
Module
):
def
__init__
(
self
):
super
(
Temp
,
self
)
.
__init__
()
self
.
a
=
(
1
,
1
)
M
=
Temp
()
assert
isinstance
(
M
.
a
,
tuple
)
...
...
theano/sparse/basic.py
浏览文件 @
3c5882e1
...
...
@@ -871,20 +871,20 @@ sd_csc = StructuredDotCSC()
class
StructuredDotCSR
(
gof
.
Op
):
def
make_node
(
self
,
a_val
,
a_ind
,
a_ptr
,
a_ncols
,
b
):
def
make_node
(
self
,
a_val
,
a_ind
,
a_ptr
,
b
):
assert
a_val
.
type
.
dtype
==
b
.
type
.
dtype
r
=
gof
.
Apply
(
self
,
[
a_val
,
a_ind
,
a_ptr
,
a_ncols
,
b
],
r
=
gof
.
Apply
(
self
,
[
a_val
,
a_ind
,
a_ptr
,
b
],
[
tensor
.
tensor
(
a_val
.
type
.
dtype
,
(
False
,
False
))])
return
r
def
perform
(
self
,
node
,
(
a_val
,
a_ind
,
a_ptr
,
a_ncols
,
b
),
(
out
,)):
def
perform
(
self
,
node
,
(
a_val
,
a_ind
,
a_ptr
,
b
),
(
out
,)):
a
=
sparse
.
csr_matrix
((
a_val
,
a_ind
,
a_ptr
),
(
a_ncols
,
b
.
shape
[
0
]),
copy
=
False
)
(
len
(
a_ptr
)
-
1
,
b
.
shape
[
0
]),
copy
=
True
)
#use view_map before setting this to False
out
[
0
]
=
a
.
dot
(
b
)
assert
_is_dense
(
out
[
0
])
# scipy 0.7 automatically converts to dense
assert
_is_dense
(
out
[
0
])
# scipy 0.7 automatically converts to dense
, but not .6 sometimes
def
c_code
(
self
,
node
,
name
,
(
a_val
,
a_ind
,
a_ptr
,
a_ncols
,
b
),
(
z
,),
sub
):
def
c_code
(
self
,
node
,
name
,
(
a_val
,
a_ind
,
a_ptr
,
b
),
(
z
,),
sub
):
"""
C-implementation of the dot product of the sparse matrix A and matrix B.
@param a_val: non-zero values of the sparse matrix
...
...
@@ -899,7 +899,6 @@ class StructuredDotCSR(gof.Op):
if (
%(a_val)
s->nd != 1) {PyErr_SetString(PyExc_NotImplementedError, "rank(a_val) != 1");
%(fail)
s;}
if (
%(a_ind)
s->nd != 1) {PyErr_SetString(PyExc_NotImplementedError, "rank(a_ind) != 1");
%(fail)
s;}
if (
%(a_ptr)
s->nd != 1) {PyErr_SetString(PyExc_NotImplementedError, "rank(a_ptr) != 1");
%(fail)
s;}
if (
%(a_ncols)
s->nd != 0) {PyErr_SetString(PyExc_NotImplementedError, "rank(ncols) != 0");
%(fail)
s;}
if (
%(b)
s->nd != 2) {PyErr_SetString(PyExc_NotImplementedError, "rank(b) != 2");
%(fail)
s;}
if (
%(a_val)
s->descr->type_num != PyArray_DOUBLE)
...
...
@@ -911,26 +910,20 @@ class StructuredDotCSR(gof.Op):
if (
%(a_ptr)
s->descr->type_num != PyArray_INT32)
{PyErr_SetString(PyExc_NotImplementedError, "a_ptr dtype not INT32");
%(fail)
s;}
if (
%(a_ncols)
s->descr->type_num != PyArray_INT32)
{PyErr_SetString(PyExc_NotImplementedError, "a_ncols dtype not INT32");
%(fail)
s;}
if (
%(b)
s->descr->type_num != PyArray_DOUBLE)
{PyErr_SetString(PyExc_NotImplementedError, "b's dtype not NPY_DOUBLE");
%(fail)
s;}
if (
%(a_val)
s->dimensions[0] !=
%(a_ind)
s->dimensions[0])
{PyErr_SetString(PyExc_NotImplementedError, "a_val and a_ind have different lengths");
%(fail)
s;}
if (
%(a_ptr)
s->dimensions[0] !=
%(b)
s->dimensions[0]+1)
{PyErr_SetString(PyExc_NotImplementedError, "a's number of columns doesn't match b's rows");
%(fail)
s;}
if ((!
%(z)
s)
|| (
%(z)
s->dimensions[0] !=
((npy_int32 *)
%(a_ncols)
s->data)[0])
|| (
%(z)
s->dimensions[1] !=
%(b)
s->dimensions[1])
|| (
%(z)
s->dimensions[0] !=
%(a_ptr)
s->dimensions[0]-1) //a's rows
|| (
%(z)
s->dimensions[1] !=
%(b)
s->dimensions[1])
//b's columns
)
{
if (
%(z)
s) Py_DECREF(
%(z)
s);
npy_intp dims[] = {0,0};
dims[0] =
((npy_int32 *)
%(a_ncols)
s->data)[0]
;
dims[0] =
%(a_ptr)
s->dimensions[0]-1
;
dims[1] =
%(b)
s->dimensions[1];
%(z)
s = (PyArrayObject*) PyArray_SimpleNew(2, dims,
%(b)
s->descr->type_num);
}
...
...
@@ -1013,11 +1006,13 @@ sd_csr = StructuredDotCSR()
def
local_structured_dot
(
node
):
if
node
.
op
==
_structured_dot
:
a
,
b
=
node
.
inputs
if
a
.
type
.
format
in
(
'csc'
,
'csr'
)
:
if
a
.
type
.
format
==
'csc'
:
a_val
,
a_ind
,
a_ptr
,
a_shape
=
csm_properties
(
a
)
a_nsparse
=
a_shape
[
0
]
sd_csx
=
sd_csc
if
a
.
type
.
format
==
'csc'
else
sd_csr
return
[
sd_csx
(
a_val
,
a_ind
,
a_ptr
,
a_nsparse
,
b
)]
return
[
sd_csc
(
a_val
,
a_ind
,
a_ptr
,
a_nsparse
,
b
)]
if
a
.
type
.
format
==
'csr'
:
a_val
,
a_ind
,
a_ptr
,
a_shape
=
csm_properties
(
a
)
return
[
sd_csr
(
a_val
,
a_ind
,
a_ptr
,
b
)]
return
False
register_specialize
(
local_structured_dot
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论