Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5bc35bc2
提交
5bc35bc2
authored
10月 13, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a transfer() method to explicit data transfers in the graph easy.
上级
9cbdc34b
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
72 行增加
和
3 行删除
+72
-3
basic.txt
doc/library/tensor/basic.txt
+2
-1
__init__.py
theano/sandbox/cuda/__init__.py
+8
-0
__init__.py
theano/sandbox/gpuarray/__init__.py
+12
-0
basic.py
theano/tensor/basic.py
+36
-1
var.py
theano/tensor/var.py
+14
-1
没有找到文件。
doc/library/tensor/basic.txt
浏览文件 @
5bc35bc2
...
@@ -427,7 +427,8 @@ TensorVariable
...
@@ -427,7 +427,8 @@ TensorVariable
you'll want to call.
you'll want to call.
.. class:: _tensor_py_operators(object)
.. autoclass:: _tensor_py_operators
:members:
This mix-in class adds convenient attributes, methods, and support
This mix-in class adds convenient attributes, methods, and support
to TensorVariable, TensorConstant and TensorSharedVariable for
to TensorVariable, TensorConstant and TensorSharedVariable for
...
...
theano/sandbox/cuda/__init__.py
浏览文件 @
5bc35bc2
...
@@ -17,6 +17,8 @@ from theano.configparser import (
...
@@ -17,6 +17,8 @@ from theano.configparser import (
config
,
AddConfigVar
,
BoolParam
,
FloatParam
,
StrParam
)
config
,
AddConfigVar
,
BoolParam
,
FloatParam
,
StrParam
)
from
.
import
nvcc_compiler
from
.
import
nvcc_compiler
from
theano.tensor.basic
import
register_transfer
# ignore_newtrees is to speed the optimization as this is the pattern
# ignore_newtrees is to speed the optimization as this is the pattern
# we use for optimization. Otherwise, we can iterate 100s of time on
# we use for optimization. Otherwise, we can iterate 100s of time on
# the graph and apply only a few optimizations each time.
# the graph and apply only a few optimizations each time.
...
@@ -327,6 +329,12 @@ if cuda_available:
...
@@ -327,6 +329,12 @@ if cuda_available:
from
.
import
opt
,
dnn
from
.
import
opt
,
dnn
from
.rng_curand
import
CURAND_RandomStreams
from
.rng_curand
import
CURAND_RandomStreams
def
transfer
(
x
,
target
):
if
target
==
'gpu'
:
return
as_cuda_ndarray_variable
(
x
)
register_transfer
(
transfer
)
def
use
(
device
,
def
use
(
device
,
force
=
False
,
force
=
False
,
...
...
theano/sandbox/gpuarray/__init__.py
浏览文件 @
5bc35bc2
...
@@ -6,6 +6,8 @@ import theano
...
@@ -6,6 +6,8 @@ import theano
from
theano.configparser
import
config
,
AddConfigVar
,
BoolParam
from
theano.configparser
import
config
,
AddConfigVar
,
BoolParam
from
theano.compile
import
optdb
from
theano.compile
import
optdb
from
theano.tensor.basic
import
register_transfer
_logger_name
=
'theano.sandbox.gpuarray'
_logger_name
=
'theano.sandbox.gpuarray'
_logger
=
logging
.
getLogger
(
_logger_name
)
_logger
=
logging
.
getLogger
(
_logger_name
)
...
@@ -23,8 +25,18 @@ except ImportError:
...
@@ -23,8 +25,18 @@ except ImportError:
from
.type
import
(
GpuArrayType
,
GpuArrayVariable
,
GpuArrayConstant
,
from
.type
import
(
GpuArrayType
,
GpuArrayVariable
,
GpuArrayConstant
,
GpuArraySharedVariable
,
gpuarray_shared_constructor
,
GpuArraySharedVariable
,
gpuarray_shared_constructor
,
reg_context
)
reg_context
)
from
.basic
import
as_gpuarray_variable
from
.
import
opt
,
nerv
from
.
import
opt
,
nerv
def
transfer
(
x
,
target
):
try
:
get_context
(
target
)
return
as_gpuarray_variable
(
x
,
target
)
except
ContextNotDefined
:
pass
register_transfer
(
transfer
)
def
init_dev
(
dev
,
name
=
None
):
def
init_dev
(
dev
,
name
=
None
):
if
pygpu
.
gpuarray
.
api_version
()
!=
(
-
10000
,
0
):
if
pygpu
.
gpuarray
.
api_version
()
!=
(
-
10000
,
0
):
...
...
theano/tensor/basic.py
浏览文件 @
5bc35bc2
...
@@ -2844,11 +2844,46 @@ class Alloc(gof.Op):
...
@@ -2844,11 +2844,46 @@ class Alloc(gof.Op):
return
False
return
False
return
True
return
True
alloc
=
Alloc
()
alloc
=
Alloc
()
pprint
.
assign
(
alloc
,
printing
.
FunctionPrinter
(
'alloc'
))
pprint
.
assign
(
alloc
,
printing
.
FunctionPrinter
(
'alloc'
))
def
transfer
(
var
,
target
):
"""
Return a version of `var` transferred to `target`.
`cpu` mean a TensorType (on the CPU). Other types may define
additional targets.
Parameters
----------
var : variable
A theano variable
target : str
The target of the transfer
"""
if
target
==
'cpu'
:
return
as_tensor_variable
(
var
)
else
:
for
trans
in
transfer
.
_others
:
res
=
trans
(
var
,
target
)
if
res
is
not
None
:
return
res
raise
ValueError
(
"Can't transfer to target
%
s"
%
(
target
,))
transfer
.
_others
=
[]
def
register_transfer
(
fn
):
"""
Register a transfer function for alternative targets.
Parameters
----------
fn : callable
"""
transfer
.
_others
.
append
(
fn
)
"""Create a duplicate of `a` (with duplicated storage)"""
"""Create a duplicate of `a` (with duplicated storage)"""
tensor_copy
=
elemwise
.
Elemwise
(
scal
.
identity
)
tensor_copy
=
elemwise
.
Elemwise
(
scal
.
identity
)
pprint
.
assign
(
tensor_copy
,
printing
.
IgnorePrinter
())
pprint
.
assign
(
tensor_copy
,
printing
.
IgnorePrinter
())
...
...
theano/tensor/var.py
浏览文件 @
5bc35bc2
...
@@ -29,7 +29,7 @@ class AsTensorError(TypeError):
...
@@ -29,7 +29,7 @@ class AsTensorError(TypeError):
pass
pass
class
_tensor_py_operators
:
class
_tensor_py_operators
(
object
)
:
# UNARY
# UNARY
def
__abs__
(
self
):
def
__abs__
(
self
):
return
theano
.
tensor
.
basic
.
abs_
(
self
)
return
theano
.
tensor
.
basic
.
abs_
(
self
)
...
@@ -369,6 +369,19 @@ class _tensor_py_operators:
...
@@ -369,6 +369,19 @@ class _tensor_py_operators:
def
diagonal
(
self
,
offset
=
0
,
axis1
=
0
,
axis2
=
1
):
def
diagonal
(
self
,
offset
=
0
,
axis1
=
0
,
axis2
=
1
):
return
theano
.
tensor
.
basic
.
diagonal
(
self
,
offset
,
axis1
,
axis2
)
return
theano
.
tensor
.
basic
.
diagonal
(
self
,
offset
,
axis1
,
axis2
)
# Transfer the data to another device
def
transfer
(
self
,
target
):
"""
If `target` is `'cpu'` this will transfer to a TensorType (if
not already one). Other types may define additional targets.
Paramters
---------
target : str
The desired location of the output variable
"""
return
theano
.
tensor
.
transfer
(
self
,
target
)
# Elemwise
# Elemwise
def
arccos
(
self
):
def
arccos
(
self
):
return
theano
.
tensor
.
arccos
(
self
)
return
theano
.
tensor
.
arccos
(
self
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论