Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ec866914
提交
ec866914
authored
4月 10, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
using operators in scalar grads
上级
0d49394d
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
13 行增加
和
9 行删除
+13
-9
opt.py
opt.py
+8
-0
scalar.py
scalar.py
+5
-9
没有找到文件。
opt.py
浏览文件 @
ec866914
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
from
gof
import
opt
from
gof
import
opt
from
elemwise
import
Broadcast
from
elemwise
import
Broadcast
class
InplaceOptimizer
(
opt
.
OpSpecificOptimizer
):
class
InplaceOptimizer
(
opt
.
OpSpecificOptimizer
):
opclass
=
Broadcast
opclass
=
Broadcast
...
@@ -25,6 +26,13 @@ class InplaceOptimizer(opt.OpSpecificOptimizer):
...
@@ -25,6 +26,13 @@ class InplaceOptimizer(opt.OpSpecificOptimizer):
inplace_optimizer
=
InplaceOptimizer
()
inplace_optimizer
=
InplaceOptimizer
()
# class ElemwisePatternOptimizer(opt.Optimizer):
# def __init__(self, scalar_opt):
# self.
# def find_elemwise_cliques(env):
...
...
scalar.py
浏览文件 @
ec866914
...
@@ -45,11 +45,6 @@ class Scalar(ResultBase):
...
@@ -45,11 +45,6 @@ class Scalar(ResultBase):
def
same_properties
(
self
,
other
):
def
same_properties
(
self
,
other
):
return
other
.
dtype
==
self
.
dtype
return
other
.
dtype
==
self
.
dtype
# def mergeable(self, other):
# return getattr(self, 'constant', False) \
# and getattr(other, 'constant', False) \
# and self.data == other.data
def
dtype_specs
(
self
):
def
dtype_specs
(
self
):
try
:
try
:
return
{
'float32'
:
(
float
,
'npy_float32'
,
'PyFloat_Check'
,
'PyFloat_AsDouble'
,
'PyFloat_FromDouble'
),
return
{
'float32'
:
(
float
,
'npy_float32'
,
'PyFloat_Check'
,
'PyFloat_AsDouble'
,
'PyFloat_FromDouble'
),
...
@@ -246,7 +241,7 @@ class Sub(BinaryScalarOp):
...
@@ -246,7 +241,7 @@ class Sub(BinaryScalarOp):
def
c_code
(
self
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
(
x
,
y
),
(
z
,
),
sub
):
return
"
%(z)
s =
%(x)
s -
%(y)
s;"
%
locals
()
return
"
%(z)
s =
%(x)
s -
%(y)
s;"
%
locals
()
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
return
gz
,
neg
(
gz
)
return
gz
,
-
gz
class
Mul
(
BinaryScalarOp
):
class
Mul
(
BinaryScalarOp
):
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
...
@@ -254,7 +249,7 @@ class Mul(BinaryScalarOp):
...
@@ -254,7 +249,7 @@ class Mul(BinaryScalarOp):
def
c_code
(
self
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
(
x
,
y
),
(
z
,
),
sub
):
return
"
%(z)
s =
%(x)
s *
%(y)
s;"
%
locals
()
return
"
%(z)
s =
%(x)
s *
%(y)
s;"
%
locals
()
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
return
mul
(
y
,
gz
),
mul
(
x
,
gz
)
return
gz
*
y
,
gz
*
x
class
Div
(
BinaryScalarOp
):
class
Div
(
BinaryScalarOp
):
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
...
@@ -262,7 +257,7 @@ class Div(BinaryScalarOp):
...
@@ -262,7 +257,7 @@ class Div(BinaryScalarOp):
def
c_code
(
self
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
(
x
,
y
),
(
z
,
),
sub
):
return
"
%(z)
s =
%(x)
s /
%(y)
s;"
%
locals
()
return
"
%(z)
s =
%(x)
s /
%(y)
s;"
%
locals
()
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
return
div
(
gz
,
y
),
neg
(
div
(
mul
(
x
,
gz
),
mul
(
y
,
y
))
)
return
gz
/
y
,
-
(
gz
*
x
)
/
(
y
*
y
)
class
Pow
(
BinaryScalarOp
):
class
Pow
(
BinaryScalarOp
):
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
...
@@ -270,7 +265,8 @@ class Pow(BinaryScalarOp):
...
@@ -270,7 +265,8 @@ class Pow(BinaryScalarOp):
def
c_code
(
self
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
(
x
,
y
),
(
z
,
),
sub
):
return
"
%(z)
s = pow(
%(x)
s,
%(y)
s);"
%
locals
()
return
"
%(z)
s = pow(
%(x)
s,
%(y)
s);"
%
locals
()
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
return
mul
(
gz
,
mul
(
y
,
pow
(
x
,
sub
(
y
,
as_scalar
(
1
))))),
mul
(
gz
,
mul
(
log
(
x
),
pow
(
x
,
y
)))
return
gz
*
y
*
x
**
(
y
-
as_scalar
(
1
)),
gz
*
log
(
x
)
*
x
**
y
# return mul(gz, mul(y, pow(x, sub(y, as_scalar(1))))), mul(gz, mul(log(x), pow(x, y)))
class
First
(
BinaryScalarOp
):
class
First
(
BinaryScalarOp
):
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论