Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fbc28965
提交
fbc28965
authored
12月 29, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
1月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix overly strict type checks across the entire codebase
上级
44066869
显示空白字符变更
内嵌
并排
正在显示
23 个修改的文件
包含
54 行增加
和
42 行删除
+54
-42
debugmode.py
aesara/compile/debugmode.py
+4
-3
pfunc.py
aesara/compile/function/pfunc.py
+1
-1
types.py
aesara/compile/function/types.py
+1
-1
mode.py
aesara/compile/mode.py
+1
-1
opt.py
aesara/gpuarray/opt.py
+5
-3
opt_util.py
aesara/gpuarray/opt_util.py
+2
-2
rng_mrg.py
aesara/gpuarray/rng_mrg.py
+1
-1
type.py
aesara/gpuarray/type.py
+2
-2
gradient.py
aesara/gradient.py
+1
-1
rng_mrg.py
aesara/sandbox/rng_mrg.py
+4
-4
basic.py
aesara/scalar/basic.py
+2
-2
basic.py
aesara/scan/basic.py
+1
-1
op.py
aesara/scan/op.py
+3
-3
opt.py
aesara/scan/opt.py
+6
-6
basic_opt.py
aesara/tensor/basic_opt.py
+1
-1
elemwise.py
aesara/tensor/elemwise.py
+1
-1
math_opt.py
aesara/tensor/math_opt.py
+6
-1
batchnorm.py
aesara/tensor/nnet/batchnorm.py
+3
-1
neighbours.py
aesara/tensor/nnet/neighbours.py
+1
-1
subtensor_opt.py
aesara/tensor/subtensor_opt.py
+1
-1
type.rst
doc/extending/type.rst
+1
-1
test_basic.py
tests/scan/test_basic.py
+1
-1
test_subtensor_opt.py
tests/tensor/test_subtensor_opt.py
+5
-3
没有找到文件。
aesara/compile/debugmode.py
浏览文件 @
fbc28965
...
@@ -680,15 +680,16 @@ def _lessbroken_deepcopy(a):
...
@@ -680,15 +680,16 @@ def _lessbroken_deepcopy(a):
# This logic is also in link.py
# This logic is also in link.py
from
aesara.graph.type
import
_cdata_type
from
aesara.graph.type
import
_cdata_type
if
type
(
a
)
in
(
np
.
ndarray
,
np
.
memmap
):
if
isinstance
(
a
,
(
np
.
ndarray
,
np
.
memmap
)
):
rval
=
a
.
copy
(
order
=
"K"
)
rval
=
a
.
copy
(
order
=
"K"
)
elif
type
(
a
)
is
_cdata_type
:
elif
isinstance
(
a
,
_cdata_type
)
:
# This is not copyable (and should be used for constant data).
# This is not copyable (and should be used for constant data).
rval
=
a
rval
=
a
else
:
else
:
rval
=
copy
.
deepcopy
(
a
)
rval
=
copy
.
deepcopy
(
a
)
assert
type
(
rval
)
==
type
(
a
),
(
type
(
rval
),
type
(
a
))
assert
type
(
rval
)
==
type
(
a
),
(
type
(
rval
),
type
(
a
))
if
isinstance
(
rval
,
np
.
ndarray
):
if
isinstance
(
rval
,
np
.
ndarray
):
assert
rval
.
dtype
==
a
.
dtype
assert
rval
.
dtype
==
a
.
dtype
return
rval
return
rval
...
@@ -2006,7 +2007,7 @@ class _Linker(LocalLinker):
...
@@ -2006,7 +2007,7 @@ class _Linker(LocalLinker):
# HACK TO LOOK LIKE A REAL DESTRUCTIVE ACTION
# HACK TO LOOK LIKE A REAL DESTRUCTIVE ACTION
# TOOK PLACE
# TOOK PLACE
if
(
if
(
(
type
(
dr_vals
[
r
][
0
])
in
(
np
.
ndarray
,
np
.
memmap
))
isinstance
(
dr_vals
[
r
][
0
],
(
np
.
ndarray
,
np
.
memmap
))
and
(
dr_vals
[
r
][
0
]
.
dtype
==
storage_map
[
r
][
0
]
.
dtype
)
and
(
dr_vals
[
r
][
0
]
.
dtype
==
storage_map
[
r
][
0
]
.
dtype
)
and
(
dr_vals
[
r
][
0
]
.
shape
==
storage_map
[
r
][
0
]
.
shape
)
and
(
dr_vals
[
r
][
0
]
.
shape
==
storage_map
[
r
][
0
]
.
shape
)
):
):
...
...
aesara/compile/function/pfunc.py
浏览文件 @
fbc28965
...
@@ -399,7 +399,7 @@ def pfunc(
...
@@ -399,7 +399,7 @@ def pfunc(
if
profile
is
True
:
if
profile
is
True
:
profile
=
ProfileStats
(
message
=
name
)
profile
=
ProfileStats
(
message
=
name
)
# profile -> object
# profile -> object
elif
type
(
profile
)
==
str
:
elif
isinstance
(
profile
,
str
)
:
profile
=
ProfileStats
(
message
=
profile
)
profile
=
ProfileStats
(
message
=
profile
)
# profile is typically either False or an object at this point.
# profile is typically either False or an object at this point.
# No need to block other objects being passed through though. It might be
# No need to block other objects being passed through though. It might be
...
...
aesara/compile/function/types.py
浏览文件 @
fbc28965
...
@@ -731,7 +731,7 @@ class Function:
...
@@ -731,7 +731,7 @@ class Function:
message
=
str
(
profile
.
message
)
+
" copy"
message
=
str
(
profile
.
message
)
+
" copy"
profile
=
aesara
.
compile
.
profiling
.
ProfileStats
(
message
=
message
)
profile
=
aesara
.
compile
.
profiling
.
ProfileStats
(
message
=
message
)
# profile -> object
# profile -> object
elif
type
(
profile
)
==
str
:
elif
isinstance
(
profile
,
str
)
:
profile
=
aesara
.
compile
.
profiling
.
ProfileStats
(
message
=
profile
)
profile
=
aesara
.
compile
.
profiling
.
ProfileStats
(
message
=
profile
)
f_cpy
=
maker
.
__class__
(
f_cpy
=
maker
.
__class__
(
...
...
aesara/compile/mode.py
浏览文件 @
fbc28965
...
@@ -308,7 +308,7 @@ class Mode:
...
@@ -308,7 +308,7 @@ class Mode:
):
):
if
linker
is
None
:
if
linker
is
None
:
linker
=
config
.
linker
linker
=
config
.
linker
if
type
(
optimizer
)
==
str
and
optimizer
==
"default"
:
if
isinstance
(
optimizer
,
str
)
and
optimizer
==
"default"
:
optimizer
=
config
.
optimizer
optimizer
=
config
.
optimizer
self
.
__setstate__
((
linker
,
optimizer
))
self
.
__setstate__
((
linker
,
optimizer
))
...
...
aesara/gpuarray/opt.py
浏览文件 @
fbc28965
...
@@ -2263,7 +2263,7 @@ class ConvMetaOptimizer(LocalMetaOptimizer):
...
@@ -2263,7 +2263,7 @@ class ConvMetaOptimizer(LocalMetaOptimizer):
):
):
return
result
return
result
if
type
(
node
.
op
)
in
[
AbstractConv2d
,
AbstractConv3d
]
:
if
isinstance
(
node
.
op
,
(
AbstractConv2d
,
AbstractConv3d
))
:
img
,
kern
=
node
.
inputs
img
,
kern
=
node
.
inputs
for
(
var
,
shape
)
in
zip
((
img
,
kern
),
shapes
):
for
(
var
,
shape
)
in
zip
((
img
,
kern
),
shapes
):
result
[
var
]
=
aesara
.
shared
(
result
[
var
]
=
aesara
.
shared
(
...
@@ -2273,7 +2273,9 @@ class ConvMetaOptimizer(LocalMetaOptimizer):
...
@@ -2273,7 +2273,9 @@ class ConvMetaOptimizer(LocalMetaOptimizer):
borrow
=
True
,
borrow
=
True
,
)
)
if
type
(
node
.
op
)
in
[
AbstractConv2d_gradWeights
,
AbstractConv3d_gradWeights
]:
if
isinstance
(
node
.
op
,
(
AbstractConv2d_gradWeights
,
AbstractConv3d_gradWeights
)
):
img
,
top
,
kshape
=
node
.
inputs
img
,
top
,
kshape
=
node
.
inputs
tshp
=
get_conv_output_shape
(
tshp
=
get_conv_output_shape
(
...
@@ -2295,7 +2297,7 @@ class ConvMetaOptimizer(LocalMetaOptimizer):
...
@@ -2295,7 +2297,7 @@ class ConvMetaOptimizer(LocalMetaOptimizer):
borrow
=
True
,
borrow
=
True
,
)
)
if
type
(
node
.
op
)
in
[
AbstractConv2d_gradInputs
,
AbstractConv3d_gradInputs
]
:
if
isinstance
(
node
.
op
,
(
AbstractConv2d_gradInputs
,
AbstractConv3d_gradInputs
))
:
kern
,
top
,
ishape
=
node
.
inputs
kern
,
top
,
ishape
=
node
.
inputs
tshp
=
get_conv_output_shape
(
tshp
=
get_conv_output_shape
(
...
...
aesara/gpuarray/opt_util.py
浏览文件 @
fbc28965
...
@@ -358,7 +358,7 @@ def inplace_allocempty(op, idx):
...
@@ -358,7 +358,7 @@ def inplace_allocempty(op, idx):
@local_optimizer
([
op
],
inplace
=
True
)
@local_optimizer
([
op
],
inplace
=
True
)
@wraps
(
maker
)
@wraps
(
maker
)
def
opt
(
fgraph
,
node
):
def
opt
(
fgraph
,
node
):
if
type
(
node
.
op
)
!=
op
or
node
.
op
.
inplace
:
if
not
isinstance
(
node
.
op
,
op
)
or
node
.
op
.
inplace
:
return
return
inputs
=
list
(
node
.
inputs
)
inputs
=
list
(
node
.
inputs
)
alloc
=
inputs
[
idx
]
alloc
=
inputs
[
idx
]
...
@@ -460,7 +460,7 @@ def op_lifter(OP, cuda_only=False):
...
@@ -460,7 +460,7 @@ def op_lifter(OP, cuda_only=False):
def
f
(
maker
):
def
f
(
maker
):
def
local_opt
(
fgraph
,
node
):
def
local_opt
(
fgraph
,
node
):
if
type
(
node
.
op
)
in
OP
:
if
isinstance
(
node
.
op
,
OP
)
:
# Either one of our inputs is on the gpu or
# Either one of our inputs is on the gpu or
# all of our clients are on the gpu
# all of our clients are on the gpu
replace
=
False
replace
=
False
...
...
aesara/gpuarray/rng_mrg.py
浏览文件 @
fbc28965
...
@@ -331,7 +331,7 @@ class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base):
...
@@ -331,7 +331,7 @@ class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base):
@register_opt2
([
mrg_uniform
],
"fast_compile"
)
@register_opt2
([
mrg_uniform
],
"fast_compile"
)
def
local_gpua_mrg_graph
(
fgraph
,
op
,
context_name
,
inputs
,
outputs
):
def
local_gpua_mrg_graph
(
fgraph
,
op
,
context_name
,
inputs
,
outputs
):
if
(
if
(
type
(
op
)
==
mrg_uniform
isinstance
(
op
,
mrg_uniform
)
and
isinstance
(
inputs
[
0
]
.
type
,
GpuArrayType
)
and
isinstance
(
inputs
[
0
]
.
type
,
GpuArrayType
)
and
(
inputs
[
0
]
.
owner
is
None
or
not
isinstance
(
inputs
[
0
]
.
owner
.
op
,
GpuFromHost
))
and
(
inputs
[
0
]
.
owner
is
None
or
not
isinstance
(
inputs
[
0
]
.
owner
.
op
,
GpuFromHost
))
):
):
...
...
aesara/gpuarray/type.py
浏览文件 @
fbc28965
...
@@ -279,7 +279,7 @@ class GpuArrayType(CType):
...
@@ -279,7 +279,7 @@ class GpuArrayType(CType):
# fallthrough to ndim check
# fallthrough to ndim check
elif
allow_downcast
or
(
elif
allow_downcast
or
(
allow_downcast
is
None
allow_downcast
is
None
and
type
(
data
)
==
float
and
isinstance
(
data
,
float
)
and
self
.
dtype
==
config
.
floatX
and
self
.
dtype
==
config
.
floatX
):
):
if
not
isinstance
(
data
,
gpuarray
.
GpuArray
):
if
not
isinstance
(
data
,
gpuarray
.
GpuArray
):
...
@@ -427,7 +427,7 @@ class GpuArrayType(CType):
...
@@ -427,7 +427,7 @@ class GpuArrayType(CType):
def
convert_variable
(
self
,
var
):
def
convert_variable
(
self
,
var
):
vt
=
var
.
type
vt
=
var
.
type
if
(
if
(
type
(
self
)
==
type
(
vt
)
isinstance
(
vt
,
type
(
self
)
)
and
self
.
typecode
==
vt
.
typecode
and
self
.
typecode
==
vt
.
typecode
and
self
.
ndim
==
vt
.
ndim
and
self
.
ndim
==
vt
.
ndim
and
self
.
context_name
==
vt
.
context_name
and
self
.
context_name
==
vt
.
context_name
...
...
aesara/gradient.py
浏览文件 @
fbc28965
...
@@ -386,7 +386,7 @@ def Lop(f, wrt, eval_points, consider_constant=None, disconnected_inputs="raise"
...
@@ -386,7 +386,7 @@ def Lop(f, wrt, eval_points, consider_constant=None, disconnected_inputs="raise"
coordinates of the tensor element in the last
coordinates of the tensor element in the last
If `f` is a list/tuple, then return a list/tuple with the results.
If `f` is a list/tuple, then return a list/tuple with the results.
"""
"""
if
type
(
eval_points
)
not
in
(
list
,
tuple
):
if
not
isinstance
(
eval_points
,
(
list
,
tuple
)
):
eval_points
=
[
eval_points
]
eval_points
=
[
eval_points
]
using_list
=
isinstance
(
wrt
,
list
)
using_list
=
isinstance
(
wrt
,
list
)
...
...
aesara/sandbox/rng_mrg.py
浏览文件 @
fbc28965
...
@@ -268,13 +268,13 @@ def ff_2p72(rstate):
...
@@ -268,13 +268,13 @@ def ff_2p72(rstate):
def
mrg_next_value
(
rstate
,
new_rstate
,
NORM
,
mask
,
offset
):
def
mrg_next_value
(
rstate
,
new_rstate
,
NORM
,
mask
,
offset
):
# TODO : need description for method, parameter and return
# TODO : need description for method, parameter and return
x11
,
x12
,
x13
,
x21
,
x22
,
x23
=
rstate
x11
,
x12
,
x13
,
x21
,
x22
,
x23
=
rstate
assert
type
(
x11
)
==
np
.
int32
assert
isinstance
(
x11
,
np
.
int32
)
i0
,
i7
,
i9
,
i15
,
i16
,
i22
,
i24
=
np_int32_vals
i0
,
i7
,
i9
,
i15
,
i16
,
i22
,
i24
=
np_int32_vals
# first component
# first component
y1
=
((
x12
&
MASK12
)
<<
i22
)
+
(
x12
>>
i9
)
+
((
x13
&
MASK13
)
<<
i7
)
+
(
x13
>>
i24
)
y1
=
((
x12
&
MASK12
)
<<
i22
)
+
(
x12
>>
i9
)
+
((
x13
&
MASK13
)
<<
i7
)
+
(
x13
>>
i24
)
assert
type
(
y1
)
==
np
.
int32
assert
isinstance
(
y1
,
np
.
int32
)
if
y1
<
0
or
y1
>=
M1
:
# must also check overflow
if
y1
<
0
or
y1
>=
M1
:
# must also check overflow
y1
-=
M1
y1
-=
M1
y1
+=
x13
y1
+=
x13
...
@@ -287,11 +287,11 @@ def mrg_next_value(rstate, new_rstate, NORM, mask, offset):
...
@@ -287,11 +287,11 @@ def mrg_next_value(rstate, new_rstate, NORM, mask, offset):
# second component
# second component
y1
=
((
x21
&
MASK2
)
<<
i15
)
+
(
MULT2
*
(
x21
>>
i16
))
y1
=
((
x21
&
MASK2
)
<<
i15
)
+
(
MULT2
*
(
x21
>>
i16
))
assert
type
(
y1
)
==
np
.
int32
assert
isinstance
(
y1
,
np
.
int32
)
if
y1
<
0
or
y1
>=
M2
:
if
y1
<
0
or
y1
>=
M2
:
y1
-=
M2
y1
-=
M2
y2
=
((
x23
&
MASK2
)
<<
i15
)
+
(
MULT2
*
(
x23
>>
i16
))
y2
=
((
x23
&
MASK2
)
<<
i15
)
+
(
MULT2
*
(
x23
>>
i16
))
assert
type
(
y2
)
==
np
.
int32
assert
isinstance
(
y2
,
np
.
int32
)
if
y2
<
0
or
y2
>=
M2
:
if
y2
<
0
or
y2
>=
M2
:
y2
-=
M2
y2
-=
M2
y2
+=
x23
y2
+=
x23
...
...
aesara/scalar/basic.py
浏览文件 @
fbc28965
...
@@ -961,7 +961,7 @@ class transfer_type(MetaObject):
...
@@ -961,7 +961,7 @@ class transfer_type(MetaObject):
__props__
=
(
"transfer"
,)
__props__
=
(
"transfer"
,)
def
__init__
(
self
,
*
transfer
):
def
__init__
(
self
,
*
transfer
):
assert
all
(
type
(
x
)
in
[
int
,
str
]
or
x
is
None
for
x
in
transfer
)
assert
all
(
isinstance
(
x
,
(
int
,
str
))
or
x
is
None
for
x
in
transfer
)
self
.
transfer
=
transfer
self
.
transfer
=
transfer
def
__str__
(
self
):
def
__str__
(
self
):
...
@@ -4363,7 +4363,7 @@ class Compositef32:
...
@@ -4363,7 +4363,7 @@ class Compositef32:
else
:
else
:
ni
=
i
ni
=
i
mapping
[
i
]
=
ni
mapping
[
i
]
=
ni
if
type
(
node
.
op
)
in
self
.
special
:
if
isinstance
(
node
.
op
,
tuple
(
self
.
special
.
keys
()))
:
self
.
special
[
type
(
node
.
op
)](
node
,
mapping
)
self
.
special
[
type
(
node
.
op
)](
node
,
mapping
)
continue
continue
new_node
=
node
.
clone_with_new_inputs
(
new_node
=
node
.
clone_with_new_inputs
(
...
...
aesara/scan/basic.py
浏览文件 @
fbc28965
...
@@ -1073,7 +1073,7 @@ def scan(
...
@@ -1073,7 +1073,7 @@ def scan(
pass
pass
scan_inputs
+=
[
arg
]
scan_inputs
+=
[
arg
]
scan_outs
=
local_op
(
*
scan_inputs
)
scan_outs
=
local_op
(
*
scan_inputs
)
if
type
(
scan_outs
)
not
in
(
list
,
tuple
):
if
not
isinstance
(
scan_outs
,
(
list
,
tuple
)
):
scan_outs
=
[
scan_outs
]
scan_outs
=
[
scan_outs
]
##
##
# Step 9. Figure out which outs are update rules for shared variables
# Step 9. Figure out which outs are update rules for shared variables
...
...
aesara/scan/op.py
浏览文件 @
fbc28965
...
@@ -2778,7 +2778,7 @@ class Scan(Op, ScanMethodsMixin, HasInnerGraph):
...
@@ -2778,7 +2778,7 @@ class Scan(Op, ScanMethodsMixin, HasInnerGraph):
allow_gc
=
self
.
allow_gc
,
allow_gc
=
self
.
allow_gc
,
)
)
outputs
=
local_op
(
*
outer_inputs
)
outputs
=
local_op
(
*
outer_inputs
)
if
type
(
outputs
)
not
in
(
list
,
tuple
):
if
not
isinstance
(
outputs
,
(
list
,
tuple
)
):
outputs
=
[
outputs
]
outputs
=
[
outputs
]
# Re-order the gradients correctly
# Re-order the gradients correctly
gradients
=
[
DisconnectedType
()()]
gradients
=
[
DisconnectedType
()()]
...
@@ -2922,7 +2922,7 @@ class Scan(Op, ScanMethodsMixin, HasInnerGraph):
...
@@ -2922,7 +2922,7 @@ class Scan(Op, ScanMethodsMixin, HasInnerGraph):
if
self
.
info
.
n_shared_outs
>
0
:
if
self
.
info
.
n_shared_outs
>
0
:
rop_self_outputs
=
rop_self_outputs
[:
-
self
.
info
.
n_shared_outs
]
rop_self_outputs
=
rop_self_outputs
[:
-
self
.
info
.
n_shared_outs
]
rop_outs
=
Rop
(
rop_self_outputs
,
rop_of_inputs
,
inner_eval_points
)
rop_outs
=
Rop
(
rop_self_outputs
,
rop_of_inputs
,
inner_eval_points
)
if
type
(
rop_outs
)
not
in
(
list
,
tuple
):
if
not
isinstance
(
rop_outs
,
(
list
,
tuple
)
):
rop_outs
=
[
rop_outs
]
rop_outs
=
[
rop_outs
]
# Step 2. Figure out what corresponds to what in the scan
# Step 2. Figure out what corresponds to what in the scan
...
@@ -3112,7 +3112,7 @@ class Scan(Op, ScanMethodsMixin, HasInnerGraph):
...
@@ -3112,7 +3112,7 @@ class Scan(Op, ScanMethodsMixin, HasInnerGraph):
allow_gc
=
self
.
allow_gc
,
allow_gc
=
self
.
allow_gc
,
)
)
outputs
=
local_op
(
*
scan_inputs
)
outputs
=
local_op
(
*
scan_inputs
)
if
type
(
outputs
)
not
in
(
list
,
tuple
):
if
not
isinstance
(
outputs
,
(
list
,
tuple
)
):
outputs
=
[
outputs
]
outputs
=
[
outputs
]
# Select only the result of the R_op results
# Select only the result of the R_op results
final_outs
=
[]
final_outs
=
[]
...
...
aesara/scan/opt.py
浏览文件 @
fbc28965
...
@@ -1200,7 +1200,7 @@ def save_mem_new_scan(fgraph, node):
...
@@ -1200,7 +1200,7 @@ def save_mem_new_scan(fgraph, node):
# 2.1 outputs of the function
# 2.1 outputs of the function
# => output needs all its intermediate values
# => output needs all its intermediate values
if
type
(
cl
)
==
str
:
if
isinstance
(
cl
,
str
)
:
# if the node is actually an output, then
# if the node is actually an output, then
# we need to store the entire thing
# we need to store the entire thing
global_nsteps
=
None
global_nsteps
=
None
...
@@ -1263,13 +1263,13 @@ def save_mem_new_scan(fgraph, node):
...
@@ -1263,13 +1263,13 @@ def save_mem_new_scan(fgraph, node):
if
isinstance
(
stop
,
Variable
):
if
isinstance
(
stop
,
Variable
):
global_nsteps
[
"sym"
]
+=
[
stop
]
global_nsteps
[
"sym"
]
+=
[
stop
]
# not if it is maxsize
# not if it is maxsize
elif
type
(
stop
)
==
int
and
stop
==
maxsize
:
elif
isinstance
(
stop
,
int
)
and
stop
==
maxsize
:
global_nsteps
=
None
global_nsteps
=
None
# yes if it is a int k, 0 < k < maxsize
# yes if it is a int k, 0 < k < maxsize
elif
type
(
stop
)
==
int
and
global_nsteps
[
"real"
]
<
stop
:
elif
isinstance
(
stop
,
int
)
and
global_nsteps
[
"real"
]
<
stop
:
global_nsteps
[
"real"
]
=
stop
global_nsteps
[
"real"
]
=
stop
# yes if it is a int k, 0 < k < maxsize
# yes if it is a int k, 0 < k < maxsize
elif
type
(
stop
)
==
int
and
stop
>
0
:
elif
isinstance
(
stop
,
int
)
and
stop
>
0
:
pass
pass
# not otherwise
# not otherwise
else
:
else
:
...
@@ -1311,7 +1311,7 @@ def save_mem_new_scan(fgraph, node):
...
@@ -1311,7 +1311,7 @@ def save_mem_new_scan(fgraph, node):
for
i
,
out
in
enumerate
(
node
.
outputs
[:
c_outs
]):
for
i
,
out
in
enumerate
(
node
.
outputs
[:
c_outs
]):
# look at all its clients
# look at all its clients
for
cl
,
_
in
fgraph
.
clients
[
out
]:
for
cl
,
_
in
fgraph
.
clients
[
out
]:
if
type
(
cl
)
==
str
:
if
isinstance
(
cl
,
str
)
:
store_steps
[
i
]
=
0
store_steps
[
i
]
=
0
break
break
elif
not
isinstance
(
cl
.
op
,
Subtensor
):
elif
not
isinstance
(
cl
.
op
,
Subtensor
):
...
@@ -2275,7 +2275,7 @@ def push_out_dot1_scan(fgraph, node):
...
@@ -2275,7 +2275,7 @@ def push_out_dot1_scan(fgraph, node):
)
)
new_outs
=
new_op
(
*
_scan_inputs
)
new_outs
=
new_op
(
*
_scan_inputs
)
if
type
(
new_outs
)
not
in
(
list
,
tuple
):
if
not
isinstance
(
new_outs
,
(
list
,
tuple
)
):
new_outs
=
[
new_outs
]
new_outs
=
[
new_outs
]
# We need now to pair correctly the new outputs
# We need now to pair correctly the new outputs
...
...
aesara/tensor/basic_opt.py
浏览文件 @
fbc28965
...
@@ -262,7 +262,7 @@ class InplaceElemwiseOptimizer(GlobalOptimizer):
...
@@ -262,7 +262,7 @@ class InplaceElemwiseOptimizer(GlobalOptimizer):
for
node
in
list
(
io_toposort
(
fgraph
.
inputs
,
fgraph
.
outputs
)):
for
node
in
list
(
io_toposort
(
fgraph
.
inputs
,
fgraph
.
outputs
)):
op
=
node
.
op
op
=
node
.
op
# gpuarray GpuElemwise inherit from Elemwise
# gpuarray GpuElemwise inherit from Elemwise
if
not
type
(
op
)
==
self
.
op
:
if
not
isinstance
(
op
,
self
.
op
)
:
continue
continue
# If big graph and the outputs are scalar, do not make it
# If big graph and the outputs are scalar, do not make it
# inplace.
# inplace.
...
...
aesara/tensor/elemwise.py
浏览文件 @
fbc28965
...
@@ -223,7 +223,7 @@ class DimShuffle(ExternalCOp):
...
@@ -223,7 +223,7 @@ class DimShuffle(ExternalCOp):
(
res
,)
=
inp
(
res
,)
=
inp
(
storage
,)
=
out
(
storage
,)
=
out
if
type
(
res
)
!=
np
.
ndarray
and
type
(
res
)
!=
np
.
memmap
:
if
not
isinstance
(
res
,
(
np
.
ndarray
,
np
.
memmap
))
:
raise
TypeError
(
res
)
raise
TypeError
(
res
)
res
=
res
.
transpose
(
self
.
transposition
)
res
=
res
.
transpose
(
self
.
transposition
)
...
...
aesara/tensor/math_opt.py
浏览文件 @
fbc28965
...
@@ -1695,7 +1695,12 @@ def local_reduce_broadcastable(fgraph, node):
...
@@ -1695,7 +1695,12 @@ def local_reduce_broadcastable(fgraph, node):
new_reduced
=
reduced
.
dimshuffle
(
*
pattern
)
new_reduced
=
reduced
.
dimshuffle
(
*
pattern
)
if
new_axis
:
if
new_axis
:
if
type
(
node
.
op
)
==
CAReduce
:
if
type
(
node
.
op
)
==
CAReduce
:
# This happen for at_max(), at_min()
# This case handles `CAReduce` instances
# (e.g. generated by `scalar_elemwise`), and not the
# scalar `Op`-specific subclasses
# TODO FIXME: This highlights a major design flaw in
# `CAReduce` (or at least our use of it), and it needs
# to be fixed
new_op
=
node
.
op
.
__class__
(
node
.
op
.
scalar_op
,
axis
=
new_axis
)
new_op
=
node
.
op
.
__class__
(
node
.
op
.
scalar_op
,
axis
=
new_axis
)
else
:
else
:
new_op
=
node
.
op
.
__class__
(
axis
=
new_axis
)
new_op
=
node
.
op
.
__class__
(
axis
=
new_axis
)
...
...
aesara/tensor/nnet/batchnorm.py
浏览文件 @
fbc28965
...
@@ -736,7 +736,9 @@ class AbstractBatchNormTrainGrad(Op):
...
@@ -736,7 +736,9 @@ class AbstractBatchNormTrainGrad(Op):
aesara
.
gradient
.
DisconnectedType
()(),
aesara
.
gradient
.
DisconnectedType
()(),
]
]
return
[
return
[
aesara
.
gradient
.
DisconnectedType
()()
if
(
type
(
r
)
==
int
and
r
==
0
)
else
r
aesara
.
gradient
.
DisconnectedType
()()
if
(
isinstance
(
r
,
int
)
and
r
==
0
)
else
r
for
r
in
results
for
r
in
results
]
]
...
...
aesara/tensor/nnet/neighbours.py
浏览文件 @
fbc28965
...
@@ -195,7 +195,7 @@ class Images2Neibs(COp):
...
@@ -195,7 +195,7 @@ class Images2Neibs(COp):
ten4
,
neib_shape
,
neib_step
=
inp
ten4
,
neib_shape
,
neib_step
=
inp
(
z
,)
=
out_
(
z
,)
=
out_
# GpuImages2Neibs should not run this perform in DebugMode
# GpuImages2Neibs should not run this perform in DebugMode
if
type
(
self
)
!=
Images2Neibs
:
if
not
isinstance
(
self
,
Images2Neibs
)
:
raise
aesara
.
graph
.
utils
.
MethodNotDefined
()
raise
aesara
.
graph
.
utils
.
MethodNotDefined
()
def
CEIL_INTDIV
(
a
,
b
):
def
CEIL_INTDIV
(
a
,
b
):
...
...
aesara/tensor/subtensor_opt.py
浏览文件 @
fbc28965
...
@@ -656,7 +656,7 @@ def local_subtensor_of_alloc(fgraph, node):
...
@@ -656,7 +656,7 @@ def local_subtensor_of_alloc(fgraph, node):
if
nw_val
.
ndim
>
len
(
nw_dims
):
if
nw_val
.
ndim
>
len
(
nw_dims
):
return
False
return
False
rval
=
alloc
(
nw_val
,
*
nw_dims
)
rval
=
alloc
(
nw_val
,
*
nw_dims
)
if
type
(
rval
)
not
in
(
list
,
tuple
):
if
not
isinstance
(
rval
,
(
list
,
tuple
)
):
rval
=
[
rval
]
rval
=
[
rval
]
if
rval
[
0
]
.
type
!=
node
.
outputs
[
0
]
.
type
:
if
rval
[
0
]
.
type
!=
node
.
outputs
[
0
]
.
type
:
# It happen that the make_node() isn't able to infer the same pattern.
# It happen that the make_node() isn't able to infer the same pattern.
...
...
doc/extending/type.rst
浏览文件 @
fbc28965
...
@@ -345,7 +345,7 @@ There are several ways to make sure that equality testing works properly:
...
@@ -345,7 +345,7 @@ There are several ways to make sure that equality testing works properly:
.. testcode::
.. testcode::
def __eq__(self, other):
def __eq__(self, other):
return type(self)
is Double and type(other) is Double
return type(self)
== type(other)
#. Override :meth:`Double.__new__` to always return the same instance.
#. Override :meth:`Double.__new__` to always return the same instance.
#. Hide the Double class and only advertise a single instance of it.
#. Hide the Double class and only advertise a single instance of it.
...
...
tests/scan/test_basic.py
浏览文件 @
fbc28965
...
@@ -209,7 +209,7 @@ class multiple_outputs_numeric_grad:
...
@@ -209,7 +209,7 @@ class multiple_outputs_numeric_grad:
def
scan_project_sum
(
*
args
,
**
kwargs
):
def
scan_project_sum
(
*
args
,
**
kwargs
):
rng
=
RandomStream
(
123
)
rng
=
RandomStream
(
123
)
scan_outputs
,
updates
=
scan
(
*
args
,
**
kwargs
)
scan_outputs
,
updates
=
scan
(
*
args
,
**
kwargs
)
if
type
(
scan_outputs
)
not
in
[
list
,
tuple
]
:
if
not
isinstance
(
scan_outputs
,
(
list
,
tuple
))
:
scan_outputs
=
[
scan_outputs
]
scan_outputs
=
[
scan_outputs
]
# we should ignore the random-state updates so that
# we should ignore the random-state updates so that
# the uniform numbers are the same every evaluation and on every call
# the uniform numbers are the same every evaluation and on every call
...
...
tests/tensor/test_subtensor_opt.py
浏览文件 @
fbc28965
...
@@ -339,15 +339,17 @@ def test_local_subtensor_remove_broadcastable_index():
...
@@ -339,15 +339,17 @@ def test_local_subtensor_remove_broadcastable_index():
z8
=
y3
[
0
,
:,
0
,
:,
0
]
z8
=
y3
[
0
,
:,
0
,
:,
0
]
f
=
function
([
x
],
[
z1
,
z2
,
z3
,
z4
,
z5
,
z6
,
z7
,
z8
],
mode
=
mode
)
f
=
function
([
x
],
[
z1
,
z2
,
z3
,
z4
,
z5
,
z6
,
z7
,
z8
],
mode
=
mode
)
for
elem
in
f
.
maker
.
fgraph
.
toposort
():
for
elem
in
f
.
maker
.
fgraph
.
toposort
():
assert
type
(
elem
.
op
)
not
in
[
assert
not
isinstance
(
elem
.
op
,
(
Subtensor
,
Subtensor
,
AdvancedSubtensor
,
AdvancedSubtensor
,
AdvancedSubtensor1
,
AdvancedSubtensor1
,
IncSubtensor
,
IncSubtensor
,
AdvancedIncSubtensor
,
AdvancedIncSubtensor
,
AdvancedIncSubtensor1
,
AdvancedIncSubtensor1
,
]
),
)
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
xn
=
rng
.
random
((
5
,
5
))
xn
=
rng
.
random
((
5
,
5
))
f
(
xn
)
f
(
xn
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论