Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dc83dda9
提交
dc83dda9
authored
3月 25, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated numpy as np
上级
5715084e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
43 行增加
和
43 行删除
+43
-43
opt.py
theano/tensor/opt.py
+43
-43
没有找到文件。
theano/tensor/opt.py
浏览文件 @
dc83dda9
...
@@ -14,7 +14,7 @@ import time
...
@@ -14,7 +14,7 @@ import time
import
traceback
import
traceback
import
warnings
import
warnings
import
numpy
import
numpy
as
np
from
six
import
integer_types
,
iteritems
from
six
import
integer_types
,
iteritems
from
six.moves
import
reduce
,
xrange
from
six.moves
import
reduce
,
xrange
...
@@ -786,7 +786,7 @@ class MakeVector(T.Op):
...
@@ -786,7 +786,7 @@ class MakeVector(T.Op):
# So there will be (1 * nb_dtype) + ((nb len(inp) - 1 ))
# So there will be (1 * nb_dtype) + ((nb len(inp) - 1 ))
# different c code with the following algo
# different c code with the following algo
out_shape
=
len
(
inp
)
out_shape
=
len
(
inp
)
out_num
=
n
umpy
.
dtype
(
node
.
outputs
[
0
]
.
dtype
)
.
num
out_num
=
n
p
.
dtype
(
node
.
outputs
[
0
]
.
dtype
)
.
num
# don't use dtype_%(out)s as when check_input=False, it isn't defined.
# don't use dtype_%(out)s as when check_input=False, it isn't defined.
out_dtype
=
node
.
outputs
[
0
]
.
type
.
dtype_specs
()[
1
]
out_dtype
=
node
.
outputs
[
0
]
.
type
.
dtype_specs
()[
1
]
if
len
(
inp
)
>
0
:
if
len
(
inp
)
>
0
:
...
@@ -1064,8 +1064,8 @@ class ShapeFeature(object):
...
@@ -1064,8 +1064,8 @@ class ShapeFeature(object):
if
type
(
s_i
)
is
float
and
int
(
s_i
)
==
s_i
:
if
type
(
s_i
)
is
float
and
int
(
s_i
)
==
s_i
:
s_i
=
int
(
s_i
)
s_i
=
int
(
s_i
)
if
(
type
(
s_i
)
in
integer_types
or
if
(
type
(
s_i
)
in
integer_types
or
isinstance
(
s_i
,
n
umpy
.
integer
)
or
isinstance
(
s_i
,
n
p
.
integer
)
or
(
isinstance
(
s_i
,
n
umpy
.
ndarray
)
and
s_i
.
ndim
==
0
)):
(
isinstance
(
s_i
,
n
p
.
ndarray
)
and
s_i
.
ndim
==
0
)):
# this shape is a constant
# this shape is a constant
if
s_i
<
0
:
if
s_i
<
0
:
msg
=
"There is a negative shape in the graph!"
msg
=
"There is a negative shape in the graph!"
...
@@ -1975,7 +1975,7 @@ def local_subtensor_remove_broadcastable_index(node):
...
@@ -1975,7 +1975,7 @@ def local_subtensor_remove_broadcastable_index(node):
elif
isinstance
(
elem
,
slice
):
elif
isinstance
(
elem
,
slice
):
if
elem
!=
slice
(
None
):
if
elem
!=
slice
(
None
):
return
return
elif
isinstance
(
elem
,
(
integer_types
,
n
umpy
.
integer
)):
elif
isinstance
(
elem
,
(
integer_types
,
n
p
.
integer
)):
if
elem
in
[
0
,
-
1
]
and
node
.
inputs
[
0
]
.
broadcastable
[
dim
]:
if
elem
in
[
0
,
-
1
]
and
node
.
inputs
[
0
]
.
broadcastable
[
dim
]:
remove_dim
.
append
(
dim
)
remove_dim
.
append
(
dim
)
else
:
else
:
...
@@ -2027,7 +2027,7 @@ def local_subtensor_make_vector(node):
...
@@ -2027,7 +2027,7 @@ def local_subtensor_make_vector(node):
else
:
else
:
return
return
if
isinstance
(
idx
,
(
integer_types
,
n
umpy
.
integer
)):
if
isinstance
(
idx
,
(
integer_types
,
n
p
.
integer
)):
# We don't need to copy over any stack traces here
# We don't need to copy over any stack traces here
return
[
x
.
owner
.
inputs
[
idx
]]
return
[
x
.
owner
.
inputs
[
idx
]]
elif
isinstance
(
idx
,
Variable
):
elif
isinstance
(
idx
,
Variable
):
...
@@ -2035,7 +2035,7 @@ def local_subtensor_make_vector(node):
...
@@ -2035,7 +2035,7 @@ def local_subtensor_make_vector(node):
# if it is a constant we can do something with it
# if it is a constant we can do something with it
try
:
try
:
v
=
get_scalar_constant_value
(
idx
,
only_process_constants
=
True
)
v
=
get_scalar_constant_value
(
idx
,
only_process_constants
=
True
)
if
isinstance
(
v
,
n
umpy
.
integer
):
if
isinstance
(
v
,
n
p
.
integer
):
# Python 2.4 wants to index only with Python integers
# Python 2.4 wants to index only with Python integers
v
=
int
(
v
)
v
=
int
(
v
)
# We don't need to copy over any stack traces here
# We don't need to copy over any stack traces here
...
@@ -2359,14 +2359,14 @@ class Assert(T.Op):
...
@@ -2359,14 +2359,14 @@ class Assert(T.Op):
if
not
isinstance
(
value
,
Variable
):
if
not
isinstance
(
value
,
Variable
):
value
=
T
.
as_tensor_variable
(
value
)
value
=
T
.
as_tensor_variable
(
value
)
cond
=
[
T
.
as_tensor_variable
(
c
)
for
c
in
conds
]
cond
=
[
T
.
as_tensor_variable
(
c
)
for
c
in
conds
]
assert
n
umpy
.
all
([
c
.
type
.
ndim
==
0
for
c
in
cond
])
assert
n
p
.
all
([
c
.
type
.
ndim
==
0
for
c
in
cond
])
return
gof
.
Apply
(
self
,
[
value
]
+
cond
,
[
value
.
type
()])
return
gof
.
Apply
(
self
,
[
value
]
+
cond
,
[
value
.
type
()])
def
perform
(
self
,
node
,
inputs
,
out_
):
def
perform
(
self
,
node
,
inputs
,
out_
):
out
,
=
out_
out
,
=
out_
v
=
inputs
[
0
]
v
=
inputs
[
0
]
out
[
0
]
=
v
out
[
0
]
=
v
assert
n
umpy
.
all
(
inputs
[
1
:]),
self
.
msg
assert
n
p
.
all
(
inputs
[
1
:]),
self
.
msg
def
grad
(
self
,
input
,
output_gradients
):
def
grad
(
self
,
input
,
output_gradients
):
return
output_gradients
+
[
DisconnectedType
()()]
*
(
len
(
input
)
-
1
)
return
output_gradients
+
[
DisconnectedType
()()]
*
(
len
(
input
)
-
1
)
...
@@ -2708,7 +2708,7 @@ def local_useless_subtensor(node):
...
@@ -2708,7 +2708,7 @@ def local_useless_subtensor(node):
length_pos
=
shape_of
[
node
.
inputs
[
0
]][
pos
]
length_pos
=
shape_of
[
node
.
inputs
[
0
]][
pos
]
if
isinstance
(
idx
.
stop
,
(
integer_types
,
n
umpy
.
integer
)):
if
isinstance
(
idx
.
stop
,
(
integer_types
,
n
p
.
integer
)):
length_pos_data
=
sys
.
maxsize
length_pos_data
=
sys
.
maxsize
try
:
try
:
length_pos_data
=
get_scalar_constant_value
(
length_pos
,
length_pos_data
=
get_scalar_constant_value
(
length_pos
,
...
@@ -2766,7 +2766,7 @@ def local_useless_subtensor(node):
...
@@ -2766,7 +2766,7 @@ def local_useless_subtensor(node):
idx
=
idx
.
value
idx
=
idx
.
value
if
len
(
idx
)
!=
length
:
if
len
(
idx
)
!=
length
:
return
False
return
False
if
n
umpy
.
any
(
idx
!=
numpy
.
arange
(
length
)):
if
n
p
.
any
(
idx
!=
np
.
arange
(
length
)):
return
False
return
False
elif
idx
.
owner
is
not
None
and
isinstance
(
idx
.
owner
.
op
,
T
.
ARange
):
elif
idx
.
owner
is
not
None
and
isinstance
(
idx
.
owner
.
op
,
T
.
ARange
):
try
:
try
:
...
@@ -3625,7 +3625,7 @@ def local_useless_rebroadcast(node):
...
@@ -3625,7 +3625,7 @@ def local_useless_rebroadcast(node):
"""
"""
if
isinstance
(
node
.
op
,
T
.
Rebroadcast
):
if
isinstance
(
node
.
op
,
T
.
Rebroadcast
):
x
=
node
.
inputs
[
0
]
x
=
node
.
inputs
[
0
]
if
n
umpy
.
all
(
x
.
broadcastable
==
node
.
outputs
[
0
]
.
broadcastable
):
if
n
p
.
all
(
x
.
broadcastable
==
node
.
outputs
[
0
]
.
broadcastable
):
# No broadcastable flag was modified
# No broadcastable flag was modified
# No need to copy over stack trace,
# No need to copy over stack trace,
# because x should already have a stack trace.
# because x should already have a stack trace.
...
@@ -3938,8 +3938,8 @@ def local_useless_switch(node):
...
@@ -3938,8 +3938,8 @@ def local_useless_switch(node):
isinstance
(
node
.
op
.
scalar_op
,
scalar
.
basic
.
Switch
)):
isinstance
(
node
.
op
.
scalar_op
,
scalar
.
basic
.
Switch
)):
cond
=
T
.
extract_constant
(
node
.
inputs
[
0
],
cond
=
T
.
extract_constant
(
node
.
inputs
[
0
],
only_process_constants
=
True
)
only_process_constants
=
True
)
if
((
type
(
cond
)
is
n
umpy
.
ndarray
and
cond
.
ndim
==
0
)
or
if
((
type
(
cond
)
is
n
p
.
ndarray
and
cond
.
ndim
==
0
)
or
isinstance
(
cond
,
n
umpy
.
number
)):
isinstance
(
cond
,
n
p
.
number
)):
if
cond
==
0
:
if
cond
==
0
:
correct_out
=
node
.
inputs
[
2
]
correct_out
=
node
.
inputs
[
2
]
else
:
else
:
...
@@ -4985,7 +4985,7 @@ class Canonizer(gof.LocalOptimizer):
...
@@ -4985,7 +4985,7 @@ class Canonizer(gof.LocalOptimizer):
num
,
denum
=
self
.
simplify
(
list
(
orig_num
),
list
(
orig_denum
),
out
.
type
)
num
,
denum
=
self
.
simplify
(
list
(
orig_num
),
list
(
orig_denum
),
out
.
type
)
def
same
(
x
,
y
):
def
same
(
x
,
y
):
return
len
(
x
)
==
len
(
y
)
and
all
(
n
umpy
.
all
(
xe
==
ye
)
for
xe
,
ye
in
return
len
(
x
)
==
len
(
y
)
and
all
(
n
p
.
all
(
xe
==
ye
)
for
xe
,
ye
in
zip
(
x
,
y
))
zip
(
x
,
y
))
if
same
(
orig_num
,
num
)
and
same
(
orig_denum
,
denum
):
if
same
(
orig_num
,
num
)
and
same
(
orig_denum
,
denum
):
...
@@ -5029,7 +5029,7 @@ def mul_calculate(num, denum, aslist=False, out_type=None):
...
@@ -5029,7 +5029,7 @@ def mul_calculate(num, denum, aslist=False, out_type=None):
if
aslist
:
if
aslist
:
return
[]
return
[]
else
:
else
:
return
n
umpy
.
int8
(
1
)
return
n
p
.
int8
(
1
)
# Make sure we do not accidently upcast data types.
# Make sure we do not accidently upcast data types.
if
out_type
is
None
:
if
out_type
is
None
:
...
@@ -5038,9 +5038,9 @@ def mul_calculate(num, denum, aslist=False, out_type=None):
...
@@ -5038,9 +5038,9 @@ def mul_calculate(num, denum, aslist=False, out_type=None):
out_dtype
=
out_type
.
dtype
out_dtype
=
out_type
.
dtype
one
=
theano
.
_asarray
(
1
,
dtype
=
out_dtype
)
one
=
theano
.
_asarray
(
1
,
dtype
=
out_dtype
)
v
=
reduce
(
n
umpy
.
multiply
,
num
,
one
)
/
reduce
(
numpy
.
multiply
,
denum
,
one
)
v
=
reduce
(
n
p
.
multiply
,
num
,
one
)
/
reduce
(
np
.
multiply
,
denum
,
one
)
if
aslist
:
if
aslist
:
if
n
umpy
.
all
(
v
==
1
):
if
n
p
.
all
(
v
==
1
):
return
[]
return
[]
else
:
else
:
return
[
v
]
return
[
v
]
...
@@ -5053,7 +5053,7 @@ register_canonicalize(local_mul_canonizer, name='local_mul_canonizer')
...
@@ -5053,7 +5053,7 @@ register_canonicalize(local_mul_canonizer, name='local_mul_canonizer')
@gof.local_optimizer
([
T
.
neg
])
@gof.local_optimizer
([
T
.
neg
])
def
local_neg_to_mul
(
node
):
def
local_neg_to_mul
(
node
):
if
node
.
op
==
T
.
neg
:
if
node
.
op
==
T
.
neg
:
return
[
T
.
mul
(
n
umpy
.
array
(
-
1
,
dtype
=
node
.
inputs
[
0
]
.
dtype
),
return
[
T
.
mul
(
n
p
.
array
(
-
1
,
dtype
=
node
.
inputs
[
0
]
.
dtype
),
node
.
inputs
[
0
])]
node
.
inputs
[
0
])]
register_canonicalize
(
local_neg_to_mul
)
register_canonicalize
(
local_neg_to_mul
)
...
@@ -5078,13 +5078,13 @@ def local_sum_prod_mul_by_scalar(node):
...
@@ -5078,13 +5078,13 @@ def local_sum_prod_mul_by_scalar(node):
if
node_inps
.
owner
and
node_inps
.
owner
.
op
==
T
.
mul
:
if
node_inps
.
owner
and
node_inps
.
owner
.
op
==
T
.
mul
:
terms
=
node_inps
.
owner
.
inputs
terms
=
node_inps
.
owner
.
inputs
scalars
=
[
t
.
dimshuffle
()
for
t
in
terms
if
scalars
=
[
t
.
dimshuffle
()
for
t
in
terms
if
n
umpy
.
all
(
t
.
type
.
broadcastable
)]
n
p
.
all
(
t
.
type
.
broadcastable
)]
if
len
(
scalars
)
==
0
:
if
len
(
scalars
)
==
0
:
# Nothing to optimize here
# Nothing to optimize here
return
return
non_scalars
=
[
t
for
t
in
terms
if
not
n
umpy
.
all
(
t
.
broadcastable
)]
non_scalars
=
[
t
for
t
in
terms
if
not
n
p
.
all
(
t
.
broadcastable
)]
# Perform the op only on the non-scalar inputs, if applicable
# Perform the op only on the non-scalar inputs, if applicable
if
len
(
non_scalars
)
==
0
:
if
len
(
non_scalars
)
==
0
:
...
@@ -5780,7 +5780,7 @@ def local_neg_div_neg(node):
...
@@ -5780,7 +5780,7 @@ def local_neg_div_neg(node):
# No other clients of the original division
# No other clients of the original division
new_num
=
num
.
owner
.
inputs
[
0
]
new_num
=
num
.
owner
.
inputs
[
0
]
return
[
T
.
true_div
(
new_num
,
denom
)]
return
[
T
.
true_div
(
new_num
,
denom
)]
elif
n
umpy
.
all
(
num
.
broadcastable
)
and
isinstance
(
num
,
Constant
):
elif
n
p
.
all
(
num
.
broadcastable
)
and
isinstance
(
num
,
Constant
):
if
len
(
frac
.
clients
)
==
1
:
if
len
(
frac
.
clients
)
==
1
:
new_num
=
-
num
.
data
new_num
=
-
num
.
data
return
[
T
.
true_div
(
new_num
,
denom
)]
return
[
T
.
true_div
(
new_num
,
denom
)]
...
@@ -5811,7 +5811,7 @@ register_canonicalize(local_mul_zero)
...
@@ -5811,7 +5811,7 @@ register_canonicalize(local_mul_zero)
@gof.local_optimizer
([
T
.
true_div
])
@gof.local_optimizer
([
T
.
true_div
])
def
local_div_to_inv
(
node
):
def
local_div_to_inv
(
node
):
if
node
.
op
==
T
.
true_div
and
n
umpy
.
all
(
if
node
.
op
==
T
.
true_div
and
n
p
.
all
(
local_mul_canonizer
.
get_constant
(
node
.
inputs
[
0
])
==
1.0
):
local_mul_canonizer
.
get_constant
(
node
.
inputs
[
0
])
==
1.0
):
out
=
node
.
outputs
[
0
]
out
=
node
.
outputs
[
0
]
new_out
=
T
.
inv
(
local_mul_canonizer
.
merge_num_denum
(
node
.
inputs
[
1
:],
new_out
=
T
.
inv
(
local_mul_canonizer
.
merge_num_denum
(
node
.
inputs
[
1
:],
...
@@ -5873,7 +5873,7 @@ def local_intdiv_by_one(node):
...
@@ -5873,7 +5873,7 @@ def local_intdiv_by_one(node):
"""
"""
if
node
.
op
in
[
T
.
int_div
]:
if
node
.
op
in
[
T
.
int_div
]:
if
isinstance
(
node
.
inputs
[
1
],
T
.
TensorConstant
)
and
\
if
isinstance
(
node
.
inputs
[
1
],
T
.
TensorConstant
)
and
\
n
umpy
.
all
(
node
.
inputs
[
1
]
.
value
==
1
):
n
p
.
all
(
node
.
inputs
[
1
]
.
value
==
1
):
return
[
node
.
inputs
[
0
]
.
astype
(
node
.
outputs
[
0
]
.
dtype
)]
return
[
node
.
inputs
[
0
]
.
astype
(
node
.
outputs
[
0
]
.
dtype
)]
...
@@ -5906,19 +5906,19 @@ def local_pow_specialize(node):
...
@@ -5906,19 +5906,19 @@ def local_pow_specialize(node):
ysym
.
type
.
broadcastable
):
ysym
.
type
.
broadcastable
):
rval
=
None
rval
=
None
if
n
umpy
.
all
(
y
==
2
):
if
n
p
.
all
(
y
==
2
):
rval
=
[
T
.
sqr
(
xsym
)]
rval
=
[
T
.
sqr
(
xsym
)]
if
n
umpy
.
all
(
y
==
1
):
if
n
p
.
all
(
y
==
1
):
rval
=
[
xsym
]
rval
=
[
xsym
]
if
n
umpy
.
all
(
y
==
0
):
if
n
p
.
all
(
y
==
0
):
rval
=
[
T
.
fill
(
xsym
,
n
umpy
.
asarray
(
1
,
dtype
=
odtype
))]
rval
=
[
T
.
fill
(
xsym
,
n
p
.
asarray
(
1
,
dtype
=
odtype
))]
if
n
umpy
.
all
(
y
==
0.5
):
if
n
p
.
all
(
y
==
0.5
):
rval
=
[
T
.
sqrt
(
xsym
)]
rval
=
[
T
.
sqrt
(
xsym
)]
if
n
umpy
.
all
(
y
==
-
0.5
):
if
n
p
.
all
(
y
==
-
0.5
):
rval
=
[
T
.
inv
(
T
.
sqrt
(
xsym
))]
rval
=
[
T
.
inv
(
T
.
sqrt
(
xsym
))]
if
n
umpy
.
all
(
y
==
-
1
):
if
n
p
.
all
(
y
==
-
1
):
rval
=
[
T
.
inv
(
xsym
)]
rval
=
[
T
.
inv
(
xsym
)]
if
n
umpy
.
all
(
y
==
-
2
):
if
n
p
.
all
(
y
==
-
2
):
rval
=
[
T
.
inv
(
T
.
sqr
(
xsym
))]
rval
=
[
T
.
inv
(
T
.
sqr
(
xsym
))]
if
rval
:
if
rval
:
rval
[
0
]
=
T
.
cast
(
rval
[
0
],
odtype
)
rval
[
0
]
=
T
.
cast
(
rval
[
0
],
odtype
)
...
@@ -5951,7 +5951,7 @@ def local_pow_specialize_device(node):
...
@@ -5951,7 +5951,7 @@ def local_pow_specialize_device(node):
# taking the value outside ndarray solve the problem.
# taking the value outside ndarray solve the problem.
# it could be that in that case, numpy make the comparaison
# it could be that in that case, numpy make the comparaison
# into the wrong type(do in int8 that overflow.)
# into the wrong type(do in int8 that overflow.)
if
isinstance
(
y
,
n
umpy
.
ndarray
):
if
isinstance
(
y
,
n
p
.
ndarray
):
assert
y
.
size
==
1
assert
y
.
size
==
1
try
:
try
:
y
=
y
[
0
]
y
=
y
[
0
]
...
@@ -5966,13 +5966,13 @@ def local_pow_specialize_device(node):
...
@@ -5966,13 +5966,13 @@ def local_pow_specialize_device(node):
pow2
=
[
xsym
]
pow2
=
[
xsym
]
pow2_scal
=
[
theano
.
scalar
.
get_scalar_type
(
xsym
.
dtype
)()]
pow2_scal
=
[
theano
.
scalar
.
get_scalar_type
(
xsym
.
dtype
)()]
y_to_do
=
abs
(
y
)
y_to_do
=
abs
(
y
)
for
i
in
xrange
(
int
(
n
umpy
.
log2
(
y_to_do
))):
for
i
in
xrange
(
int
(
n
p
.
log2
(
y_to_do
))):
pow2
.
append
(
T
.
sqr
(
pow2
[
i
]))
pow2
.
append
(
T
.
sqr
(
pow2
[
i
]))
pow2_scal
.
append
(
theano
.
scalar
.
sqr
(
pow2_scal
[
i
]))
pow2_scal
.
append
(
theano
.
scalar
.
sqr
(
pow2_scal
[
i
]))
rval1
=
None
rval1
=
None
rval1_scal
=
None
rval1_scal
=
None
while
y_to_do
>
0
:
while
y_to_do
>
0
:
log_to_do
=
int
(
n
umpy
.
log2
(
y_to_do
))
log_to_do
=
int
(
n
p
.
log2
(
y_to_do
))
if
rval1
:
if
rval1
:
rval1
*=
pow2
[
log_to_do
]
rval1
*=
pow2
[
log_to_do
]
rval1_scal
*=
pow2_scal
[
log_to_do
]
rval1_scal
*=
pow2_scal
[
log_to_do
]
...
@@ -6061,7 +6061,7 @@ def local_mul_specialize(node):
...
@@ -6061,7 +6061,7 @@ def local_mul_specialize(node):
elif
neg
:
elif
neg
:
# Don't add an extra neg node as we can't
# Don't add an extra neg node as we can't
# fully replace this mul by a neg.
# fully replace this mul by a neg.
m1
=
n
umpy
.
asarray
(
-
1
,
dtype
=
node
.
outputs
[
0
]
.
dtype
)
m1
=
n
p
.
asarray
(
-
1
,
dtype
=
node
.
outputs
[
0
]
.
dtype
)
new_inputs
=
[
m1
]
+
new_inputs
new_inputs
=
[
m1
]
+
new_inputs
rval
=
T
.
mul
(
*
new_inputs
)
rval
=
T
.
mul
(
*
new_inputs
)
...
@@ -6092,7 +6092,7 @@ def local_add_specialize(node):
...
@@ -6092,7 +6092,7 @@ def local_add_specialize(node):
y
=
get_scalar_constant_value
(
input
)
y
=
get_scalar_constant_value
(
input
)
except
NotScalarConstantError
:
except
NotScalarConstantError
:
y
=
input
y
=
input
if
n
umpy
.
all
(
y
==
0.0
):
if
n
p
.
all
(
y
==
0.0
):
continue
continue
new_inputs
.
append
(
input
)
new_inputs
.
append
(
input
)
...
@@ -6102,7 +6102,7 @@ def local_add_specialize(node):
...
@@ -6102,7 +6102,7 @@ def local_add_specialize(node):
# we got rid of the entire expression!
# we got rid of the entire expression!
ndim
=
node
.
outputs
[
0
]
.
type
.
ndim
ndim
=
node
.
outputs
[
0
]
.
type
.
ndim
# Reuse call to constant for cache()
# Reuse call to constant for cache()
cst
=
T
.
constant
(
n
umpy
.
zeros
((
1
,)
*
ndim
,
dtype
=
dtype
))
cst
=
T
.
constant
(
n
p
.
zeros
((
1
,)
*
ndim
,
dtype
=
dtype
))
assert
cst
.
type
.
broadcastable
==
(
True
,)
*
ndim
assert
cst
.
type
.
broadcastable
==
(
True
,)
*
ndim
return
fill_chain
(
cst
)
return
fill_chain
(
cst
)
...
@@ -6209,7 +6209,7 @@ def local_log1p(node):
...
@@ -6209,7 +6209,7 @@ def local_log1p(node):
scalars
,
scalar_inputs
,
nonconsts
=
scalarconsts_rest
(
scalars
,
scalar_inputs
,
nonconsts
=
scalarconsts_rest
(
log_arg
.
owner
.
inputs
,
only_process_constants
=
True
)
log_arg
.
owner
.
inputs
,
only_process_constants
=
True
)
# scalar_inputs are potentially dimshuffled and fill'd scalars
# scalar_inputs are potentially dimshuffled and fill'd scalars
if
scalars
and
n
umpy
.
allclose
(
numpy
.
sum
(
scalars
),
1
):
if
scalars
and
n
p
.
allclose
(
np
.
sum
(
scalars
),
1
):
if
nonconsts
:
if
nonconsts
:
if
len
(
nonconsts
)
>
1
:
if
len
(
nonconsts
)
>
1
:
ninp
=
T
.
add
(
*
nonconsts
)
ninp
=
T
.
add
(
*
nonconsts
)
...
@@ -6315,9 +6315,9 @@ def add_calculate(num, denum, aslist=False, out_type=None):
...
@@ -6315,9 +6315,9 @@ def add_calculate(num, denum, aslist=False, out_type=None):
zero
=
theano
.
_asarray
(
0
,
dtype
=
out_type
.
dtype
)
zero
=
theano
.
_asarray
(
0
,
dtype
=
out_type
.
dtype
)
# zero = 0.0 if out_type is None else theano._asarray(0,
# zero = 0.0 if out_type is None else theano._asarray(0,
# dtype=out_type.dtype)
# dtype=out_type.dtype)
v
=
reduce
(
n
umpy
.
add
,
num
,
zero
)
-
reduce
(
numpy
.
add
,
denum
,
zero
)
v
=
reduce
(
n
p
.
add
,
num
,
zero
)
-
reduce
(
np
.
add
,
denum
,
zero
)
if
aslist
:
if
aslist
:
if
n
umpy
.
all
(
v
==
0
):
if
n
p
.
all
(
v
==
0
):
return
[]
return
[]
else
:
else
:
return
[
v
]
return
[
v
]
...
@@ -6708,7 +6708,7 @@ def local_log_erfc(node):
...
@@ -6708,7 +6708,7 @@ def local_log_erfc(node):
node
.
tag
.
local_log_erfc_applied
=
True
node
.
tag
.
local_log_erfc_applied
=
True
x
=
node
.
inputs
[
0
]
.
owner
.
inputs
[
0
]
x
=
node
.
inputs
[
0
]
.
owner
.
inputs
[
0
]
stab_value
=
(
-
x
**
2
-
T
.
log
(
x
)
-
.
5
*
T
.
log
(
n
umpy
.
pi
)
+
stab_value
=
(
-
x
**
2
-
T
.
log
(
x
)
-
.
5
*
T
.
log
(
n
p
.
pi
)
+
T
.
log
(
1
-
1
/
(
2
*
x
**
2
)
+
3
/
(
4
*
x
**
4
)
-
T
.
log
(
1
-
1
/
(
2
*
x
**
2
)
+
3
/
(
4
*
x
**
4
)
-
15
/
(
8
*
x
**
6
)))
15
/
(
8
*
x
**
6
)))
...
@@ -6863,7 +6863,7 @@ def local_grad_log_erfc_neg(node):
...
@@ -6863,7 +6863,7 @@ def local_grad_log_erfc_neg(node):
# aaron value
# aaron value
stab_value
=
(
x
*
T
.
pow
(
1
-
1
/
(
2
*
(
x
**
2
))
+
stab_value
=
(
x
*
T
.
pow
(
1
-
1
/
(
2
*
(
x
**
2
))
+
3
/
(
4
*
(
x
**
4
))
-
15
/
(
8
*
(
x
**
6
)),
-
1
)
*
3
/
(
4
*
(
x
**
4
))
-
15
/
(
8
*
(
x
**
6
)),
-
1
)
*
T
.
cast
(
T
.
sqrt
(
n
umpy
.
pi
),
dtype
=
x
.
dtype
))
T
.
cast
(
T
.
sqrt
(
n
p
.
pi
),
dtype
=
x
.
dtype
))
if
x
.
dtype
==
'float32'
or
x
.
dtype
==
'float16'
:
if
x
.
dtype
==
'float32'
or
x
.
dtype
==
'float16'
:
threshold
=
9.3
threshold
=
9.3
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论