Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
574c285f
提交
574c285f
authored
5月 06, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added logical and comparison ops to scalar.py
上级
c331e558
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
138 行增加
和
4 行删除
+138
-4
_test_scalar.py
_test_scalar.py
+50
-1
scalar.py
scalar.py
+88
-3
没有找到文件。
_test_scalar.py
浏览文件 @
574c285f
...
@@ -55,7 +55,56 @@ class _test_composite(unittest.TestCase):
...
@@ -55,7 +55,56 @@ class _test_composite(unittest.TestCase):
g
=
Env
([
x
,
y
,
z
],
c
.
outputs
)
g
=
Env
([
x
,
y
,
z
],
c
.
outputs
)
fn
=
gof
.
DualLinker
(
g
)
.
make_function
()
fn
=
gof
.
DualLinker
(
g
)
.
make_function
()
assert
fn
(
1.0
,
2.0
,
3.0
)
==
[
6.0
,
7.0
,
0.5
]
assert
fn
(
1.0
,
2.0
,
3.0
)
==
[
6.0
,
7.0
,
0.5
]
class
_test_logical
(
unittest
.
TestCase
):
def
test_gt
(
self
):
x
,
y
,
z
=
inputs
()
fn
=
gof
.
DualLinker
(
Env
([
x
,
y
],
[
x
>
y
]))
.
make_function
()
for
a
,
b
in
((
3.
,
9
),
(
3
,
0.9
),
(
3
,
3
)):
self
.
failUnless
(
fn
(
a
,
b
)
==
(
a
>
b
))
def
test_lt
(
self
):
x
,
y
,
z
=
inputs
()
fn
=
gof
.
DualLinker
(
Env
([
x
,
y
],
[
x
<
y
]))
.
make_function
()
for
a
,
b
in
((
3.
,
9
),
(
3
,
0.9
),
(
3
,
3
)):
self
.
failUnless
(
fn
(
a
,
b
)
==
(
a
<
b
))
def
test_le
(
self
):
x
,
y
,
z
=
inputs
()
fn
=
gof
.
DualLinker
(
Env
([
x
,
y
],
[
x
<=
y
]))
.
make_function
()
for
a
,
b
in
((
3.
,
9
),
(
3
,
0.9
),
(
3
,
3
)):
self
.
failUnless
(
fn
(
a
,
b
)
==
(
a
<=
b
))
def
test_ge
(
self
):
x
,
y
,
z
=
inputs
()
fn
=
gof
.
DualLinker
(
Env
([
x
,
y
],
[
x
>=
y
]))
.
make_function
()
for
a
,
b
in
((
3.
,
9
),
(
3
,
0.9
),
(
3
,
3
)):
self
.
failUnless
(
fn
(
a
,
b
)
==
(
a
>=
b
))
def
test_or
(
self
):
x
,
y
,
z
=
ints
(
'xyz'
)
fn
=
gof
.
DualLinker
(
Env
([
x
,
y
],
[
or_
(
x
,
y
)]))
.
make_function
()
for
a
,
b
in
((
0
,
1
),
(
0
,
0
),
(
1
,
0
),
(
1
,
1
)):
self
.
failUnless
(
fn
(
a
,
b
)
==
(
a
or
b
),
(
a
,
b
))
def
test_xor
(
self
):
x
,
y
,
z
=
ints
(
'xyz'
)
fn
=
gof
.
DualLinker
(
Env
([
x
,
y
],
[
xor
(
x
,
y
)]))
.
make_function
()
for
a
,
b
in
((
0
,
1
),
(
0
,
0
),
(
1
,
0
),
(
1
,
1
)):
self
.
failUnless
(
fn
(
a
,
b
)
==
(
operator
.
xor
(
a
,
b
)),
(
a
,
b
))
def
test_and
(
self
):
x
,
y
,
z
=
ints
(
'xyz'
)
fn
=
gof
.
DualLinker
(
Env
([
x
,
y
],
[
and_
(
x
,
y
)]))
.
make_function
()
for
a
,
b
in
((
0
,
1
),
(
0
,
0
),
(
1
,
0
),
(
1
,
1
)):
self
.
failUnless
(
fn
(
a
,
b
)
==
(
a
and
b
),
(
a
,
b
))
def
test_not
(
self
):
x
,
y
,
z
=
ints
(
'xyz'
)
fn
=
gof
.
DualLinker
(
Env
([
x
,
y
],
[
not_
(
x
)]))
.
make_function
()
for
a
,
b
in
((
0
,
1
),
(
0
,
0
),
(
1
,
0
),
(
1
,
1
)):
self
.
failUnless
(
fn
(
a
,
b
)
==
(
not
a
),
(
a
,))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
...
...
scalar.py
浏览文件 @
574c285f
import
operator
import
numpy
import
math
import
math
from
copy
import
copy
from
copy
import
copy
import
numpy
import
gof
import
gof
from
gof
import
PropertiedType
,
Op
,
PropertiedOp
,
utils
,
Result
,
Constant
,
Type
,
Apply
,
Env
from
gof
import
PropertiedType
,
Op
,
PropertiedOp
,
utils
,
Result
,
Constant
,
Type
,
Apply
,
Env
from
gof.python25
import
partial
from
gof.python25
import
partial
...
@@ -326,6 +326,91 @@ class UnaryScalarOp(ScalarOp):
...
@@ -326,6 +326,91 @@ class UnaryScalarOp(ScalarOp):
class
BinaryScalarOp
(
ScalarOp
):
class
BinaryScalarOp
(
ScalarOp
):
nin
=
2
nin
=
2
class
UnaryLogicalOp
(
UnaryScalarOp
):
def
output_types
(
self
,
*
input_dtypes
):
return
[
int8
]
def
grad
(
self
,
inputs
,
output_gradients
):
return
[
None
]
class
BinaryLogicalOp
(
BinaryScalarOp
):
def
output_types
(
self
,
*
input_dtypes
):
return
[
int8
]
def
grad
(
self
,
inputs
,
output_gradients
):
return
[
None
,
None
]
class
LT
(
BinaryLogicalOp
):
identity
=
False
commutative
=
False
associative
=
False
def
impl
(
self
,
x
,
y
):
return
x
<
y
lt
=
LT
()
class
GT
(
BinaryLogicalOp
):
identity
=
False
commutative
=
False
associative
=
False
def
impl
(
self
,
x
,
y
):
return
x
>
y
gt
=
GT
()
class
LE
(
BinaryLogicalOp
):
identity
=
False
commutative
=
False
associative
=
False
def
impl
(
self
,
x
,
y
):
return
x
<=
y
le
=
LE
()
class
GE
(
BinaryLogicalOp
):
identity
=
False
commutative
=
False
associative
=
False
def
impl
(
self
,
x
,
y
):
return
x
>=
y
ge
=
GE
()
class
EQ
(
BinaryLogicalOp
):
identity
=
False
commutative
=
True
associative
=
False
def
impl
(
self
,
x
,
y
):
return
x
==
y
eq
=
EQ
()
class
OR
(
BinaryLogicalOp
):
identity
=
False
commutative
=
True
associative
=
False
def
impl
(
self
,
x
,
y
):
return
(
x
or
y
)
or_
=
OR
()
class
XOR
(
BinaryLogicalOp
):
identity
=
False
commutative
=
True
associative
=
False
def
impl
(
self
,
x
,
y
):
return
operator
.
xor
(
x
,
y
)
xor
=
XOR
()
class
AND
(
BinaryLogicalOp
):
identity
=
False
commutative
=
True
associative
=
False
def
impl
(
self
,
x
,
y
):
return
x
and
y
and_
=
AND
()
class
NOT
(
UnaryLogicalOp
):
identity
=
False
def
impl
(
self
,
x
):
return
not
x
not_
=
NOT
()
class
Add
(
ScalarOp
):
class
Add
(
ScalarOp
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论