Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
85019057
提交
85019057
authored
3月 25, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated numpy as np
上级
4a98f1e1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
17 行增加
和
17 行删除
+17
-17
subtensor.py
theano/tensor/subtensor.py
+17
-17
没有找到文件。
theano/tensor/subtensor.py
浏览文件 @
85019057
...
@@ -4,7 +4,7 @@ from textwrap import dedent
...
@@ -4,7 +4,7 @@ from textwrap import dedent
import
warnings
import
warnings
import
logging
import
logging
import
numpy
import
numpy
as
np
from
six
import
integer_types
from
six
import
integer_types
from
six.moves
import
xrange
from
six.moves
import
xrange
...
@@ -58,7 +58,7 @@ def make_constant(args):
...
@@ -58,7 +58,7 @@ def make_constant(args):
return
slice
(
conv
(
a
.
start
),
return
slice
(
conv
(
a
.
start
),
conv
(
a
.
stop
),
conv
(
a
.
stop
),
conv
(
a
.
step
))
conv
(
a
.
step
))
elif
isinstance
(
a
,
(
integer_types
,
n
umpy
.
integer
)):
elif
isinstance
(
a
,
(
integer_types
,
n
p
.
integer
)):
return
scal
.
ScalarConstant
(
scal
.
int64
,
a
)
return
scal
.
ScalarConstant
(
scal
.
int64
,
a
)
else
:
else
:
return
a
return
a
...
@@ -355,11 +355,11 @@ class Subtensor(Op):
...
@@ -355,11 +355,11 @@ class Subtensor(Op):
if
(
isinstance
(
entry
,
gof
.
Variable
)
and
if
(
isinstance
(
entry
,
gof
.
Variable
)
and
entry
.
type
in
tensor_types
and
entry
.
type
in
tensor_types
and
n
umpy
.
all
(
entry
.
type
.
broadcastable
)):
n
p
.
all
(
entry
.
type
.
broadcastable
)):
return
scal
.
get_scalar_type
(
entry
.
type
.
dtype
)
return
scal
.
get_scalar_type
(
entry
.
type
.
dtype
)
elif
(
isinstance
(
entry
,
gof
.
Type
)
and
elif
(
isinstance
(
entry
,
gof
.
Type
)
and
entry
in
tensor_types
and
entry
in
tensor_types
and
n
umpy
.
all
(
entry
.
broadcastable
)):
n
p
.
all
(
entry
.
broadcastable
)):
return
scal
.
get_scalar_type
(
entry
.
dtype
)
return
scal
.
get_scalar_type
(
entry
.
dtype
)
elif
slice_ok
and
isinstance
(
entry
,
slice
):
elif
slice_ok
and
isinstance
(
entry
,
slice
):
a
=
entry
.
start
a
=
entry
.
start
...
@@ -385,7 +385,7 @@ class Subtensor(Op):
...
@@ -385,7 +385,7 @@ class Subtensor(Op):
slice_c
=
None
slice_c
=
None
return
slice
(
slice_a
,
slice_b
,
slice_c
)
return
slice
(
slice_a
,
slice_b
,
slice_c
)
elif
isinstance
(
entry
,
(
integer_types
,
n
umpy
.
integer
)):
elif
isinstance
(
entry
,
(
integer_types
,
n
p
.
integer
)):
# Disallow the use of python scalars in idx_list
# Disallow the use of python scalars in idx_list
raise
TypeError
(
"Python scalar in idx_list."
raise
TypeError
(
"Python scalar in idx_list."
"Please report this error to theano-dev."
)
"Please report this error to theano-dev."
)
...
@@ -510,8 +510,8 @@ class Subtensor(Op):
...
@@ -510,8 +510,8 @@ class Subtensor(Op):
if
start
is
None
:
if
start
is
None
:
start
=
0
start
=
0
if
(
p
.
stop
is
None
or
if
(
p
.
stop
is
None
or
(
isinstance
(
p
.
stop
,
(
integer_types
,
n
umpy
.
integer
,
(
isinstance
(
p
.
stop
,
(
integer_types
,
n
p
.
integer
,
n
umpy
.
ndarray
))
and
n
p
.
ndarray
))
and
p
.
stop
>
start
)):
p
.
stop
>
start
)):
broadcastable
.
append
(
True
)
broadcastable
.
append
(
True
)
continue
continue
...
@@ -531,7 +531,7 @@ class Subtensor(Op):
...
@@ -531,7 +531,7 @@ class Subtensor(Op):
if
len
(
cdata
)
==
1
:
if
len
(
cdata
)
==
1
:
cdata
=
cdata
[
0
]
cdata
=
cdata
[
0
]
out
[
0
]
=
n
umpy
.
asarray
(
x
.
__getitem__
(
cdata
))
out
[
0
]
=
n
p
.
asarray
(
x
.
__getitem__
(
cdata
))
def
infer_shape
(
self
,
node
,
shapes
):
def
infer_shape
(
self
,
node
,
shapes
):
xshp
=
shapes
[
0
]
xshp
=
shapes
[
0
]
...
@@ -681,7 +681,7 @@ class Subtensor(Op):
...
@@ -681,7 +681,7 @@ class Subtensor(Op):
return
pos
[
1
]
return
pos
[
1
]
def
init_entry
(
entry
,
depth
=
0
):
def
init_entry
(
entry
,
depth
=
0
):
if
isinstance
(
entry
,
(
n
umpy
.
integer
,
integer_types
)):
if
isinstance
(
entry
,
(
n
p
.
integer
,
integer_types
)):
init_cmds
.
append
(
init_cmds
.
append
(
"subtensor_spec[
%
i] =
%
i;"
%
(
spec_pos
(),
"subtensor_spec[
%
i] =
%
i;"
%
(
spec_pos
(),
entry
))
entry
))
...
@@ -1390,7 +1390,7 @@ class IncSubtensor(Op):
...
@@ -1390,7 +1390,7 @@ class IncSubtensor(Op):
op_is_set
=
0
op_is_set
=
0
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
view_ndim
=
(
node
.
inputs
[
0
]
.
ndim
-
view_ndim
=
(
node
.
inputs
[
0
]
.
ndim
-
n
umpy
.
sum
([
not
isinstance
(
idx
,
slice
)
n
p
.
sum
([
not
isinstance
(
idx
,
slice
)
for
idx
in
self
.
idx_list
]))
for
idx
in
self
.
idx_list
]))
copy_of_x
=
self
.
copy_of_x
(
x
)
copy_of_x
=
self
.
copy_of_x
(
x
)
...
@@ -1712,11 +1712,11 @@ class AdvancedSubtensor1(Op):
...
@@ -1712,11 +1712,11 @@ class AdvancedSubtensor1(Op):
# We need to check if values in i can fit in numpy.intp, because
# We need to check if values in i can fit in numpy.intp, because
# if they don't, that should be an error (no array can have that
# if they don't, that should be an error (no array can have that
# many elements on a 32-bit arch).
# many elements on a 32-bit arch).
if
i
.
dtype
!=
n
umpy
.
intp
:
if
i
.
dtype
!=
n
p
.
intp
:
i_
=
theano
.
_asarray
(
i
,
dtype
=
n
umpy
.
intp
)
i_
=
theano
.
_asarray
(
i
,
dtype
=
n
p
.
intp
)
if
not
n
umpy
.
can_cast
(
i
.
dtype
,
numpy
.
intp
):
if
not
n
p
.
can_cast
(
i
.
dtype
,
np
.
intp
):
# Check if there was actually an incorrect conversion
# Check if there was actually an incorrect conversion
if
n
umpy
.
any
(
i
!=
i_
):
if
n
p
.
any
(
i
!=
i_
):
raise
IndexError
(
raise
IndexError
(
'index contains values that are bigger '
'index contains values that are bigger '
'than the maximum array size on this system.'
,
i
)
'than the maximum array size on this system.'
,
i
)
...
@@ -1946,7 +1946,7 @@ class AdvancedIncSubtensor1(Op):
...
@@ -1946,7 +1946,7 @@ class AdvancedIncSubtensor1(Op):
return
compile_cutils_code
()
return
compile_cutils_code
()
def
c_code
(
self
,
node
,
name
,
input_names
,
output_names
,
sub
):
def
c_code
(
self
,
node
,
name
,
input_names
,
output_names
,
sub
):
numpy_ver
=
[
int
(
n
)
for
n
in
n
umpy
.
__version__
.
split
(
'.'
)[:
2
]]
numpy_ver
=
[
int
(
n
)
for
n
in
n
p
.
__version__
.
split
(
'.'
)[:
2
]]
if
bool
(
numpy_ver
<
[
1
,
8
]):
if
bool
(
numpy_ver
<
[
1
,
8
]):
raise
NotImplementedError
raise
NotImplementedError
x
,
y
,
idx
=
input_names
x
,
y
,
idx
=
input_names
...
@@ -2113,13 +2113,13 @@ def adv_index_broadcastable_pattern(a, idx):
...
@@ -2113,13 +2113,13 @@ def adv_index_broadcastable_pattern(a, idx):
if
isinstance
(
v
.
type
,
SliceType
):
if
isinstance
(
v
.
type
,
SliceType
):
return
slice
(
None
,
None
)
return
slice
(
None
,
None
)
return
n
umpy
.
zeros
((
2
,)
*
v
.
ndim
,
int
)
return
n
p
.
zeros
((
2
,)
*
v
.
ndim
,
int
)
newidx
=
tuple
(
map
(
replace_slice
,
idx
))
newidx
=
tuple
(
map
(
replace_slice
,
idx
))
# 2 - True = 1; 2 - False = 2
# 2 - True = 1; 2 - False = 2
fakeshape
=
[
2
-
bc
for
bc
in
a
.
broadcastable
]
fakeshape
=
[
2
-
bc
for
bc
in
a
.
broadcastable
]
retshape
=
n
umpy
.
empty
(
fakeshape
)[
newidx
]
.
shape
retshape
=
n
p
.
empty
(
fakeshape
)[
newidx
]
.
shape
return
tuple
([
dim
==
1
for
dim
in
retshape
])
return
tuple
([
dim
==
1
for
dim
in
retshape
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论