Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8aada18a
提交
8aada18a
authored
1月 14, 2008
作者:
olivier@olivier-desktop
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
m
上级
bc361363
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
38 行增加
和
20 行删除
+38
-20
core.py
core.py
+12
-9
test.py
test.py
+26
-11
没有找到文件。
core.py
浏览文件 @
8aada18a
...
@@ -155,11 +155,11 @@ class omega_op(gof.PythonOp):
...
@@ -155,11 +155,11 @@ class omega_op(gof.PythonOp):
def
scalar_switch
(
x
,
y
,
normal_f
,
scalar_f
):
def
scalar_switch
(
x
,
y
,
normal_f
,
scalar_f
):
x
,
y
=
wrap
(
x
),
wrap
(
y
)
#
x, y = wrap(x), wrap(y)
if
x
.
constant
and
not
x
.
data
.
shape
:
#
if x.constant and not x.data.shape:
return
scalar_f
(
y
,
x
)
#
return scalar_f(y, x)
if
y
.
constant
and
not
y
.
data
.
shape
:
#
if y.constant and not y.data.shape:
return
scalar_f
(
x
,
y
)
#
return scalar_f(x, y)
return
normal_f
(
x
,
y
)
return
normal_f
(
x
,
y
)
...
@@ -231,10 +231,13 @@ class iadd(proto_add, inplace):
...
@@ -231,10 +231,13 @@ class iadd(proto_add, inplace):
class
add_scalar
(
omega_op
):
class
add_scalar
(
omega_op
):
impl
=
numpy
.
ndarray
.
__add__
impl
=
numpy
.
ndarray
.
__add__
class
iadd_scalar
(
omega_op
,
inplace
):
impl
=
numpy
.
ndarray
.
__add__
class
proto_twice
(
omega_op
):
class
proto_twice
(
omega_op
):
def
grad
(
x
,
gz
):
def
grad
(
x
,
gz
):
return
scal
(
gz
,
2.0
)
return
scal
e
(
gz
,
2.0
)
class
twice
(
proto_twice
):
class
twice
(
proto_twice
):
def
impl
(
x
):
def
impl
(
x
):
...
@@ -280,7 +283,7 @@ class imul(proto_mul, inplace):
...
@@ -280,7 +283,7 @@ class imul(proto_mul, inplace):
class
proto_sqr
(
omega_op
):
class
proto_sqr
(
omega_op
):
def
grad
(
x
,
gz
):
def
grad
(
x
,
gz
):
return
scal
(
mul
(
x
,
gz
),
2.0
)
return
scal
e
(
mul
(
x
,
gz
),
2.0
)
class
sqr
(
proto_sqr
):
class
sqr
(
proto_sqr
):
impl
=
lambda
x
:
numpy
.
multiply
(
x
,
x
)
impl
=
lambda
x
:
numpy
.
multiply
(
x
,
x
)
...
@@ -291,7 +294,7 @@ class isqr(proto_sqr, inplace):
...
@@ -291,7 +294,7 @@ class isqr(proto_sqr, inplace):
class
proto_sqrt
(
omega_op
):
class
proto_sqrt
(
omega_op
):
def
grad
(
x
,
gz
):
def
grad
(
x
,
gz
):
return
scal
(
div
(
gz
,
sqrt
(
x
)),
0.5
)
return
scal
e
(
div
(
gz
,
sqrt
(
x
)),
0.5
)
class
sqrt
(
proto_sqrt
):
class
sqrt
(
proto_sqrt
):
impl
=
numpy
.
sqrt
impl
=
numpy
.
sqrt
...
@@ -329,7 +332,7 @@ class iinv_scale(omega_op, inplace):
...
@@ -329,7 +332,7 @@ class iinv_scale(omega_op, inplace):
class
proto_scale
(
omega_op
):
class
proto_scale
(
omega_op
):
def
grad
(
x
,
a
,
gz
):
def
grad
(
x
,
a
,
gz
):
return
scal
(
a
,
gz
),
sum
(
mul
(
x
,
gz
))
return
scal
e
(
a
,
gz
),
sum
(
mul
(
x
,
gz
))
class
scale
(
omega_op
):
class
scale
(
omega_op
):
impl
=
numpy
.
ndarray
.
__mul__
impl
=
numpy
.
ndarray
.
__mul__
...
...
test.py
浏览文件 @
8aada18a
...
@@ -131,6 +131,7 @@ import grad
...
@@ -131,6 +131,7 @@ import grad
############################
############################
# def dataset_1hot(x, targ, n):
# def dataset_1hot(x, targ, n):
# """Return an looping iterator over 1-hot vectors
# """Return an looping iterator over 1-hot vectors
...
@@ -181,15 +182,6 @@ import grad
...
@@ -181,15 +182,6 @@ import grad
# # 1 = mul(mul(neg(scal(mul(sub(0.736213102665, sigmoid(*3)), 1.0), 2.0)), sigmoid(*3)), sub(1, sigmoid(*3)))
# # 2 = transpose(0.11474051836)
# # 3 = dot(*2, *5)
# # 4 = dot(0.11474051836, 0.736213102665)
# # 5 = sigmoid(*4)
# # add(transpose(dot(*1, transpose(*5))), dot(mul(mul(dot(transpose(*2), *1), sigmoid(*4)), sub(1, sigmoid(*4))), transpose(0.736213102665)))
############################
############################
...
@@ -209,8 +201,31 @@ import grad
...
@@ -209,8 +201,31 @@ import grad
############################
############################
print
core
.
ones
((
2
,
2
))
+
1
# print core.ones((2, 2)) + 1
# print numpy.ones((2, 2)) ** numpy.ones((2, 2))
############################
x
=
core
.
ones
((
2
,
2
))
y
=
core
.
zeros
((
1
,
1
))
#print "?", gof.graph.ops([], [x + y])
print
x
x
+
x
print
"1"
,
gof
.
eval_env
#.ops()
y
+
y
print
"2"
,
gof
.
eval_env
#.ops()
x
+
x
print
"3"
,
gof
.
eval_env
#.ops()
print
numpy
.
ones
((
2
,
2
))
**
numpy
.
ones
((
2
,
2
))
x
+=
(
x
+
x
)
print
x
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论