Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8ee3b6d6
提交
8ee3b6d6
authored
3月 18, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
e89f6631
952eabb7
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
13 行增加
和
12 行删除
+13
-12
_test_tensor.py
_test_tensor.py
+2
-1
tensor.py
tensor.py
+11
-11
没有找到文件。
_test_tensor.py
浏览文件 @
8ee3b6d6
...
...
@@ -14,6 +14,7 @@ import gof, gof.graph
def
verify_grad
(
testcase
,
op_cls
,
pt
,
n_tests
=
1
,
rng
=
numpy
.
random
,
eps
=
0.0000001
,
tol
=
0.0001
):
"""testcase.failUnless( analytic gradient matches finite-diff gradient) """
pt
=
[
numpy
.
asarray
(
p
)
for
p
in
pt
]
for
test_num
in
xrange
(
n_tests
):
tensor_pt
=
[
tinit
(
p
,
name
=
'input
%
i'
%
i
)
for
i
,
p
in
enumerate
(
pt
)]
...
...
@@ -165,7 +166,7 @@ class T_mul(unittest.TestCase):
[
numpy
.
ones
(
3
),
numpy
.
ones
(
4
)],
1.0
)
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
is
tensor
.
_assert_same_shapes
.
E_shape
)
self
.
failUnless
(
e
[
0
]
is
tensor
.
_assert_same_shapes
.
E_shape
)
class
T_div
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
tensor.py
浏览文件 @
8ee3b6d6
...
...
@@ -105,8 +105,8 @@ def _assert_same_shapes(x, *rest):
shape
=
x
.
shape
for
other
in
rest
:
if
other
.
shape
!=
shape
:
raise
_assert_same_shapes
.
E_shape
_assert_same_shapes
.
E_shape
=
ValueError
(
"The dimensions of the inputs do not match."
)
raise
ValueError
(
_assert_same_shapes
.
E_shape
)
_assert_same_shapes
.
E_shape
=
"The dimensions of the inputs do not match."
def
_assert_tensor_scalar
(
x
,
a
):
"""ensure that the second input is a scalar"""
...
...
@@ -585,8 +585,8 @@ class PowElemwise(_Elemwise):
return
x
**
y
def
grad
(
self
,
(
x
,
y
),
gz
):
gx
=
gz
*
y
*
(
pow_elemwise
(
x
,
y
-
1.0
))
g
s
=
gz
*
log
(
x
)
*
pow_elemwise
(
x
,
y
)
return
gx
,
g
s
g
y
=
gz
*
log
(
x
)
*
pow_elemwise
(
x
,
y
)
return
gx
,
g
y
def
c_foreach
(
self
,
(
x_i
,
y_i
),
(
z_i
,
)):
return
"
%(z)
s_i = pow(
%(x)
s_i,
%(y)
s_i);"
pow_elemwise
=
_constructor
(
PowElemwise
)
...
...
@@ -600,13 +600,13 @@ pow_elemwise_inplace = _constructor(PowElemwiseInplace)
# Scalar #
class
PowScalarL
(
TensorScalarOp
):
def
impl
(
self
,
x
,
a
):
_assert_tensor_scalar
(
x
,
a
)
return
a
**
x
def
grad
(
self
,
(
x
,
s
),
gz
):
gx
=
sum
(
gz
*
s
*
pow_scalar_l
(
add_scalar
(
s
,
-
1.0
),
x
))
g
s
=
scale
(
mul
(
gz
,
pow_scalar_l
(
s
,
x
)),
log
(
x
))
return
g
x
,
gs
def
impl
(
self
,
y
,
x
):
_assert_tensor_scalar
(
y
,
x
)
return
x
**
y
def
grad
(
self
,
(
y
,
x
),
gz
):
gx
=
sum
(
gz
*
y
*
x
**
(
y
-
1.0
))
g
y
=
gz
*
log
(
x
)
*
x
**
y
return
g
y
,
gx
c_expr
=
"pow(
%(a)
s,
%(x)
s_i)"
pow_scalar_l
=
_constructor
(
PowScalarL
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论