Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
909aa3d7
提交
909aa3d7
authored
8月 10, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
numpydoc for theano/sandbox/cuda/type.py
上级
49af6efe
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
62 行增加
和
25 行删除
+62
-25
type.py
theano/sandbox/cuda/type.py
+62
-25
没有找到文件。
theano/sandbox/cuda/type.py
浏览文件 @
909aa3d7
"""Provide CudaNdarrayType
"""
Provide CudaNdarrayType.
"""
from
__future__
import
print_function
import
os
...
...
@@ -31,36 +33,47 @@ class CudaNdarrayType(Type):
dtype
=
'float32'
Variable
=
None
""" This will be set to the Variable type corresponding to this class.
"""
This will be set to the Variable type corresponding to this class.
That variable type is `CudaNdarrayVariable` defined in the
``var.py`` file beside this one.
:note: The var file depends on the file basic_ops.py, which
depends on this file. A cyclic dependency is avoided by not
hardcoding ``Variable = CudaNdarrayVariable``.
Notes
-----
The var file depends on the file basic_ops.py, which depends on this file.
A cyclic dependency is avoided by not hardcoding
``Variable = CudaNdarrayVariable``.
"""
Constant
=
None
""" This will be set to `CudaNdarrayConstant` defined in ``var.py``
"""
This will be set to `CudaNdarrayConstant` defined in ``var.py``.
:note:
Notes
-----
The var file depends on the file basic_ops.py, which depends on this file.
A cyclic dependency is avoided by not hardcoding this class.
"""
SharedVariable
=
None
""" This will be set to `CudaNdarraySharedVariable` defined in ``var.py``
"""
This will be set to `CudaNdarraySharedVariable` defined in ``var.py``.
:note:
Notes
-----
The var file depends on the file basic_ops.py, which depends on this file.
A cyclic dependency is avoided by not hardcoding this class.
"""
if
cuda
is
not
None
:
value_zeros
=
staticmethod
(
cuda
.
CudaNdarray
.
zeros
)
"""
Create an CudaNdarray full of 0 values
Create an CudaNdarray full of 0 values.
"""
def
__init__
(
self
,
broadcastable
,
name
=
None
,
dtype
=
None
):
...
...
@@ -120,11 +133,13 @@ class CudaNdarrayType(Type):
data
)
def
filter_variable
(
self
,
other
,
allow_convert
=
True
):
"""Convert a Variable into a CudaNdarrayType, if compatible.
"""
Convert a Variable into a CudaNdarrayType, if compatible.
This Variable should either already be a CudaNdarrayType, or be
a TensorType. It has to have the right number of dimensions,
broadcastable pattern, and dtype.
"""
if
hasattr
(
other
,
'_as_CudaNdarrayVariable'
):
other
=
other
.
_as_CudaNdarrayVariable
()
...
...
@@ -209,10 +224,12 @@ class CudaNdarrayType(Type):
)
def
dtype_specs
(
self
):
"""Return a tuple (python type, c type, numpy typenum) that
corresponds to self.dtype.
"""
Return a tuple (python type, c type, numpy typenum) that corresponds
to self.dtype.
This function is used internally as part of C code generation.
"""
# TODO: add more type correspondances for e.g. int32, int64, float32,
# complex64, etc.
...
...
@@ -236,7 +253,10 @@ class CudaNdarrayType(Type):
self
.
__class__
.
__name__
,
self
.
dtype
))
def
__eq__
(
self
,
other
):
"""Compare True iff other is the same kind of CudaNdarrayType"""
"""
Compare True iff other is the same kind of CudaNdarrayType.
"""
return
(
type
(
self
)
==
type
(
other
)
and
other
.
broadcastable
==
self
.
broadcastable
)
...
...
@@ -248,12 +268,16 @@ class CudaNdarrayType(Type):
return
theano
.
tensor
.
patternbroadcast
(
var
,
self
.
broadcastable
)
def
__hash__
(
self
):
"""Hash equal for same kinds of CudaNdarrayType"""
"""
Hash equal for same kinds of CudaNdarrayType.
"""
return
hash
(
type
(
self
))
^
hash
(
self
.
broadcastable
)
ndim
=
property
(
lambda
self
:
len
(
self
.
broadcastable
),
doc
=
"number of dimensions"
)
"""Number of dimensions
"""
Number of dimensions.
This read-only property is the preferred way to get the number of
dimensions of a `CudaNdarrayType`.
...
...
@@ -261,12 +285,14 @@ class CudaNdarrayType(Type):
"""
def
make_variable
(
self
,
name
=
None
):
"""Return a `TensorVariable` of this type
"""
Return a `TensorVariable` of this type.
:Parameters:
- `name`: str
A pretty name to identify this `Variable` when printing and
debugging
Parameters
----------
name : str
A pretty name to identify this `Variable` when printing and
debugging.
"""
return
self
.
Variable
(
self
,
name
=
name
)
...
...
@@ -381,7 +407,9 @@ class CudaNdarrayType(Type):
return
sio
.
getvalue
()
def
c_extract_out
(
self
,
name
,
sub
,
check_input
=
True
,
check_broadcast
=
True
):
""" To allow the hack to skip check_broadcast.
"""
To allow the hack to skip check_broadcast.
"""
return
"""
if (py_
%(name)
s == Py_None)
...
...
@@ -411,7 +439,10 @@ class CudaNdarrayType(Type):
"""
%
locals
()
def
c_sync
(
self
,
name
,
sub
):
"""Override `CLinkerOp.c_sync` """
"""
Override `CLinkerOp.c_sync`.
"""
return
"""
//std::cerr << "sync
\\
n";
if (NULL ==
%(name)
s) {
...
...
@@ -433,11 +464,17 @@ class CudaNdarrayType(Type):
"""
%
locals
()
def
c_headers
(
self
):
"""Override `CLinkerOp.c_headers` """
"""
Override `CLinkerOp.c_headers`.
"""
return
[
'cuda_ndarray.cuh'
]
def
c_header_dirs
(
self
):
"""Override `CLinkerOp.c_headers` """
"""
Override `CLinkerOp.c_headers`.
"""
ret
=
[
os
.
path
.
dirname
(
cuda_ndarray
.
__file__
)]
cuda_root
=
config
.
cuda
.
root
if
cuda_root
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论