Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8e512ce0
提交
8e512ce0
authored
9月 19, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow numpy.asarray(cuda_ndarray, dtype=...)
上级
dcd43ac9
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
44 行增加
和
3 行删除
+44
-3
cuda_ndarray.cu
theano/sandbox/cuda/cuda_ndarray.cu
+32
-2
cuda_ndarray.cuh
theano/sandbox/cuda/cuda_ndarray.cuh
+1
-1
test_cuda_ndarray.py
theano/sandbox/cuda/tests/test_cuda_ndarray.py
+11
-0
没有找到文件。
theano/sandbox/cuda/cuda_ndarray.cu
浏览文件 @
8e512ce0
...
@@ -348,8 +348,38 @@ static PyMemberDef CudaNdarray_members[] =
...
@@ -348,8 +348,38 @@ static PyMemberDef CudaNdarray_members[] =
{
NULL
}
/* Sentinel */
{
NULL
}
/* Sentinel */
};
};
PyObject
*
CudaNdarray_CreateArrayObj
(
CudaNdarray
*
self
)
PyObject
*
CudaNdarray_CreateArrayObj
(
CudaNdarray
*
self
,
PyObject
*
args
)
{
{
PyObject
*
dtype
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"|O"
,
&
dtype
))
return
NULL
;
if
(
dtype
)
{
PyArray_Descr
*
dtype2
;
// PyArray_DescrConverter try to convert anything to a PyArray_Descr.
if
(
!
PyArray_DescrConverter
(
dtype
,
&
dtype2
))
{
PyObject
*
str
=
PyObject_Repr
(
dtype
);
PyErr_Format
(
PyExc_TypeError
,
"CudaNdarray dtype parameter not understood: %s"
,
PyString_AsString
(
str
)
);
Py_CLEAR
(
str
);
return
NULL
;
}
int
typeNum
=
dtype2
->
type_num
;
Py_DECREF
(
dtype2
);
if
(
typeNum
!=
NPY_FLOAT32
)
{
PyObject
*
str
=
PyObject_Repr
(
dtype
);
PyErr_Format
(
PyExc_TypeError
,
"CudaNdarray support only support float32 dtype, provided: %d"
,
typeNum
);
Py_CLEAR
(
str
);
return
NULL
;
}
}
int
verbose
=
0
;
int
verbose
=
0
;
if
(
self
->
nd
>=
0
&&
CudaNdarray_SIZE
(
self
)
==
0
){
if
(
self
->
nd
>=
0
&&
CudaNdarray_SIZE
(
self
)
==
0
){
npy_intp
*
npydims
=
(
npy_intp
*
)
malloc
(
self
->
nd
*
sizeof
(
npy_intp
));
npy_intp
*
npydims
=
(
npy_intp
*
)
malloc
(
self
->
nd
*
sizeof
(
npy_intp
));
...
@@ -1217,7 +1247,7 @@ CudaNdarray_exp(CudaNdarray* self)
...
@@ -1217,7 +1247,7 @@ CudaNdarray_exp(CudaNdarray* self)
static
PyMethodDef
CudaNdarray_methods
[]
=
static
PyMethodDef
CudaNdarray_methods
[]
=
{
{
{
"__array__"
,
{
"__array__"
,
(
PyCFunction
)
CudaNdarray_CreateArrayObj
,
METH_
NO
ARGS
,
(
PyCFunction
)
CudaNdarray_CreateArrayObj
,
METH_
VAR
ARGS
,
"Copy from the device to a numpy ndarray"
},
"Copy from the device to a numpy ndarray"
},
{
"__copy__"
,
{
"__copy__"
,
(
PyCFunction
)
CudaNdarray_View
,
METH_NOARGS
,
(
PyCFunction
)
CudaNdarray_View
,
METH_NOARGS
,
...
...
theano/sandbox/cuda/cuda_ndarray.cuh
浏览文件 @
8e512ce0
...
@@ -473,7 +473,7 @@ DllExport int CudaNdarray_CopyFromCudaNdarray(CudaNdarray * self,
...
@@ -473,7 +473,7 @@ DllExport int CudaNdarray_CopyFromCudaNdarray(CudaNdarray * self,
* Transfer the contents of CudaNdarray `self` to a new numpy ndarray.
* Transfer the contents of CudaNdarray `self` to a new numpy ndarray.
*/
*/
DllExport
PyObject
*
DllExport
PyObject
*
CudaNdarray_CreateArrayObj
(
CudaNdarray
*
self
);
CudaNdarray_CreateArrayObj
(
CudaNdarray
*
self
,
PyObject
*
args
=
NULL
);
DllExport
PyObject
*
DllExport
PyObject
*
CudaNdarray_ZEROS
(
int
n
,
int
*
dims
);
CudaNdarray_ZEROS
(
int
n
,
int
*
dims
);
...
...
theano/sandbox/cuda/tests/test_cuda_ndarray.py
浏览文件 @
8e512ce0
...
@@ -38,6 +38,17 @@ def test_host_to_device():
...
@@ -38,6 +38,17 @@ def test_host_to_device():
c
=
numpy
.
asarray
(
b
)
c
=
numpy
.
asarray
(
b
)
assert
numpy
.
all
(
a
==
c
)
assert
numpy
.
all
(
a
==
c
)
# test with float32 dtype
d
=
numpy
.
asarray
(
b
,
dtype
=
'float32'
)
assert
numpy
.
all
(
a
==
d
)
# test with not float32 dtype
try
:
numpy
.
asarray
(
b
,
dtype
=
'int8'
)
assert
False
except
TypeError
:
pass
def
test_add_iadd_idiv
():
def
test_add_iadd_idiv
():
for
shapes
in
(
for
shapes
in
(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论