Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
93825dcc
提交
93825dcc
authored
7月 07, 2024
作者:
Virgile Andreani
提交者:
Virgile Andreani
7月 12, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace % formatting with f-strings
上级
55b2f4fa
隐藏空白字符变更
内嵌
并排
正在显示
22 个修改的文件
包含
115 行增加
和
133 行删除
+115
-133
generate_dtype_tensor_table.py
doc/generate_dtype_tensor_table.py
+1
-1
monitormode.py
pytensor/compile/monitormode.py
+2
-2
profiling.py
pytensor/compile/profiling.py
+4
-7
basic.py
pytensor/link/c/basic.py
+17
-19
op.py
pytensor/link/c/op.py
+10
-17
type.py
pytensor/link/c/type.py
+17
-17
check_duplicate_key.py
pytensor/misc/check_duplicate_key.py
+1
-1
printing.py
pytensor/printing.py
+1
-1
blas.py
pytensor/tensor/blas.py
+1
-1
math.py
pytensor/tensor/math.py
+23
-27
math.py
pytensor/tensor/rewriting/math.py
+1
-1
shape.py
pytensor/tensor/shape.py
+1
-1
subtensor.py
pytensor/tensor/subtensor.py
+3
-3
test_types.py
tests/compile/function/test_types.py
+2
-2
test_debugmode.py
tests/compile/test_debugmode.py
+15
-15
test_misc.py
tests/compile/test_misc.py
+1
-1
test_monitormode.py
tests/compile/test_monitormode.py
+6
-6
test_profiling.py
tests/compile/test_profiling.py
+1
-1
test_features.py
tests/graph/test_features.py
+2
-2
test_basic.py
tests/scan/test_basic.py
+1
-2
test_blas.py
tests/tensor/test_blas.py
+3
-4
test_math.py
tests/tensor/test_math.py
+2
-2
没有找到文件。
doc/generate_dtype_tensor_table.py
浏览文件 @
93825dcc
...
@@ -31,7 +31,7 @@ for letter in letters:
...
@@ -31,7 +31,7 @@ for letter in letters:
if
len
(
shape
[
1
])
<
6
or
len
(
set
(
shape
[
1
]))
>
1
:
if
len
(
shape
[
1
])
<
6
or
len
(
set
(
shape
[
1
]))
>
1
:
broadcastable_str
=
str
(
shape
[
1
])
broadcastable_str
=
str
(
shape
[
1
])
else
:
else
:
broadcastable_str
=
'(
%
s,) *
%
d'
%
(
str
(
shape
[
1
][
0
]),
len
(
shape
[
1
]))
broadcastable_str
=
f
'({shape[1][0]},) * {len(shape[1])}'
print
(
'
%
s
%-10
s
%-10
s
%-4
s
%-15
s
%-20
s'
%
(
print
(
'
%
s
%-10
s
%-10
s
%-4
s
%-15
s
%-20
s'
%
(
letter
[
0
],
shape
[
0
],
letter
[
1
],
len
(
shape
[
1
]),
s
,
broadcastable_str
letter
[
0
],
shape
[
0
],
letter
[
1
],
len
(
shape
[
1
]),
s
,
broadcastable_str
))
))
...
...
pytensor/compile/monitormode.py
浏览文件 @
93825dcc
...
@@ -110,6 +110,6 @@ def detect_nan(fgraph, i, node, fn):
...
@@ -110,6 +110,6 @@ def detect_nan(fgraph, i, node, fn):
):
):
print
(
"*** NaN detected ***"
)
print
(
"*** NaN detected ***"
)
debugprint
(
node
)
debugprint
(
node
)
print
(
"Inputs :
%
s"
%
[
input
[
0
]
for
input
in
fn
.
inputs
]
)
print
(
f
"Inputs : {[input[0] for input in fn.inputs]}"
)
print
(
"Outputs:
%
s"
%
[
output
[
0
]
for
output
in
fn
.
outputs
]
)
print
(
f
"Outputs: {[output[0] for output in fn.outputs]}"
)
break
break
pytensor/compile/profiling.py
浏览文件 @
93825dcc
...
@@ -753,14 +753,11 @@ class ProfileStats:
...
@@ -753,14 +753,11 @@ class ProfileStats:
)
)
# Same as before, this I've sacrificed some information making
# Same as before, this I've sacrificed some information making
# the output more readable
# the output more readable
percent
=
sum
(
f
for
f
,
t
,
a
,
nd_id
,
nb_call
in
atimes
[
N
:])
duration
=
sum
(
t
for
f
,
t
,
a
,
nd_id
,
nb_call
in
atimes
[
N
:])
print
(
print
(
" ... (remaining
%
i Apply instances account for "
f
" ... (remaining {max(0, len(atimes) - N)} Apply instances account for "
"
%.2
f
%%
(
%.2
fs) of the runtime)"
f
"{percent:.2f}
%%
({duration:.2f}s) of the runtime)"
,
%
(
max
(
0
,
len
(
atimes
)
-
N
),
sum
(
f
for
f
,
t
,
a
,
nd_id
,
nb_call
in
atimes
[
N
:]),
sum
(
t
for
f
,
t
,
a
,
nd_id
,
nb_call
in
atimes
[
N
:]),
),
file
=
file
,
file
=
file
,
)
)
print
(
""
,
file
=
file
)
print
(
""
,
file
=
file
)
...
...
pytensor/link/c/basic.py
浏览文件 @
93825dcc
...
@@ -87,9 +87,8 @@ class CodeBlock:
...
@@ -87,9 +87,8 @@ class CodeBlock:
# for that...)
# for that...)
# we need the label even if cleanup is empty because the
# we need the label even if cleanup is empty because the
# behavior block jumps there on failure
# behavior block jumps there on failure
self
.
cleanup
=
(
id
=
sub
[
"id"
]
"__label_
%(id)
i:
\n
"
%
sub
+
cleanup
+
"
\n
double __DUMMY_
%(id)
i;
\n
"
%
sub
self
.
cleanup
=
f
"__label_{id}:
\n
{cleanup}
\n
double __DUMMY_{id};
\n
"
)
# % sub
def
failure_code
(
sub
,
use_goto
=
True
):
def
failure_code
(
sub
,
use_goto
=
True
):
...
@@ -114,14 +113,16 @@ def failure_code(sub, use_goto=True):
...
@@ -114,14 +113,16 @@ def failure_code(sub, use_goto=True):
goto_statement
=
"goto __label_
%(id)
i;"
%
sub
goto_statement
=
"goto __label_
%(id)
i;"
%
sub
else
:
else
:
goto_statement
=
""
goto_statement
=
""
return
"""{
id
=
sub
[
"id"
]
%(failure_var)
s =
%(id)
i;
failure_var
=
sub
[
"failure_var"
]
if (!PyErr_Occurred()) {
return
f
"""{{
{failure_var} = {id};
if (!PyErr_Occurred()) {{
PyErr_SetString(PyExc_RuntimeError,
PyErr_SetString(PyExc_RuntimeError,
"Unexpected error in an Op's C code. "
"Unexpected error in an Op's C code. "
"No Python exception was set.");
"No Python exception was set.");
}
}
}
%(goto_statement)
s}"""
%
dict
(
sub
,
goto_statement
=
goto_statement
)
{goto_statement}}}"""
def
failure_code_init
(
sub
):
def
failure_code_init
(
sub
):
...
@@ -135,17 +136,15 @@ def failure_code_init(sub):
...
@@ -135,17 +136,15 @@ def failure_code_init(sub):
* failure_var -> must contain a variable name to use for
* failure_var -> must contain a variable name to use for
the failure code.
the failure code.
"""
"""
return
(
id
=
sub
[
"id"
]
"""
{
return
f
"""{
{
if (!PyErr_Occurred()) {
if (!PyErr_Occurred()) {
{
PyErr_SetString(PyExc_RuntimeError,
PyErr_SetString(PyExc_RuntimeError,
"Unexpected error in an Op's C code. "
"Unexpected error in an Op's C code. "
"No Python exception was set.");
"No Python exception was set.");
}
}}
return
%(id)
d;
return {id};
}"""
}}"""
%
sub
)
def
code_gen
(
blocks
):
def
code_gen
(
blocks
):
...
@@ -1657,10 +1656,9 @@ class CLinker(Linker):
...
@@ -1657,10 +1656,9 @@ class CLinker(Linker):
file
=
code
,
file
=
code
,
)
)
print
(
" assert(PyTuple_Check(argtuple));"
,
file
=
code
)
print
(
" assert(PyTuple_Check(argtuple));"
,
file
=
code
)
print
(
" if (
%(n_args)
i != PyTuple_Size(argtuple)){ "
%
locals
()
,
file
=
code
)
print
(
f
" if ({n_args} != PyTuple_Size(argtuple)){{ "
,
file
=
code
)
print
(
print
(
' PyErr_Format(PyExc_TypeError, "Wrong number of arguments, expected
%(n_args)
i, got
%%
i", (int)PyTuple_Size(argtuple));'
f
' PyErr_Format(PyExc_TypeError, "Wrong number of arguments, expected {n_args}, got
%%
i", (int)PyTuple_Size(argtuple));'
,
%
locals
(),
file
=
code
,
file
=
code
,
)
)
print
(
" return NULL;"
,
file
=
code
)
print
(
" return NULL;"
,
file
=
code
)
...
...
pytensor/link/c/op.py
浏览文件 @
93825dcc
...
@@ -513,8 +513,6 @@ class ExternalCOp(COp):
...
@@ -513,8 +513,6 @@ class ExternalCOp(COp):
self
,
node
:
Apply
,
name
:
str
,
check_input
:
bool
|
None
=
None
self
,
node
:
Apply
,
name
:
str
,
check_input
:
bool
|
None
=
None
)
->
tuple
[
str
,
str
]:
)
->
tuple
[
str
,
str
]:
"Construct a pair of C ``#define`` and ``#undef`` code strings."
"Construct a pair of C ``#define`` and ``#undef`` code strings."
define_template
=
"#define
%
s
%
s"
undef_template
=
"#undef
%
s"
define_macros
=
[]
define_macros
=
[]
undef_macros
=
[]
undef_macros
=
[]
...
@@ -535,28 +533,23 @@ class ExternalCOp(COp):
...
@@ -535,28 +533,23 @@ class ExternalCOp(COp):
vname
=
variable_names
[
i
]
vname
=
variable_names
[
i
]
macro_items
=
(
f
"DTYPE_{vname}"
,
f
"npy_{v.type.dtype}"
)
define_macros
.
append
(
f
"#define DTYPE_{vname} npy_{v.type.dtype}"
)
define_macros
.
append
(
define_template
%
macro_items
)
undef_macros
.
append
(
f
"#undef DTYPE_{vname}"
)
undef_macros
.
append
(
undef_template
%
macro_items
[
0
])
d
=
np
.
dtype
(
v
.
type
.
dtype
)
d
=
np
.
dtype
(
v
.
type
.
dtype
)
macro_items_2
=
(
f
"TYPENUM_{vname}"
,
d
.
num
)
define_macros
.
append
(
f
"#define TYPENUM_{vname} {d.num}"
)
define_macros
.
append
(
define_template
%
macro_items_2
)
undef_macros
.
append
(
f
"#undef TYPENUM_{vname}"
)
undef_macros
.
append
(
undef_template
%
macro_items_2
[
0
])
macro_items_3
=
(
f
"ITEMSIZE_{vname}"
,
d
.
itemsize
)
define_macros
.
append
(
f
"#define ITEMSIZE_{vname} {d.itemsize}"
)
define_macros
.
append
(
define_template
%
macro_items_3
)
undef_macros
.
append
(
f
"#undef ITEMSIZE_{vname}"
)
undef_macros
.
append
(
undef_template
%
macro_items_3
[
0
])
# Generate a macro to mark code as being apply-specific
# Generate a macro to mark code as being apply-specific
define_macros
.
append
(
define_template
%
(
"APPLY_SPECIFIC(str)"
,
f
"str##_{name}"
)
)
define_macros
.
append
(
f
"#define APPLY_SPECIFIC(str) str##_{name}"
)
undef_macros
.
append
(
undef_template
%
"
APPLY_SPECIFIC"
)
undef_macros
.
append
(
"#undef
APPLY_SPECIFIC"
)
define_macros
.
extend
(
define_macros
.
extend
(
f
"#define {n} {v}"
for
n
,
v
in
self
.
__get_op_params
())
define_template
%
(
n
,
v
)
for
n
,
v
in
self
.
__get_op_params
()
undef_macros
.
extend
(
f
"#undef {n}"
for
n
,
_
in
self
.
__get_op_params
())
)
undef_macros
.
extend
(
undef_template
%
(
n
,)
for
n
,
_
in
self
.
__get_op_params
())
return
"
\n
"
.
join
(
define_macros
),
"
\n
"
.
join
(
undef_macros
)
return
"
\n
"
.
join
(
define_macros
),
"
\n
"
.
join
(
undef_macros
)
...
...
pytensor/link/c/type.py
浏览文件 @
93825dcc
...
@@ -208,29 +208,29 @@ class CDataType(CType[D]):
...
@@ -208,29 +208,29 @@ class CDataType(CType[D]):
freefunc
=
self
.
freefunc
freefunc
=
self
.
freefunc
if
freefunc
is
None
:
if
freefunc
is
None
:
freefunc
=
"NULL"
freefunc
=
"NULL"
s
=
"""
s
=
f
"""
Py_XDECREF(py_
%(name)
s
);
Py_XDECREF(py_
{name}
);
if (
%(name)
s == NULL)
{
if (
{name} == NULL) {
{
py_
%(name)
s
= Py_None;
py_
{name}
= Py_None;
Py_INCREF(py_
%(name)
s
);
Py_INCREF(py_
{name}
);
}
else
{
}
} else {
{
py_
%(name)
s = PyCapsule_New((void *)
%(name)
s
, NULL,
py_
{name} = PyCapsule_New((void *){name}
, NULL,
_capsule_destructor);
_capsule_destructor);
if (py_
%(name)
s != NULL)
{
if (py_
{name} != NULL) {
{
if (PyCapsule_SetContext(py_
%(name)
s, (void *)
%(freefunc)
s) != 0)
{
if (PyCapsule_SetContext(py_
{name}, (void *){freefunc}) != 0) {
{
/* This won't trigger a call to freefunc since it could not be
/* This won't trigger a call to freefunc since it could not be
set. The error case below will do it. */
set. The error case below will do it. */
Py_DECREF(py_
%(name)
s
);
Py_DECREF(py_
{name}
);
/* Signal the error */
/* Signal the error */
py_
%(name)
s
= NULL;
py_
{name}
= NULL;
}
}
}
}
}
}
}"""
}
}
"""
if
self
.
freefunc
is
not
None
:
if
self
.
freefunc
is
not
None
:
s
+=
"""
s
+=
f
"""
if (py_
%(name)
s == NULL) {
%(freefunc)
s(
%(name)
s);
}
if (py_
{name} == NULL) {{ {freefunc}({name}); }
}
"""
"""
return
s
%
dict
(
name
=
name
,
freefunc
=
freefunc
)
return
s
def
c_cleanup
(
self
,
name
,
sub
):
def
c_cleanup
(
self
,
name
,
sub
):
# No need to do anything here since the CObject/Capsule will
# No need to do anything here since the CObject/Capsule will
...
...
pytensor/misc/check_duplicate_key.py
浏览文件 @
93825dcc
...
@@ -36,7 +36,7 @@ for dir in dirs:
...
@@ -36,7 +36,7 @@ for dir in dirs:
if
DISPLAY_DUPLICATE_KEYS
:
if
DISPLAY_DUPLICATE_KEYS
:
for
k
,
v
in
keys
.
items
():
for
k
,
v
in
keys
.
items
():
if
v
>
1
:
if
v
>
1
:
print
(
"Duplicate key (
%
i copies):
%
s"
%
(
v
,
pickle
.
loads
(
k
))
)
print
(
f
"Duplicate key ({v} copies): {pickle.loads(k)}"
)
# nb seen -> how many keys
# nb seen -> how many keys
nbs_keys
=
Counter
(
val
for
val
in
keys
.
values
())
nbs_keys
=
Counter
(
val
for
val
in
keys
.
values
())
...
...
pytensor/printing.py
浏览文件 @
93825dcc
...
@@ -1120,7 +1120,7 @@ class PPrinter(Printer):
...
@@ -1120,7 +1120,7 @@ class PPrinter(Printer):
i
+=
1
i
+=
1
if
output
.
name
is
not
None
or
output
in
outputs
:
if
output
.
name
is
not
None
or
output
in
outputs
:
if
output
.
name
is
None
:
if
output
.
name
is
None
:
name
=
"out[
%
i]"
%
outputs
.
index
(
output
)
name
=
f
"out[{outputs.index(output)}]"
else
:
else
:
name
=
output
.
name
name
=
output
.
name
# backport
# backport
...
...
pytensor/tensor/blas.py
浏览文件 @
93825dcc
...
@@ -1827,7 +1827,7 @@ class BatchedDot(COp):
...
@@ -1827,7 +1827,7 @@ class BatchedDot(COp):
]
]
z_shape_correct
=
" && "
.
join
(
z_shape_correct
=
" && "
.
join
(
"PyArray_DIMS(
%
s)[
%
i] ==
%
s"
%
(
_z
,
i
,
dim
)
for
i
,
dim
in
enumerate
(
z_dims
)
f
"PyArray_DIMS({_z})[{i}] == {dim}"
for
i
,
dim
in
enumerate
(
z_dims
)
)
)
z_shape
=
", "
.
join
(
z_dims
)
z_shape
=
", "
.
join
(
z_dims
)
z_contiguous
=
contiguous
(
_z
,
z_ndim
)
z_contiguous
=
contiguous
(
_z
,
z_ndim
)
...
...
pytensor/tensor/math.py
浏览文件 @
93825dcc
...
@@ -223,32 +223,31 @@ class Argmax(COp):
...
@@ -223,32 +223,31 @@ class Argmax(COp):
{fail}
{fail}
}}
}}
"""
"""
ret
=
"""
ret
urn
f
"""
int axis;
int axis;
Py_CLEAR(
%(argmax)
s
);//todo pass them as out parameter.
Py_CLEAR(
{argmax}
);//todo pass them as out parameter.
%(axis_code)
s
{axis_code}
%(argmax)
s = (PyArrayObject*)PyArray_ArgMax(
%(x)
s
, axis, NULL);
{argmax} = (PyArrayObject*)PyArray_ArgMax({x}
, axis, NULL);
if(
%(argmax)
s == NULL)
{
if(
{argmax} == NULL){
{
%(fail)
s
;
{fail}
;
}
}
}
if(!PyArray_CheckExact(
%(argmax)
s))
{
if(!PyArray_CheckExact(
{argmax})){
{
%(argmax)
s = (PyArrayObject*)PyArray_FromAny((PyObject*)
%(argmax)
s
, NULL, 0, 0, NPY_ARRAY_ENSUREARRAY, NULL);
{argmax} = (PyArrayObject*)PyArray_FromAny((PyObject*){argmax}
, NULL, 0, 0, NPY_ARRAY_ENSUREARRAY, NULL);
if(
%(argmax)
s == NULL)
{
if(
{argmax} == NULL){
{
%(fail)
s
;
{fail}
;
}
}
}
}
}
}
if(PyArray_TYPE(
%(argmax)
s) != NPY_INT64)
{
if(PyArray_TYPE(
{argmax}) != NPY_INT64){
{
PyObject * tmp = PyArray_Cast(
%(argmax)
s
, NPY_INT64);
PyObject * tmp = PyArray_Cast(
{argmax}
, NPY_INT64);
if (NULL == tmp){
if (NULL == tmp){
{
%(fail)
s
;
{fail}
;
}
}
}
Py_DECREF(
%(argmax)
s
);
Py_DECREF(
{argmax}
);
%(argmax)
s
= (PyArrayObject*)tmp;
{argmax}
= (PyArrayObject*)tmp;
}
}
}
"""
"""
return
ret
%
locals
()
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
2
,)
return
(
2
,)
...
@@ -2602,10 +2601,7 @@ class MulWithoutZeros(BinaryScalarOp):
...
@@ -2602,10 +2601,7 @@ class MulWithoutZeros(BinaryScalarOp):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
y
=
inp
x
,
y
=
inp
(
z
,)
=
out
(
z
,)
=
out
return
(
return
f
"{z} = (({x} == 0) ? ({y}) : (({y} == 0) ? ({x}) : (({y})*({x}))) );"
"
%(z)
s = ((
%(x)
s == 0) ? (
%(y)
s) : "
+
"((
%(y)
s == 0) ? (
%(x)
s) : ((
%(y)
s)*(
%(x)
s))) );"
)
%
locals
()
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
1
,)
return
(
1
,)
...
...
pytensor/tensor/rewriting/math.py
浏览文件 @
93825dcc
...
@@ -3254,7 +3254,7 @@ def simplify_mul(tree):
...
@@ -3254,7 +3254,7 @@ def simplify_mul(tree):
rval
=
[
neg
,
s_inputs
]
rval
=
[
neg
,
s_inputs
]
else
:
else
:
rval
=
tree
rval
=
tree
# print
'simplify_mul: %s -> %s' % (tree, rval
)
# print
(f"simplify_mul: {tree} -> {rval}"
)
return
rval
return
rval
...
...
pytensor/tensor/shape.py
浏览文件 @
93825dcc
...
@@ -243,7 +243,7 @@ class Shape_i(COp):
...
@@ -243,7 +243,7 @@ class Shape_i(COp):
return
ParamsType
(
i
=
pytensor
.
scalar
.
basic
.
int64
)
return
ParamsType
(
i
=
pytensor
.
scalar
.
basic
.
int64
)
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s{
%
i}"
%
(
self
.
__class__
.
__name__
,
self
.
i
)
return
f
"{self.__class__.__name__}{{{self.i}}}"
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
if
not
(
isinstance
(
x
,
Variable
)
and
hasattr
(
x
.
type
,
"ndim"
)):
if
not
(
isinstance
(
x
,
Variable
)
and
hasattr
(
x
.
type
,
"ndim"
)):
...
...
pytensor/tensor/subtensor.py
浏览文件 @
93825dcc
...
@@ -1073,20 +1073,20 @@ class Subtensor(COp):
...
@@ -1073,20 +1073,20 @@ class Subtensor(COp):
def
init_entry
(
entry
,
depth
=
0
):
def
init_entry
(
entry
,
depth
=
0
):
if
isinstance
(
entry
,
np
.
integer
|
int
):
if
isinstance
(
entry
,
np
.
integer
|
int
):
init_cmds
.
append
(
"subtensor_spec[
%
i] =
%
i;"
%
(
spec_pos
(),
entry
)
)
init_cmds
.
append
(
f
"subtensor_spec[{spec_pos()}] = {entry};"
)
inc_spec_pos
(
1
)
inc_spec_pos
(
1
)
if
depth
==
0
:
if
depth
==
0
:
is_slice
.
append
(
0
)
is_slice
.
append
(
0
)
elif
isinstance
(
entry
,
Type
):
elif
isinstance
(
entry
,
Type
):
init_cmds
.
append
(
init_cmds
.
append
(
"subtensor_spec[
%
i] =
%
s;"
%
(
spec_pos
(),
inputs
[
input_pos
()])
f
"subtensor_spec[{spec_pos()}] = {inputs[input_pos()]};"
)
)
inc_spec_pos
(
1
)
inc_spec_pos
(
1
)
inc_input_pos
(
1
)
inc_input_pos
(
1
)
if
depth
==
0
:
if
depth
==
0
:
is_slice
.
append
(
0
)
is_slice
.
append
(
0
)
elif
entry
is
None
:
elif
entry
is
None
:
init_cmds
.
append
(
"subtensor_spec[
%
i] =
%
i;"
%
(
spec_pos
(),
NONE_CODE
)
)
init_cmds
.
append
(
f
"subtensor_spec[{spec_pos()}] = {NONE_CODE};"
)
inc_spec_pos
(
1
)
inc_spec_pos
(
1
)
if
depth
==
0
:
if
depth
==
0
:
is_slice
.
append
(
0
)
is_slice
.
append
(
0
)
...
...
tests/compile/function/test_types.py
浏览文件 @
93825dcc
...
@@ -902,8 +902,8 @@ class TestPicklefunction:
...
@@ -902,8 +902,8 @@ class TestPicklefunction:
assert
f
.
_check_for_aliased_inputs
is
g
.
_check_for_aliased_inputs
assert
f
.
_check_for_aliased_inputs
is
g
.
_check_for_aliased_inputs
assert
f
.
name
==
g
.
name
assert
f
.
name
==
g
.
name
assert
f
.
maker
.
fgraph
.
name
==
g
.
maker
.
fgraph
.
name
assert
f
.
maker
.
fgraph
.
name
==
g
.
maker
.
fgraph
.
name
# print
'f.defaults = %s' % (f.defaults,
)
# print
(f"{f.defaults = }"
)
# print
'g.defaults = %s' % (g.defaults,
)
# print
(f"{g.defaults = }"
)
for
(
f_req
,
f_feed
,
f_val
),
(
g_req
,
g_feed
,
g_val
)
in
zip
(
for
(
f_req
,
f_feed
,
f_val
),
(
g_req
,
g_feed
,
g_val
)
in
zip
(
f
.
defaults
,
g
.
defaults
f
.
defaults
,
g
.
defaults
):
):
...
...
tests/compile/test_debugmode.py
浏览文件 @
93825dcc
...
@@ -152,28 +152,28 @@ class WeirdBrokenOp(COp):
...
@@ -152,28 +152,28 @@ class WeirdBrokenOp(COp):
(
a
,)
=
inp
(
a
,)
=
inp
(
z
,)
=
out
(
z
,)
=
out
if
"inplace"
in
self
.
behaviour
:
if
"inplace"
in
self
.
behaviour
:
z_code
=
"""
z_code
=
f
"""
{
Py_XDECREF(
%(z)
s);
}
{
{Py_XDECREF({z});}
}
Py_INCREF(
%(a)
s
);
Py_INCREF(
{a}
);
%(z)
s =
%(a)
s
;
{z} = {a}
;
"""
"""
else
:
else
:
z_code
=
"""
z_code
=
f
"""
{
Py_XDECREF(
%(z)
s);
}
{
{Py_XDECREF({z});}
}
%(z)
s = (PyArrayObject*) PyArray_SimpleNew(1, PyArray_DIMS(
%(a)
s), PyArray_DESCR(
%(a)
s
)->type_num);
{z} = (PyArrayObject*) PyArray_SimpleNew(1, PyArray_DIMS({a}), PyArray_DESCR({a}
)->type_num);
"""
"""
prep_vars
=
"""
prep_vars
=
f
"""
//the output array has size M x N
//the output array has size M x N
npy_intp M = PyArray_DIMS(
%(a)
s
)[0];
npy_intp M = PyArray_DIMS(
{a}
)[0];
npy_intp Sa = PyArray_STRIDES(
%(a)
s)[0] / PyArray_DESCR(
%(a)
s
)->elsize;
npy_intp Sa = PyArray_STRIDES(
{a})[0] / PyArray_DESCR({a}
)->elsize;
npy_intp Sz = PyArray_STRIDES(
%(z)
s)[0] / PyArray_DESCR(
%(z)
s
)->elsize;
npy_intp Sz = PyArray_STRIDES(
{z})[0] / PyArray_DESCR({z}
)->elsize;
npy_double * Da = (npy_double*)PyArray_BYTES(
%(a)
s
);
npy_double * Da = (npy_double*)PyArray_BYTES(
{a}
);
npy_double * Dz = (npy_double*)PyArray_BYTES(
%(z)
s
);
npy_double * Dz = (npy_double*)PyArray_BYTES(
{z}
);
//clear the output array
//clear the output array
for (npy_intp m = 0; m < M; ++m)
for (npy_intp m = 0; m < M; ++m)
{
{
{
"""
"""
if
self
.
behaviour
==
"times2"
:
if
self
.
behaviour
==
"times2"
:
...
@@ -196,7 +196,7 @@ class WeirdBrokenOp(COp):
...
@@ -196,7 +196,7 @@ class WeirdBrokenOp(COp):
}
}
"""
"""
total
=
(
z_code
+
prep_vars
+
behaviour
+
prep_vars2
)
%
dict
(
locals
(),
**
sub
)
total
=
z_code
+
prep_vars
+
behaviour
+
prep_vars2
return
total
return
total
...
...
tests/compile/test_misc.py
浏览文件 @
93825dcc
...
@@ -65,7 +65,7 @@ def test_nnet():
...
@@ -65,7 +65,7 @@ def test_nnet():
output
,
cost
=
nnet
.
sgd_step
(
input
,
target
)
output
,
cost
=
nnet
.
sgd_step
(
input
,
target
)
mean_cost
+=
cost
mean_cost
+=
cost
mean_cost
/=
float
(
len
(
data
))
mean_cost
/=
float
(
len
(
data
))
# print
'Mean cost at epoch %s: %s' % (epoch, mean_cost
)
# print
(f"Mean cost at epoch {epoch}: {mean_cost}"
)
# Seed based test
# Seed based test
assert
abs
(
mean_cost
-
0.2301901
)
<
1e-6
assert
abs
(
mean_cost
-
0.2301901
)
<
1e-6
# Just call functions to make sure they do not crash.
# Just call functions to make sure they do not crash.
...
...
tests/compile/test_monitormode.py
浏览文件 @
93825dcc
...
@@ -20,8 +20,8 @@ def test_detect_nan():
...
@@ -20,8 +20,8 @@ def test_detect_nan():
if
np
.
isnan
(
output
[
0
])
.
any
():
if
np
.
isnan
(
output
[
0
])
.
any
():
print
(
"*** NaN detected ***"
)
print
(
"*** NaN detected ***"
)
debugprint
(
node
)
debugprint
(
node
)
print
(
"Inputs :
%
s"
%
[
input
[
0
]
for
input
in
fn
.
inputs
]
)
print
(
f
"Inputs : {[input[0] for input in fn.inputs]}"
)
print
(
"Outputs:
%
s"
%
[
output
[
0
]
for
output
in
fn
.
outputs
]
)
print
(
f
"Outputs: {[output[0] for output in fn.outputs]}"
)
nan_detected
[
0
]
=
True
nan_detected
[
0
]
=
True
break
break
...
@@ -50,8 +50,8 @@ def test_optimizer():
...
@@ -50,8 +50,8 @@ def test_optimizer():
if
np
.
isnan
(
output
[
0
])
.
any
():
if
np
.
isnan
(
output
[
0
])
.
any
():
print
(
"*** NaN detected ***"
)
print
(
"*** NaN detected ***"
)
debugprint
(
node
)
debugprint
(
node
)
print
(
"Inputs :
%
s"
%
[
input
[
0
]
for
input
in
fn
.
inputs
]
)
print
(
f
"Inputs : {[input[0] for input in fn.inputs]}"
)
print
(
"Outputs:
%
s"
%
[
output
[
0
]
for
output
in
fn
.
outputs
]
)
print
(
f
"Outputs: {[output[0] for output in fn.outputs]}"
)
nan_detected
[
0
]
=
True
nan_detected
[
0
]
=
True
break
break
...
@@ -82,8 +82,8 @@ def test_not_inplace():
...
@@ -82,8 +82,8 @@ def test_not_inplace():
if
np
.
isnan
(
output
[
0
])
.
any
():
if
np
.
isnan
(
output
[
0
])
.
any
():
print
(
"*** NaN detected ***"
)
print
(
"*** NaN detected ***"
)
debugprint
(
node
)
debugprint
(
node
)
print
(
"Inputs :
%
s"
%
[
input
[
0
]
for
input
in
fn
.
inputs
]
)
print
(
f
"Inputs : {[input[0] for input in fn.inputs]}"
)
print
(
"Outputs:
%
s"
%
[
output
[
0
]
for
output
in
fn
.
outputs
]
)
print
(
f
"Outputs: {[output[0] for output in fn.outputs]}"
)
nan_detected
[
0
]
=
True
nan_detected
[
0
]
=
True
break
break
...
...
tests/compile/test_profiling.py
浏览文件 @
93825dcc
...
@@ -25,7 +25,7 @@ class TestProfiling:
...
@@ -25,7 +25,7 @@ class TestProfiling:
config
.
profile_memory
=
True
config
.
profile_memory
=
True
config
.
profiling__min_peak_memory
=
True
config
.
profiling__min_peak_memory
=
True
x
=
[
fvector
(
"val
%
i"
%
i
)
for
i
in
range
(
3
)]
x
=
[
fvector
(
f
"val{i}"
)
for
i
in
range
(
3
)]
z
=
[]
z
=
[]
z
+=
[
pt
.
outer
(
x
[
i
],
x
[
i
+
1
])
.
sum
(
axis
=
1
)
for
i
in
range
(
len
(
x
)
-
1
)]
z
+=
[
pt
.
outer
(
x
[
i
],
x
[
i
+
1
])
.
sum
(
axis
=
1
)
for
i
in
range
(
len
(
x
)
-
1
)]
...
...
tests/graph/test_features.py
浏览文件 @
93825dcc
...
@@ -74,7 +74,7 @@ class TestNodeFinder:
...
@@ -74,7 +74,7 @@ class TestNodeFinder:
assert
hasattr
(
g
,
"get_nodes"
)
assert
hasattr
(
g
,
"get_nodes"
)
for
type
,
num
in
((
add
,
3
),
(
sigmoid
,
3
),
(
dot
,
2
)):
for
type
,
num
in
((
add
,
3
),
(
sigmoid
,
3
),
(
dot
,
2
)):
if
len
(
list
(
g
.
get_nodes
(
type
)))
!=
num
:
if
len
(
list
(
g
.
get_nodes
(
type
)))
!=
num
:
raise
Exception
(
"Expected:
%
i times
%
s"
%
(
num
,
type
)
)
raise
Exception
(
f
"Expected: {num} times {type}"
)
new_e0
=
add
(
y
,
z
)
new_e0
=
add
(
y
,
z
)
assert
e0
.
owner
in
g
.
get_nodes
(
dot
)
assert
e0
.
owner
in
g
.
get_nodes
(
dot
)
assert
new_e0
.
owner
not
in
g
.
get_nodes
(
add
)
assert
new_e0
.
owner
not
in
g
.
get_nodes
(
add
)
...
@@ -83,7 +83,7 @@ class TestNodeFinder:
...
@@ -83,7 +83,7 @@ class TestNodeFinder:
assert
new_e0
.
owner
in
g
.
get_nodes
(
add
)
assert
new_e0
.
owner
in
g
.
get_nodes
(
add
)
for
type
,
num
in
((
add
,
4
),
(
sigmoid
,
3
),
(
dot
,
1
)):
for
type
,
num
in
((
add
,
4
),
(
sigmoid
,
3
),
(
dot
,
1
)):
if
len
(
list
(
g
.
get_nodes
(
type
)))
!=
num
:
if
len
(
list
(
g
.
get_nodes
(
type
)))
!=
num
:
raise
Exception
(
"Expected:
%
i times
%
s"
%
(
num
,
type
)
)
raise
Exception
(
f
"Expected: {num} times {type}"
)
class
TestReplaceValidate
:
class
TestReplaceValidate
:
...
...
tests/scan/test_basic.py
浏览文件 @
93825dcc
...
@@ -177,8 +177,7 @@ class multiple_outputs_numeric_grad:
...
@@ -177,8 +177,7 @@ class multiple_outputs_numeric_grad:
for
i
,
(
a
,
b
)
in
enumerate
(
zip
(
g_pt
,
self
.
gx
)):
for
i
,
(
a
,
b
)
in
enumerate
(
zip
(
g_pt
,
self
.
gx
)):
if
a
.
shape
!=
b
.
shape
:
if
a
.
shape
!=
b
.
shape
:
raise
ValueError
(
raise
ValueError
(
"argument element
%
i has wrong shape
%
s"
f
"argument element {i} has wrong shape {(a.shape, b.shape)}"
%
(
i
,
str
((
a
.
shape
,
b
.
shape
)))
)
)
errs
.
append
(
np
.
max
(
multiple_outputs_numeric_grad
.
abs_rel_err
(
a
,
b
)))
errs
.
append
(
np
.
max
(
multiple_outputs_numeric_grad
.
abs_rel_err
(
a
,
b
)))
if
np
.
all
(
np
.
isfinite
(
errs
)):
if
np
.
all
(
np
.
isfinite
(
errs
)):
...
...
tests/tensor/test_blas.py
浏览文件 @
93825dcc
...
@@ -672,10 +672,9 @@ def just_gemm(i, o, ishapes=None, max_graphlen=0, expected_nb_gemm=1):
...
@@ -672,10 +672,9 @@ def just_gemm(i, o, ishapes=None, max_graphlen=0, expected_nb_gemm=1):
assert
node
.
op
!=
gemm_inplace
,
"gemm_inplace in original graph"
assert
node
.
op
!=
gemm_inplace
,
"gemm_inplace in original graph"
graphlen
=
len
(
f
.
maker
.
fgraph
.
toposort
())
graphlen
=
len
(
f
.
maker
.
fgraph
.
toposort
())
assert
not
(
max_graphlen
and
(
graphlen
<=
max_graphlen
)),
"graphlen=
%
i>
%
i"
%
(
assert
not
(
graphlen
,
max_graphlen
and
(
graphlen
<=
max_graphlen
)
max_graphlen
,
),
f
"graphlen={graphlen}>{max_graphlen}"
)
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
(
234
))
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
(
234
))
r0
=
f
(
*
[
np
.
asarray
(
rng
.
standard_normal
(
sh
),
config
.
floatX
)
for
sh
in
ishapes
])
r0
=
f
(
*
[
np
.
asarray
(
rng
.
standard_normal
(
sh
),
config
.
floatX
)
for
sh
in
ishapes
])
...
...
tests/tensor/test_math.py
浏览文件 @
93825dcc
...
@@ -1851,8 +1851,8 @@ class TestBitwise:
...
@@ -1851,8 +1851,8 @@ class TestBitwise:
class
TestAdd
:
class
TestAdd
:
def
test_complex_all_ops
(
self
):
def
test_complex_all_ops
(
self
):
for
nbits
in
(
64
,
128
):
for
nbits
in
(
64
,
128
):
a
=
shared
(
np
.
ones
(
3
,
dtype
=
"complex
%
i"
%
nbits
)
+
0.5
j
)
a
=
shared
(
np
.
ones
(
3
,
dtype
=
f
"complex{nbits}"
)
+
0.5
j
)
b
=
shared
(
np
.
ones
(
3
,
dtype
=
"complex
%
i"
%
nbits
)
+
1.5
j
)
b
=
shared
(
np
.
ones
(
3
,
dtype
=
f
"complex{nbits}"
)
+
1.5
j
)
tests
=
(
tests
=
(
(
"+"
,
lambda
x
,
y
:
x
+
y
),
(
"+"
,
lambda
x
,
y
:
x
+
y
),
(
"-"
,
lambda
x
,
y
:
x
-
y
),
(
"-"
,
lambda
x
,
y
:
x
-
y
),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论