Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
56d152c8
提交
56d152c8
authored
7月 21, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test_elemwise0 passed
上级
5d16a644
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
45 行增加
和
22 行删除
+45
-22
__init__.py
__init__.py
+6
-0
basic_ops.py
basic_ops.py
+0
-0
test_basic_ops.py
tests/test_basic_ops.py
+35
-17
type.py
type.py
+0
-0
type_support.cu
type_support.cu
+4
-5
没有找到文件。
__init__.py
浏览文件 @
56d152c8
from
.type
import
CudaNdarrayType
from
.var
import
(
CudaNdarrayVariable
,
CudaNdarrayConstant
,
CudaNdarraySharedVariable
,
shared_constructor
)
basic_ops.py
浏览文件 @
56d152c8
差异被折叠。
点击展开。
tests/test_basic_ops.py
浏览文件 @
56d152c8
...
...
@@ -4,35 +4,53 @@ from theano import tensor
import
numpy
import
gputensor
as
gpt
import
theano_cuda_ndarray
as
tcn
def
test0
():
def
test
_elemwise
0
():
a
=
gpt
.
gpu_tensor_shared_constructor
(
numpy
.
random
.
rand
(
3
,
4
),
'a'
)
a
=
tcn
.
shared_constructor
(
numpy
.
random
.
rand
(
4
,
4
),
'a'
)
b
=
tensor
.
dmatrix
()
f
=
pfunc
([
b
],
[],
updates
=
[(
a
,
a
+
b
)])
a0
=
a
.
value
*
1.0
f
(
numpy
.
ones
((
3
,
4
)))
print
'BEFORE ADD'
,
a
.
value
f
(
numpy
.
ones
((
4
,
4
)))
print
f
.
maker
.
env
.
toposort
()
print
'AFTER ADD'
,
a
.
value
assert
numpy
.
all
(
a0
+
1.0
==
a
.
value
)
def
test1
():
a
=
gpt
.
gpu_tensor_shared_constructor
(
numpy
.
random
.
rand
(
3
,
4
),
'a'
)
def
test_elemwise1
():
""" Several kinds of elemwise expressions with no broadcasting, non power-of-two shape """
shape
=
(
3
,
4
)
a
=
tcn
.
shared_constructor
(
numpy
.
random
.
rand
(
*
shape
),
'a'
)
b
=
tensor
.
dmatrix
()
f
=
pfunc
([
b
],
[],
updates
=
[(
a
,
a
+
b
)])
for
i
,
node
in
enumerate
(
f
.
maker
.
env
.
toposort
()):
print
'test1 toposort'
,
i
,
node
a0
=
a
.
value
*
1.0
f
(
numpy
.
ones
((
3
,
4
)))
assert
numpy
.
all
(
a0
+
1.0
==
a
.
value
)
f
=
pfunc
([
b
],
[],
updates
=
[(
a
,
a
+
b
*
tensor
.
exp
(
b
**
a
))])
#let debugmode catch any mistakes
f
(
numpy
.
ones
(
shape
))
def
test_elemwise2
():
""" Several kinds of elemwise expressions with dimension permutations """
shape
=
(
3
,
4
,
5
,
6
)
a
=
tcn
.
shared_constructor
(
numpy
.
random
.
rand
(
*
shape
),
'a'
)
b
=
tensor
.
Tensor
(
dtype
=
'float32'
,
broadcastable
=
[
0
]
*
len
(
shape
))()
f
=
pfunc
([
b
],
[],
updates
=
[(
a
,
(
a
+
b
)
.
dimshuffle
([
2
,
0
,
3
,
1
])
*
tensor
.
exp
(
b
**
a
)
.
dimshuffle
([
2
,
0
,
3
,
1
]))])
#let debugmode catch errors
f
(
numpy
.
ones
(
shape
))
def
test_elemwise3
():
""" Several kinds of elemwise expressions with dimension permutations and broadcasting"""
shape
=
(
3
,
4
,
5
,
6
)
a
=
tcn
.
shared_constructor
(
numpy
.
random
.
rand
(
*
shape
),
'a'
)
b
=
tensor
.
dvector
()
f
=
pfunc
([
b
],
[],
updates
=
[(
a
,
(
a
+
b
)
.
dimshuffle
([
2
,
0
,
3
,
1
])
*
tensor
.
exp
(
1
+
b
**
a
)
.
dimshuffle
([
2
,
0
,
3
,
1
]))])
#let debugmode catch errors
f
(
numpy
.
ones
(
6
))
type.py
浏览文件 @
56d152c8
差异被折叠。
点击展开。
type_support.cu
浏览文件 @
56d152c8
...
...
@@ -7,15 +7,14 @@
#define DECL(s) static PyObject * s(PyObject * self, PyObject *args)
static PyObject *
filter(PyObject* self, PyObject *args) // args = (data,
typenum,
broadcastable, strict)
filter(PyObject* self, PyObject *args) // args = (data, broadcastable, strict)
{
PyObject *py_data=NULL;
PyArrayObject * data = NULL;
int dtype_typenum=-1;
int strict = 0;
PyObject * broadcastable=NULL;
if (!PyArg_ParseTuple(args, "O
iOi", &py_data, &dtype_typenum
, &broadcastable, &strict)) return NULL;
if (!PyArg_ParseTuple(args, "O
Oi", &py_data
, &broadcastable, &strict)) return NULL;
if (!PyTuple_Check(broadcastable)){
PyErr_SetString(PyExc_TypeError, "broadcastable arg should be a tuple of int.");
...
...
@@ -99,9 +98,9 @@ static PyMethodDef MyMethods[] = {
PyMODINIT_FUNC
init
_theano_cuda_ndarray
(void)
init
type_support
(void)
{
(void) Py_InitModule("
_theano_cuda_ndarray
", MyMethods);
(void) Py_InitModule("
type_support
", MyMethods);
import_array();
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论