Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c7376aba
提交
c7376aba
authored
3月 25, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated numpy as np
上级
85fb68bc
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
21 行删除
+21
-21
var.py
theano/tensor/var.py
+21
-21
没有找到文件。
theano/tensor/var.py
浏览文件 @
c7376aba
...
...
@@ -4,7 +4,7 @@ import copy
import
traceback
as
tb
import
warnings
import
numpy
import
numpy
as
np
from
six
import
integer_types
from
six.moves
import
xrange
...
...
@@ -462,7 +462,7 @@ class _tensor_py_operators(object):
def
check_bool
(
args_el
):
try
:
if
(
isinstance
(
args_el
,
(
n
umpy
.
bool_
,
bool
))
or
if
(
isinstance
(
args_el
,
(
n
p
.
bool_
,
bool
))
or
args_el
.
dtype
==
'bool'
):
raise
TypeError
(
'TensorType does not support boolean '
'mask for indexing such as tensor[x==0]. '
...
...
@@ -495,7 +495,7 @@ class _tensor_py_operators(object):
elif
len
(
ellipses
)
==
1
:
new_axes
=
sum
(
1
for
index
in
args
if
index
is
n
umpy
.
newaxis
)
# numpy.newaxis is None
if
index
is
n
p
.
newaxis
)
# numpy.newaxis is None
ellipsis_at
=
ellipses
[
0
]
args
=
list
(
args
)
args
[
ellipsis_at
:
ellipsis_at
+
1
]
=
(
...
...
@@ -503,7 +503,7 @@ class _tensor_py_operators(object):
# Force input to be int64 datatype if input is an empty list or tuple
# Else leave it as is if it is a real number
args
=
tuple
([
n
umpy
.
array
(
inp
,
dtype
=
numpy
.
int64
)
args
=
tuple
([
n
p
.
array
(
inp
,
dtype
=
np
.
int64
)
if
(
inp
==
[]
or
inp
==
())
else
inp
for
inp
in
args
])
# Convert python literals to theano constants
args
=
theano
.
tensor
.
subtensor
.
make_constant
(
args
)
...
...
@@ -515,7 +515,7 @@ class _tensor_py_operators(object):
axis
=
None
for
i
,
arg
in
enumerate
(
args
):
try
:
if
arg
is
not
n
umpy
.
newaxis
:
if
arg
is
not
n
p
.
newaxis
:
theano
.
tensor
.
subtensor
.
Subtensor
.
convert
(
arg
)
except
theano
.
tensor
.
subtensor
.
AdvancedIndexingError
:
if
advanced
:
...
...
@@ -532,14 +532,14 @@ class _tensor_py_operators(object):
all
(
isinstance
(
a
,
slice
)
and
equal_slices
(
a
,
slice
(
None
))
for
a
in
args
[
axis
+
1
:])
and
isinstance
(
args
[
axis
],
(
n
umpy
.
ndarray
,
list
,
(
n
p
.
ndarray
,
list
,
TensorVariable
,
TensorConstant
,
theano
.
tensor
.
sharedvar
.
TensorSharedVariable
))):
return
self
.
take
(
args
[
axis
],
axis
)
else
:
return
theano
.
tensor
.
subtensor
.
advanced_subtensor
(
self
,
*
args
)
else
:
if
n
umpy
.
newaxis
in
args
:
if
n
p
.
newaxis
in
args
:
# None (aka np.newaxis) in numpy indexing means to add a
# broadcastable dimension, which theano traditionally did with
# the dimshuffle op. The following code converts numpy-style
...
...
@@ -550,7 +550,7 @@ class _tensor_py_operators(object):
pattern
=
[]
new_args
=
[]
for
arg
in
args
:
if
arg
==
n
umpy
.
newaxis
:
if
arg
==
n
p
.
newaxis
:
pattern
.
append
(
'x'
)
new_args
.
append
(
slice
(
None
,
None
,
None
))
else
:
...
...
@@ -642,7 +642,7 @@ class _tensor_py_operators(object):
def
norm
(
self
,
L
,
axis
=
None
,
keepdims
=
False
):
if
L
==
0
:
raise
NotImplementedError
()
if
n
umpy
.
isinf
(
L
):
if
n
p
.
isinf
(
L
):
raise
NotImplementedError
()
# optimizations will/should catch cases like L=1, L=2
y
=
theano
.
tensor
.
basic
.
pow
(
...
...
@@ -862,7 +862,7 @@ class TensorConstantSignature(tuple):
# (note that if there are NaN values in d1, this will return
# False, which is why we do not bother with testing `other.has_nan`
# here).
return
(
self
.
sum
==
other
.
sum
)
and
n
umpy
.
all
(
d0
==
d1
)
return
(
self
.
sum
==
other
.
sum
)
and
n
p
.
all
(
d0
==
d1
)
def
__hash__
(
self
):
t
,
d
=
self
...
...
@@ -880,25 +880,25 @@ class TensorConstantSignature(tuple):
self
.
_sum
=
self
.
no_nan
.
sum
()
# The following 2 lines are needede as in Python 3.3 with NumPy
# 1.7.1, numpy.ndarray and numpy.memmap aren't hashable.
if
type
(
self
.
_sum
)
is
n
umpy
.
memmap
:
self
.
_sum
=
n
umpy
.
asarray
(
self
.
_sum
)
.
item
()
if
type
(
self
.
_sum
)
is
n
p
.
memmap
:
self
.
_sum
=
n
p
.
asarray
(
self
.
_sum
)
.
item
()
if
self
.
has_nan
and
self
.
no_nan
.
mask
.
all
():
# In this case the sum is not properly computed by numpy.
self
.
_sum
=
0
if
n
umpy
.
isinf
(
self
.
_sum
)
or
numpy
.
isnan
(
self
.
_sum
):
if
n
p
.
isinf
(
self
.
_sum
)
or
np
.
isnan
(
self
.
_sum
):
# NaN may happen when there are both -inf and +inf values.
if
self
.
has_nan
:
# Filter both NaN and Inf values.
mask
=
self
.
no_nan
.
mask
+
n
umpy
.
isinf
(
self
[
1
])
mask
=
self
.
no_nan
.
mask
+
n
p
.
isinf
(
self
[
1
])
else
:
# Filter only Inf values.
mask
=
n
umpy
.
isinf
(
self
[
1
])
mask
=
n
p
.
isinf
(
self
[
1
])
if
mask
.
all
():
self
.
_sum
=
0
else
:
self
.
_sum
=
n
umpy
.
ma
.
masked_array
(
self
[
1
],
mask
)
.
sum
()
self
.
_sum
=
n
p
.
ma
.
masked_array
(
self
[
1
],
mask
)
.
sum
()
# At this point there should be no more NaN.
assert
not
n
umpy
.
isnan
(
self
.
_sum
)
assert
not
n
p
.
isnan
(
self
.
_sum
)
return
self
.
_sum
sum
=
property
(
_get_sum
)
...
...
@@ -906,9 +906,9 @@ class TensorConstantSignature(tuple):
try
:
return
self
.
_no_nan
except
AttributeError
:
nan_mask
=
n
umpy
.
isnan
(
self
[
1
])
nan_mask
=
n
p
.
isnan
(
self
[
1
])
if
nan_mask
.
any
():
self
.
_no_nan
=
n
umpy
.
ma
.
masked_array
(
self
[
1
],
nan_mask
)
self
.
_no_nan
=
n
p
.
ma
.
masked_array
(
self
[
1
],
nan_mask
)
self
.
has_nan
=
True
else
:
self
.
_no_nan
=
self
[
1
]
...
...
@@ -926,7 +926,7 @@ class TensorConstant(_tensor_py_operators, Constant):
def
__init__
(
self
,
type
,
data
,
name
=
None
):
Constant
.
__init__
(
self
,
type
,
data
,
name
)
self
.
tag
.
unique_value
=
None
if
isinstance
(
data
,
n
umpy
.
ndarray
)
and
data
.
ndim
>
0
:
if
isinstance
(
data
,
n
p
.
ndarray
)
and
data
.
ndim
>
0
:
flat_data
=
data
.
ravel
()
if
flat_data
.
shape
[
0
]:
if
(
flat_data
==
flat_data
[
0
])
.
all
():
...
...
@@ -949,7 +949,7 @@ class TensorConstant(_tensor_py_operators, Constant):
def
equals
(
self
,
other
):
# Override Contant.equals to allow to compare with
# numpy.ndarray, and python type.
if
isinstance
(
other
,
(
n
umpy
.
ndarray
,
int
,
float
)):
if
isinstance
(
other
,
(
n
p
.
ndarray
,
int
,
float
)):
# Make a TensorConstant to be able to compare
other
=
theano
.
tensor
.
basic
.
constant
(
other
)
return
(
isinstance
(
other
,
TensorConstant
)
and
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论