Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3f16fbc5
提交
3f16fbc5
authored
11月 09, 2012
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge var and type, makes it easier not to misuse.
上级
ed996e17
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
83 行增加
和
95 行删除
+83
-95
__init__.py
theano/sandbox/gpuarray/__init__.py
+2
-3
globals.py
theano/sandbox/gpuarray/globals.py
+2
-0
type.py
theano/sandbox/gpuarray/type.py
+79
-7
var.py
theano/sandbox/gpuarray/var.py
+0
-85
没有找到文件。
theano/sandbox/gpuarray/__init__.py
浏览文件 @
3f16fbc5
...
@@ -27,9 +27,8 @@ AddConfigVar('gpuarray.init_device',
...
@@ -27,9 +27,8 @@ AddConfigVar('gpuarray.init_device',
# This is for documentation not to depend on the availability of pygpu
# This is for documentation not to depend on the availability of pygpu
from
type
import
GpuArrayType
from
type
import
(
GpuArrayType
,
GpuArrayVariable
,
GpuArrayConstant
,
from
var
import
(
GpuArrayVariable
,
GpuArrayConstant
,
GpuArraySharedVariable
,
GpuArraySharedVariable
,
gpuarray_shared_constructor
)
gpuarray_shared_constructor
)
def
init_dev
(
dev
):
def
init_dev
(
dev
):
...
...
theano/sandbox/gpuarray/globals.py
浏览文件 @
3f16fbc5
# This modules serves to stuff global values (like kind and context)
# This modules serves to stuff global values (like kind and context)
kind
=
None
context
=
None
theano/sandbox/gpuarray/type.py
浏览文件 @
3f16fbc5
import
copy_reg
import
numpy
import
numpy
import
theano
import
theano
from
theano
import
Type
,
Variable
,
tensor
,
config
,
scalar
from
theano
import
Type
,
Variable
,
Constant
,
tensor
,
config
,
scalar
from
theano.compile
import
SharedVariable
# Make sure this is importable even if pygpu is absent
# Make sure this is importable even if pygpu is absent
# (it will not work though)
# (it will not work though)
...
@@ -11,14 +10,11 @@ try:
...
@@ -11,14 +10,11 @@ try:
import
pygpu
import
pygpu
from
pygpu
import
gpuarray
from
pygpu
import
gpuarray
from
pygpu.elemwise
import
compare
from
pygpu.elemwise
import
compare
from
basic_ops
import
host_from_gpu
,
gpu_from_host
except
ImportError
:
except
ImportError
:
pass
pass
class
GpuArrayType
(
Type
):
class
GpuArrayType
(
Type
):
Variable
=
None
Constant
=
None
SharedVariable
=
None
def
value_zeros
(
self
,
shape
):
def
value_zeros
(
self
,
shape
):
return
pygpu
.
gpuarray
.
zeros
(
shape
,
dtype
=
self
.
typecode
,
kind
=
self
.
kind
,
return
pygpu
.
gpuarray
.
zeros
(
shape
,
dtype
=
self
.
typecode
,
kind
=
self
.
kind
,
context
=
self
.
context
)
context
=
self
.
context
)
...
@@ -30,6 +26,9 @@ class GpuArrayType(Type):
...
@@ -30,6 +26,9 @@ class GpuArrayType(Type):
kind
=
globals
.
kind
kind
=
globals
.
kind
if
context
is
None
:
if
context
is
None
:
context
=
globals
.
context
context
=
globals
.
context
# In case this was not provided and no global value is available
if
kind
is
None
:
raise
RuntimeError
(
"pygpu is not initialized"
)
self
.
dtype
=
str
(
dtype
)
self
.
dtype
=
str
(
dtype
)
self
.
broadcastable
=
tuple
(
bool
(
b
)
for
b
in
broadcastable
)
self
.
broadcastable
=
tuple
(
bool
(
b
)
for
b
in
broadcastable
)
self
.
ndim
=
len
(
self
.
broadcastable
)
self
.
ndim
=
len
(
self
.
broadcastable
)
...
@@ -103,3 +102,76 @@ class GpuArrayType(Type):
...
@@ -103,3 +102,76 @@ class GpuArrayType(Type):
def
__str__
(
self
):
def
__str__
(
self
):
return
"GpuArray<
%
s>"
%
self
.
dtype
return
"GpuArray<
%
s>"
%
self
.
dtype
class
_operators
(
tensor
.
basic
.
_tensor_py_operators
):
def
_as_TensorVariable
(
self
):
return
host_from_gpu
(
self
)
def
_as_GpuArrayVariable
(
self
):
return
self
dtype
=
property
(
lambda
s
:
s
.
type
.
dtype
)
broadcastable
=
property
(
lambda
s
:
s
.
type
.
broadcastable
)
ndim
=
property
(
lambda
s
:
s
.
type
.
ndim
)
class
GpuArrayVariable
(
_operators
,
Variable
):
pass
GpuArrayType
.
Variable
=
GpuArrayVariable
class
GpuArraySignature
(
tensor
.
basic
.
TensorConstantSignature
):
pass
# might do something better if we can run the sum on the
# GPU, but for now this will suffice.
class
GpuArrayConstant
(
_operators
,
Constant
):
def
signature
(
self
):
return
GpuArraySignature
((
self
.
type
,
numpy
.
asarray
(
self
.
data
)))
def
__str__
(
self
):
if
self
.
name
is
not
None
:
return
self
.
name
return
"GpuArrayConstant{
%
s}"
%
numpy
.
asarray
(
self
.
data
)
GpuArrayType
.
Constant
=
GpuArrayConstant
class
GpuArraySharedVariable
(
_operators
,
SharedVariable
):
def
get_value
(
self
,
borrow
=
False
,
return_internal_type
=
False
):
if
return_internal_type
:
if
borrow
:
return
self
.
container
.
value
else
:
return
self
.
container
.
value
.
copy
()
else
:
return
numpy
.
asarray
(
self
.
container
.
value
)
def
set_value
(
self
,
value
,
borrow
=
False
):
self
.
container
.
value
=
pygpu
.
gpuarray
.
array
(
value
,
copy
=
(
not
borrow
))
def
__getitem__
(
self
,
*
args
):
return
_operators
.
__getitem__
(
self
,
*
args
)
GpuArrayType
.
SharedVariable
=
GpuArraySharedVariable
def
gpuarray_shared_constructor
(
value
,
name
=
None
,
strict
=
False
,
allow_downcast
=
None
,
borrow
=
False
,
broadcastable
=
None
,
kind
=
None
,
context
=
None
):
"""SharedVariable constructor for GpuArrayType"""
if
not
isinstance
(
value
,
(
numpy
.
ndarray
,
pygpu
.
gpuarray
.
GpuArray
)):
raise
TypeError
(
'ndarray or GpuArray required'
)
if
broadcastable
is
None
:
broadcastable
=
(
False
,)
*
value
.
ndim
type
=
GpuArrayType
(
value
.
dtype
,
broadcastable
,
kind
=
kind
,
context
=
context
)
deviceval
=
pygpu
.
gpuarray
.
array
(
value
,
copy
=
(
not
borrow
),
kind
=
type
.
kind
,
context
=
type
.
context
)
return
GpuArraySharedVariable
(
type
=
type
,
value
=
deviceval
,
name
=
name
,
strict
=
strict
)
theano/sandbox/gpuarray/var.py
deleted
100644 → 0
浏览文件 @
ed996e17
import
numpy
import
theano
from
theano
import
Variable
,
Constant
,
tensor
from
theano.compile
import
SharedVariable
try
:
# Let this be importable for documentation purposes
import
pygpu.gpuarray
from
basic_ops
import
host_from_gpu
,
gpu_from_host
except
ImportError
:
pass
from
type
import
GpuArrayType
class
_operators
(
tensor
.
basic
.
_tensor_py_operators
):
def
_as_TensorVariable
(
self
):
return
host_from_gpu
(
self
)
# XXX: don't forget to add _as_CudaNdarrayVariable() when we
# figure out how to do it.
def
_as_GpuArrayVariable
(
self
):
return
self
dtype
=
property
(
lambda
s
:
s
.
type
.
dtype
)
broadcastable
=
property
(
lambda
s
:
s
.
type
.
broadcastable
)
ndim
=
property
(
lambda
s
:
s
.
type
.
ndim
)
class
GpuArrayVariable
(
_operators
,
Variable
):
pass
GpuArrayType
.
Variable
=
GpuArrayVariable
class
GpuArrayConstant
(
_operators
,
Constant
):
def
signature
(
self
):
return
GpuArraySignature
((
self
.
type
,
numpy
.
asarray
(
self
.
data
)))
def
__str__
(
self
):
if
self
.
name
is
not
None
:
return
self
.
name
return
"GpuArrayConstant{
%
s}"
%
numpy
.
asarray
(
self
.
data
)
GpuArrayType
.
Constant
=
GpuArrayConstant
class
GpuArraySharedVariable
(
_operators
,
SharedVariable
):
def
get_value
(
self
,
borrow
=
False
,
return_internal_type
=
False
):
if
return_internal_type
:
if
borrow
:
return
self
.
container
.
value
else
:
return
self
.
container
.
value
.
copy
()
else
:
return
numpy
.
asarray
(
self
.
container
.
value
)
def
set_value
(
self
,
value
,
borrow
=
False
):
self
.
container
.
value
=
pygpu
.
gpuarray
.
array
(
value
,
copy
=
(
not
borrow
))
def
__getitem__
(
self
,
*
args
):
return
_operators
.
__getitem__
(
self
,
*
args
)
GpuArrayType
.
SharedVariable
=
GpuArraySharedVariable
def
gpuarray_shared_constructor
(
value
,
name
=
None
,
strict
=
False
,
allow_downcast
=
None
,
borrow
=
False
,
broadcastable
=
None
):
"""SharedVariable constructor for GpuArrayType"""
if
globals
.
kind
is
None
:
raise
RuntimeError
(
"pygpu is not initialized"
)
if
not
isinstance
(
value
,
(
numpy
.
ndarray
,
pygpu
.
gpuarray
.
GpuArray
)):
raise
TypeError
(
'ndarray or GpuArray required'
)
if
broadcastable
is
None
:
broadcastable
=
(
False
,)
*
value
.
ndim
type
=
GpuArrayType
(
value
.
dtype
,
broadcastable
)
deviceval
=
pygpu
.
gpuarray
.
array
(
value
,
copy
=
(
not
borrow
))
return
GpuArraySharedVariable
(
type
=
type
,
value
=
deviceval
,
name
=
name
,
strict
=
strict
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论