Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9c4c58ad
提交
9c4c58ad
authored
5月 16, 2011
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
差异文件
merged
上级
e731582c
4befd3b9
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
49 行增加
和
29 行删除
+49
-29
basic.py
theano/scalar/basic.py
+6
-7
scan_op.py
theano/scan_module/scan_op.py
+11
-8
basic.py
theano/tensor/basic.py
+5
-1
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+27
-13
没有找到文件。
theano/scalar/basic.py
浏览文件 @
9c4c58ad
...
@@ -821,9 +821,9 @@ class BinaryBitOp(BinaryScalarOp):
...
@@ -821,9 +821,9 @@ class BinaryBitOp(BinaryScalarOp):
return
[
None
,
None
]
return
[
None
,
None
]
class
OR
(
BinaryBitOp
):
class
OR
(
BinaryBitOp
):
identity
=
False
identity
=
0
commutative
=
True
commutative
=
True
associative
=
Fals
e
associative
=
Tru
e
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
|
y
return
x
|
y
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
...
@@ -831,9 +831,9 @@ class OR(BinaryBitOp):
...
@@ -831,9 +831,9 @@ class OR(BinaryBitOp):
or_
=
OR
()
or_
=
OR
()
class
XOR
(
BinaryBitOp
):
class
XOR
(
BinaryBitOp
):
identity
=
False
identity
=
0
commutative
=
True
commutative
=
True
associative
=
Fals
e
associative
=
Tru
e
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
^
y
return
x
^
y
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
...
@@ -841,9 +841,9 @@ class XOR(BinaryBitOp):
...
@@ -841,9 +841,9 @@ class XOR(BinaryBitOp):
xor
=
XOR
()
xor
=
XOR
()
class
AND
(
BinaryBitOp
):
class
AND
(
BinaryBitOp
):
identity
=
False
identity
=
1
commutative
=
True
commutative
=
True
associative
=
Fals
e
associative
=
Tru
e
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
&
y
return
x
&
y
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
...
@@ -851,7 +851,6 @@ class AND(BinaryBitOp):
...
@@ -851,7 +851,6 @@ class AND(BinaryBitOp):
and_
=
AND
()
and_
=
AND
()
class
Invert
(
UnaryBitOp
):
class
Invert
(
UnaryBitOp
):
identity
=
False
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
~
x
return
~
x
def
c_code
(
self
,
node
,
name
,
(
x
,),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
(
x
,),
(
z
,
),
sub
):
...
...
theano/scan_module/scan_op.py
浏览文件 @
9c4c58ad
...
@@ -1063,13 +1063,16 @@ def profile_printer(fct_name, compile_time, fct_call_time, fct_call,
...
@@ -1063,13 +1063,16 @@ def profile_printer(fct_name, compile_time, fct_call_time, fct_call,
total_scan_op_time
=
0
total_scan_op_time
=
0
for
(
_
,
node
),
v
in
apply_time
.
items
():
for
(
_
,
node
),
v
in
apply_time
.
items
():
if
isinstance
(
node
.
op
,
Scan
):
if
isinstance
(
node
.
op
,
Scan
):
scan_fct_time
=
node
.
op
.
mode_instance
.
fn_time
if
v
>
0
:
scan_op_time
=
sum
(
node
.
op
.
mode_instance
.
local_time
)
scan_fct_time
=
node
.
op
.
mode_instance
.
fn_time
total_super_scan_time
+=
v
scan_op_time
=
sum
(
node
.
op
.
mode_instance
.
local_time
)
total_scan_fct_time
+=
scan_fct_time
total_super_scan_time
+=
v
total_scan_op_time
+=
scan_op_time
total_scan_fct_time
+=
scan_fct_time
print
'
%5.1
fs
%5.1
fs
%5.1
fs
%5.1
f
%% %5.1
f
%%
'
%
(
total_scan_op_time
+=
scan_op_time
v
,
scan_fct_time
,
scan_op_time
,
scan_fct_time
/
v
*
100
,
print
'
%5.1
fs
%5.1
fs
%5.1
fs
%5.1
f
%% %5.1
f
%%
'
%
(
scan_op_time
/
v
*
100
),
node
v
,
scan_fct_time
,
scan_op_time
,
scan_fct_time
/
v
*
100
,
scan_op_time
/
v
*
100
),
node
else
:
print
' The node took 0s, so we can not compute the overhead'
print
' total
%5.1
fs
%5.1
fs
%5.1
fs
%5.1
f
%% %5.1
f
%%
'
%
(
print
' total
%5.1
fs
%5.1
fs
%5.1
fs
%5.1
f
%% %5.1
f
%%
'
%
(
total_super_scan_time
,
total_scan_fct_time
,
total_scan_op_time
,
total_scan_fct_time
/
total_super_scan_time
*
100
,
total_scan_op_time
/
total_super_scan_time
*
100
)
total_super_scan_time
,
total_scan_fct_time
,
total_scan_op_time
,
total_scan_fct_time
/
total_super_scan_time
*
100
,
total_scan_op_time
/
total_super_scan_time
*
100
)
theano/tensor/basic.py
浏览文件 @
9c4c58ad
...
@@ -1299,7 +1299,11 @@ class TensorConstant(_tensor_py_operators, Constant):
...
@@ -1299,7 +1299,11 @@ class TensorConstant(_tensor_py_operators, Constant):
To create a TensorConstant, use the `constant` function in this module.
To create a TensorConstant, use the `constant` function in this module.
"""
"""
def
__str__
(
self
):
def
__str__
(
self
):
return
"TensorConstant{
%
s}"
%
self
.
data
name
=
"
%
s"
%
self
.
data
if
len
(
name
)
>
20
:
name
=
name
[:
10
]
+
".."
+
name
[
-
10
:]
return
"TensorConstant{
%
s}"
%
name
def
signature
(
self
):
def
signature
(
self
):
return
TensorConstantSignature
((
self
.
type
,
self
.
data
))
return
TensorConstantSignature
((
self
.
type
,
self
.
data
))
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
9c4c58ad
...
@@ -172,7 +172,7 @@ class test_CAReduce(unittest.TestCase):
...
@@ -172,7 +172,7 @@ class test_CAReduce(unittest.TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
unittest_tools
.
seed_rng
()
unittest_tools
.
seed_rng
()
def
with_linker
(
self
,
linker
,
scalar_op
=
add
):
def
with_linker
(
self
,
linker
,
scalar_op
=
add
,
dtype
=
"floatX"
):
for
xsh
,
tosum
in
[((
5
,
6
),
None
),
for
xsh
,
tosum
in
[((
5
,
6
),
None
),
((
5
,
6
),
(
0
,
1
)),
((
5
,
6
),
(
0
,
1
)),
((
5
,
6
),
(
0
,
)),
((
5
,
6
),
(
0
,
)),
...
@@ -188,11 +188,17 @@ class test_CAReduce(unittest.TestCase):
...
@@ -188,11 +188,17 @@ class test_CAReduce(unittest.TestCase):
((
5
,
0
),
()),
((
5
,
0
),
()),
((),
None
),
((),
None
),
((),
())]:
((),
())]:
x
=
TensorType
(
'float64'
,
[(
entry
==
1
)
for
entry
in
xsh
])(
'x'
)
if
dtype
==
"floatX"
:
dtype
=
theano
.
config
.
floatX
x
=
TensorType
(
dtype
,
[(
entry
==
1
)
for
entry
in
xsh
])(
'x'
)
e
=
CAReduce
(
scalar_op
,
axis
=
tosum
)(
x
)
e
=
CAReduce
(
scalar_op
,
axis
=
tosum
)(
x
)
if
tosum
is
None
:
tosum
=
range
(
len
(
xsh
))
if
tosum
is
None
:
tosum
=
range
(
len
(
xsh
))
f
=
copy
(
linker
)
.
accept
(
Env
([
x
],
[
e
]))
.
make_function
()
f
=
copy
(
linker
)
.
accept
(
Env
([
x
],
[
e
]))
.
make_function
()
xv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
xsh
))
xv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
xsh
))
if
dtype
.
startswith
(
'float'
):
xv
=
numpy
.
asarray
(
xv
,
dtype
=
dtype
)
else
:
xv
=
numpy
.
asarray
(
xv
<
0.5
,
dtype
=
dtype
)
zv
=
xv
zv
=
xv
numpy_raised
=
False
numpy_raised
=
False
if
len
(
tosum
)
>
1
and
any
([
a
<
0
for
a
in
tosum
]):
if
len
(
tosum
)
>
1
and
any
([
a
<
0
for
a
in
tosum
]):
...
@@ -224,10 +230,17 @@ class test_CAReduce(unittest.TestCase):
...
@@ -224,10 +230,17 @@ class test_CAReduce(unittest.TestCase):
numpy_raised
=
True
numpy_raised
=
True
elif
scalar_op
==
or_
:
elif
scalar_op
==
or_
:
for
axis
in
reversed
(
sorted
(
tosum
)):
for
axis
in
reversed
(
sorted
(
tosum
)):
zv
=
numpy
.
any
(
zv
,
axis
)
zv
=
numpy
.
bitwise_or
.
reduce
(
zv
,
axis
)
elif
scalar_op
==
and_
:
elif
scalar_op
==
and_
:
for
axis
in
reversed
(
sorted
(
tosum
)):
for
axis
in
reversed
(
sorted
(
tosum
)):
zv
=
numpy
.
all
(
zv
,
axis
)
zv
=
numpy
.
bitwise_and
.
reduce
(
zv
,
axis
)
elif
scalar_op
==
xor
:
# There is no identity value for the xor function
# So we can't support shape of dimensions 0.
if
numpy
.
prod
(
zv
.
shape
)
==
0
:
continue
for
axis
in
reversed
(
sorted
(
tosum
)):
zv
=
numpy
.
bitwise_xor
.
reduce
(
zv
,
axis
)
else
:
else
:
raise
Exception
(
"Test for CAReduce with scalar_op
%
s not implemented"
%
str
(
scalar_op
))
raise
Exception
(
"Test for CAReduce with scalar_op
%
s not implemented"
%
str
(
scalar_op
))
if
scalar_op
in
[
maximum
,
minimum
]
and
numpy_raised
:
if
scalar_op
in
[
maximum
,
minimum
]
and
numpy_raised
:
...
@@ -238,13 +251,16 @@ class test_CAReduce(unittest.TestCase):
...
@@ -238,13 +251,16 @@ class test_CAReduce(unittest.TestCase):
else
:
else
:
self
.
fail
()
self
.
fail
()
else
:
else
:
#numpy.{all,any} return bool type.
if
scalar_op
in
[
and_
,
or_
]:
zv
=
numpy
.
asarray
(
zv
,
dtype
=
dtype
)
self
.
assertTrue
((
numpy
.
abs
(
f
(
xv
)
-
zv
)
<
1e-10
)
.
all
())
self
.
assertTrue
((
numpy
.
abs
(
f
(
xv
)
-
zv
)
<
1e-10
)
.
all
())
#test CAReduce.infer_shape
#test CAReduce.infer_shape
#the Shape op don't implement c_code!
#the Shape op don't implement c_code!
if
isinstance
(
linker
,
gof
.
PerformLinker
):
if
isinstance
(
linker
,
gof
.
PerformLinker
):
x
=
TensorType
(
'float64'
,
[(
entry
==
1
)
for
entry
in
xsh
])(
'x'
)
x
=
TensorType
(
dtype
,
[(
entry
==
1
)
for
entry
in
xsh
])(
'x'
)
e
=
CAReduce
(
scalar_op
,
axis
=
tosum
)(
x
)
e
=
CAReduce
(
scalar_op
,
axis
=
tosum
)(
x
)
if
tosum
is
None
:
tosum
=
range
(
len
(
xsh
))
if
tosum
is
None
:
tosum
=
range
(
len
(
xsh
))
f
=
copy
(
linker
)
.
accept
(
Env
([
x
],
[
e
.
shape
]))
.
make_function
()
f
=
copy
(
linker
)
.
accept
(
Env
([
x
],
[
e
.
shape
]))
.
make_function
()
...
@@ -256,20 +272,18 @@ class test_CAReduce(unittest.TestCase):
...
@@ -256,20 +272,18 @@ class test_CAReduce(unittest.TestCase):
self
.
with_linker
(
gof
.
PerformLinker
(),
mul
)
self
.
with_linker
(
gof
.
PerformLinker
(),
mul
)
self
.
with_linker
(
gof
.
PerformLinker
(),
maximum
)
self
.
with_linker
(
gof
.
PerformLinker
(),
maximum
)
self
.
with_linker
(
gof
.
PerformLinker
(),
minimum
)
self
.
with_linker
(
gof
.
PerformLinker
(),
minimum
)
#need other dtype then real
self
.
with_linker
(
gof
.
PerformLinker
(),
or_
,
dtype
=
'int8'
)
#self.with_linker(gof.PerformLinker(), or_
)
self
.
with_linker
(
gof
.
PerformLinker
(),
and_
,
dtype
=
'int8'
)
#self.with_linker(gof.PerformLinker(), and_
)
self
.
with_linker
(
gof
.
PerformLinker
(),
xor
,
dtype
=
'int8'
)
def
test_c
(
self
):
def
test_c
(
self
):
self
.
with_linker
(
gof
.
CLinker
(),
add
)
self
.
with_linker
(
gof
.
CLinker
(),
add
)
self
.
with_linker
(
gof
.
CLinker
(),
mul
)
self
.
with_linker
(
gof
.
CLinker
(),
mul
)
self
.
with_linker
(
gof
.
CLinker
(),
maximum
)
self
.
with_linker
(
gof
.
CLinker
(),
maximum
)
self
.
with_linker
(
gof
.
CLinker
(),
minimum
)
self
.
with_linker
(
gof
.
CLinker
(),
minimum
)
self
.
with_linker
(
gof
.
CLinker
(),
or_
,
dtype
=
'int8'
)
#need other dtype then real
self
.
with_linker
(
gof
.
CLinker
(),
and_
,
dtype
=
'int8'
)
#no c_code for or_, and_
self
.
with_linker
(
gof
.
CLinker
(),
xor
,
dtype
=
'int8'
)
#self.with_linker(gof.CLinker(), or_)
#self.with_linker(gof.CLinker(), and_)
class
test_Prod
(
unittest
.
TestCase
):
class
test_Prod
(
unittest
.
TestCase
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论