Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5f9b2a8c
提交
5f9b2a8c
authored
3月 14, 2013
作者:
John Salvatier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
simplified increment check
上级
4c7c7bc3
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
13 行增加
和
29 行删除
+13
-29
basic.py
theano/tensor/basic.py
+13
-28
test_basic.py
theano/tensor/tests/test_basic.py
+0
-1
没有找到文件。
theano/tensor/basic.py
浏览文件 @
5f9b2a8c
...
@@ -25,6 +25,10 @@ from theano.printing import pprint, min_informative_str
...
@@ -25,6 +25,10 @@ from theano.printing import pprint, min_informative_str
from
theano.tensor.utils
import
hash_from_ndarray
from
theano.tensor.utils
import
hash_from_ndarray
import
theano.gof.cutils
#needed to import cutils_ext
import
theano.gof.cutils
#needed to import cutils_ext
try
:
from
cutils_ext.cutils_ext
import
inplace_increment
except
ImportError
:
inplace_increment
=
None
# We use these exceptions as well.
# We use these exceptions as well.
from
theano.scalar
import
ComplexError
,
IntegerDivisionError
from
theano.scalar
import
ComplexError
,
IntegerDivisionError
...
@@ -7136,9 +7140,8 @@ class AdvancedIncSubtensor1(Op):
...
@@ -7136,9 +7140,8 @@ class AdvancedIncSubtensor1(Op):
if
self
.
set_instead_of_inc
:
if
self
.
set_instead_of_inc
:
x
[
idx
]
=
y
x
[
idx
]
=
y
else
:
else
:
try
:
increment
=
inplace_increment
from
cutils_ext.cutils_ext
import
inplace_increment
as
increment
if
increment
is
None
:
except
ImportError
:
increment
=
self
.
inplace_increment1d_slow
increment
=
self
.
inplace_increment1d_slow
increment
(
x
,
idx
,
y
)
increment
(
x
,
idx
,
y
)
...
@@ -7376,17 +7379,6 @@ class AdvancedIncSubtensor(Op):
...
@@ -7376,17 +7379,6 @@ class AdvancedIncSubtensor(Op):
op.
op.
"""
"""
increment_available
=
None
@classmethod
def
check_increment_available
(
cls
):
if
cls
.
increment_available
is
None
:
try
:
from
cutils_ext.cutils_ext
import
(
inplace_increment
as
increment
)
cls
.
increment_available
=
True
except
ImportError
:
cls
.
increment_available
=
False
def
__init__
(
self
,
inplace
=
False
,
set_instead_of_inc
=
False
):
def
__init__
(
self
,
inplace
=
False
,
set_instead_of_inc
=
False
):
self
.
inplace
=
inplace
self
.
inplace
=
inplace
...
@@ -7398,16 +7390,13 @@ class AdvancedIncSubtensor(Op):
...
@@ -7398,16 +7390,13 @@ class AdvancedIncSubtensor(Op):
raise
NotImplementedError
(
'In place computation is not'
raise
NotImplementedError
(
'In place computation is not'
' implemented'
)
' implemented'
)
# The first time we instanciate an AdvancedIncSubtensor without
# set_instead_of_inc, check if the "increment" function is available
if
not
set_instead_of_inc
:
self
.
check_increment_available
()
# This flag enables the legacy implementation of "perform" for
# advanced_inc_subtensor. This implementation is incorrect in general,
# but gives correct results when no element is indexed more than once.
self
.
allow_legacy_perform
=
False
self
.
allow_legacy_perform
=
False
@classmethod
@property
def
increment_available
():
return
inplace_increment
is
not
None
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
((
type
(
self
),
self
.
inplace
,
self
.
set_instead_of_inc
))
return
hash
((
type
(
self
),
self
.
inplace
,
self
.
set_instead_of_inc
))
...
@@ -7422,11 +7411,7 @@ class AdvancedIncSubtensor(Op):
...
@@ -7422,11 +7411,7 @@ class AdvancedIncSubtensor(Op):
" set_instead_of_inc="
+
str
(
self
.
set_instead_of_inc
))
" set_instead_of_inc="
+
str
(
self
.
set_instead_of_inc
))
def
__setstate__
(
self
,
state
):
def
__setstate__
(
self
,
state
):
# We do not want to pickle increment_available, as it depends
# on the machine. Instead, we call check_increment_available on load
self
.
__dict__
.
update
(
state
)
self
.
__dict__
.
update
(
state
)
if
self
.
set_instead_of_inc
:
self
.
check_increment_available
()
def
make_node
(
self
,
x
,
y
,
*
inputs
):
def
make_node
(
self
,
x
,
y
,
*
inputs
):
x
=
as_tensor_variable
(
x
)
x
=
as_tensor_variable
(
x
)
...
@@ -7482,8 +7467,8 @@ class AdvancedIncSubtensor(Op):
...
@@ -7482,8 +7467,8 @@ class AdvancedIncSubtensor(Op):
if
self
.
set_instead_of_inc
:
if
self
.
set_instead_of_inc
:
out
[
0
][
inputs
[
2
:]]
=
inputs
[
1
]
out
[
0
][
inputs
[
2
:]]
=
inputs
[
1
]
elif
self
.
increment_availabl
e
:
elif
inplace_increment
is
not
Non
e
:
increment
(
out
[
0
],
tuple
(
inputs
[
2
:]),
inputs
[
1
])
in
place_in
crement
(
out
[
0
],
tuple
(
inputs
[
2
:]),
inputs
[
1
])
elif
self
.
allow_legacy_perform
:
elif
self
.
allow_legacy_perform
:
out
[
0
][
inputs
[
2
:]]
+=
inputs
[
1
]
out
[
0
][
inputs
[
2
:]]
+=
inputs
[
1
]
else
:
else
:
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
5f9b2a8c
...
@@ -3675,7 +3675,6 @@ class TestIncSubtensor1(unittest.TestCase):
...
@@ -3675,7 +3675,6 @@ class TestIncSubtensor1(unittest.TestCase):
# also tests set_subtensor
# also tests set_subtensor
def
setUp
(
self
):
def
setUp
(
self
):
AdvancedIncSubtensor
.
check_increment_available
()
self
.
s
=
iscalar
()
self
.
s
=
iscalar
()
self
.
v
=
fvector
()
self
.
v
=
fvector
()
self
.
m
=
dmatrix
()
self
.
m
=
dmatrix
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论