Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
933aa55b
提交
933aa55b
authored
6月 04, 2008
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
差异文件
Automated merge with
ssh://projects@lgcm.iro.umontreal.ca/hg/theano
上级
b538e245
705dfaaf
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
23 行增加
和
10 行删除
+23
-10
compile.py
compile.py
+13
-7
elemwise.py
elemwise.py
+6
-0
scalar.py
scalar.py
+2
-2
tensor.py
tensor.py
+2
-1
没有找到文件。
compile.py
浏览文件 @
933aa55b
...
@@ -70,15 +70,17 @@ def cloned_env(inputs, outputs):
...
@@ -70,15 +70,17 @@ def cloned_env(inputs, outputs):
env
=
gof
.
env
.
Env
(
inputs
,
outputs
)
env
=
gof
.
env
.
Env
(
inputs
,
outputs
)
return
env
return
env
def
std_env
(
inputs
,
outputs
,
disown_inputs
=
False
):
def
std_env
(
inputs
,
outputs
,
disown_inputs
=
False
,
use_destroy_handler
=
True
):
inputs
,
outputs
=
gof
.
graph
.
clone
(
inputs
,
outputs
)
inputs
,
outputs
=
gof
.
graph
.
clone
(
inputs
,
outputs
)
_mark_indestructible
(
outputs
)
_mark_indestructible
(
outputs
)
env
=
gof
.
env
.
Env
(
inputs
,
outputs
)
env
=
gof
.
env
.
Env
(
inputs
,
outputs
)
env
.
extend
(
gof
.
DestroyHandler
())
if
use_destroy_handler
:
env
.
extend
(
gof
.
DestroyHandler
())
env
.
extend
(
gof
.
ReplaceValidate
())
env
.
extend
(
gof
.
ReplaceValidate
())
env
.
validate
()
env
.
validate
()
for
input
in
inputs
:
for
input
in
inputs
:
input
.
destroyed_by_user
=
len
(
env
.
destroyers
(
input
))
!=
0
input
.
destroyed_by_user
=
use_destroy_handler
and
len
(
env
.
destroyers
(
input
))
!=
0
if
not
input
.
destroyed_by_user
and
not
disown_inputs
:
if
not
input
.
destroyed_by_user
and
not
disown_inputs
:
# prevent optimizations from destroying the inputs
# prevent optimizations from destroying the inputs
input
.
tag
.
indestructible
=
True
input
.
tag
.
indestructible
=
True
...
@@ -97,13 +99,15 @@ predefined_linkers = {
...
@@ -97,13 +99,15 @@ predefined_linkers = {
class
FunctionFactory
:
class
FunctionFactory
:
def
__init__
(
self
,
inputs
,
outputs
,
linker
=
'py'
,
optimizer
=
std_opt
,
borrow_outputs
=
False
,
disown_inputs
=
False
):
def
__init__
(
self
,
inputs
,
outputs
,
linker
=
'py'
,
optimizer
=
std_opt
,
borrow_outputs
=
False
,
disown_inputs
=
False
,
use_destroy_handler
=
True
):
if
len
(
inputs
)
!=
len
(
set
(
inputs
)):
if
len
(
inputs
)
!=
len
(
set
(
inputs
)):
print
>>
sys
.
stderr
,
"Warning: duplicate inputs"
print
>>
sys
.
stderr
,
"Warning: duplicate inputs"
for
r
in
list
(
inputs
)
+
list
(
outputs
):
for
r
in
list
(
inputs
)
+
list
(
outputs
):
if
not
isinstance
(
r
,
gof
.
Result
):
if
not
isinstance
(
r
,
gof
.
Result
):
raise
TypeError
(
"All inputs and outputs to FunctionFactory should be Result instances. Received:"
,
type
(
r
),
r
)
raise
TypeError
(
"All inputs and outputs to FunctionFactory should be Result instances. Received:"
,
type
(
r
),
r
)
env
=
std_env
(
inputs
,
outputs
,
disown_inputs
=
disown_inputs
)
env
=
std_env
(
inputs
,
outputs
,
disown_inputs
=
disown_inputs
,
use_destroy_handler
=
use_destroy_handler
)
if
None
is
not
optimizer
:
if
None
is
not
optimizer
:
optimizer
(
env
)
optimizer
(
env
)
env
.
validate
()
env
.
validate
()
...
@@ -144,13 +148,15 @@ def function(inputs,
...
@@ -144,13 +148,15 @@ def function(inputs,
disown_inputs
=
False
,
disown_inputs
=
False
,
profiler
=
None
,
profiler
=
None
,
unpack_single
=
True
,
unpack_single
=
True
,
strict
=
'if_destroyed'
):
strict
=
'if_destroyed'
,
use_destroy_handler
=
True
):
ff
=
FunctionFactory
(
inputs
,
ff
=
FunctionFactory
(
inputs
,
outputs
,
outputs
,
linker
=
linker
,
linker
=
linker
,
optimizer
=
optimizer
,
optimizer
=
optimizer
,
borrow_outputs
=
borrow_outputs
,
borrow_outputs
=
borrow_outputs
,
disown_inputs
=
disown_inputs
)
disown_inputs
=
disown_inputs
,
use_destroy_handler
=
use_destroy_handler
)
return
ff
.
create
(
profiler
=
profiler
,
return
ff
.
create
(
profiler
=
profiler
,
unpack_single
=
unpack_single
,
unpack_single
=
unpack_single
,
strict
=
strict
)
strict
=
strict
)
...
...
elemwise.py
浏览文件 @
933aa55b
...
@@ -272,6 +272,12 @@ class Elemwise(Op):
...
@@ -272,6 +272,12 @@ class Elemwise(Op):
outputs
=
[
Tensor
(
dtype
=
dtype
,
broadcastable
=
broadcastable
)()
for
dtype
,
broadcastable
in
zip
(
out_dtypes
,
out_broadcastables
)]
outputs
=
[
Tensor
(
dtype
=
dtype
,
broadcastable
=
broadcastable
)()
for
dtype
,
broadcastable
in
zip
(
out_dtypes
,
out_broadcastables
)]
return
Apply
(
self
,
inputs
,
outputs
)
return
Apply
(
self
,
inputs
,
outputs
)
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
self
.
scalar_op
==
other
.
scalar_op
and
self
.
inplace_pattern
==
other
.
inplace_pattern
def
__hash__
(
self
):
return
hash
(
self
.
scalar_op
)
^
hash
(
self
.
inplace_pattern
)
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
name
is
None
:
if
self
.
name
is
None
:
if
self
.
inplace_pattern
:
if
self
.
inplace_pattern
:
...
...
scalar.py
浏览文件 @
933aa55b
...
@@ -670,7 +670,7 @@ class Tan(UnaryScalarOp):
...
@@ -670,7 +670,7 @@ class Tan(UnaryScalarOp):
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
math
.
tan
(
x
)
return
math
.
tan
(
x
)
def
grad
(
self
,
(
x
,
),
(
gz
,
)):
def
grad
(
self
,
(
x
,
),
(
gz
,
)):
return
gz
/
(
cos
(
x
)
**
2
),
return
gz
/
sqr
(
cos
(
x
)
),
def
c_code
(
self
,
node
,
name
,
(
x
,
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
(
x
,
),
(
z
,
),
sub
):
return
"
%(z)
s = tan(
%(x)
s);"
%
locals
()
return
"
%(z)
s = tan(
%(x)
s);"
%
locals
()
tan
=
Tan
(
upgrade_to_float
,
name
=
'tan'
)
tan
=
Tan
(
upgrade_to_float
,
name
=
'tan'
)
...
@@ -707,7 +707,7 @@ class Tanh(UnaryScalarOp):
...
@@ -707,7 +707,7 @@ class Tanh(UnaryScalarOp):
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
math
.
tanh
(
x
)
return
math
.
tanh
(
x
)
def
grad
(
self
,
(
x
,
),
(
gz
,
)):
def
grad
(
self
,
(
x
,
),
(
gz
,
)):
return
gz
*
(
1
-
tanh
(
x
)
**
2
),
return
gz
*
(
1
-
sqr
(
tanh
(
x
))
),
def
c_code
(
self
,
node
,
name
,
(
x
,
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
(
x
,
),
(
z
,
),
sub
):
return
"
%(z)
s = tanh(
%(x)
s);"
%
locals
()
return
"
%(z)
s = tanh(
%(x)
s);"
%
locals
()
tanh
=
Tanh
(
upgrade_to_float
,
name
=
'tanh'
)
tanh
=
Tanh
(
upgrade_to_float
,
name
=
'tanh'
)
...
...
tensor.py
浏览文件 @
933aa55b
...
@@ -390,7 +390,8 @@ class _tensor_py_operators:
...
@@ -390,7 +390,8 @@ class _tensor_py_operators:
def
__iter__
(
self
):
def
__iter__
(
self
):
# This prevents accidental iteration via builtin.sum(self)
# This prevents accidental iteration via builtin.sum(self)
raise
TypeError
(
'Tensor does not support iteration'
)
raise
TypeError
(
'Tensor does not support iteration. '
'Maybe you are using builtin.sum instead of theano.tensor.sum?'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论