Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
12b63cdc
提交
12b63cdc
authored
7月 05, 2016
作者:
Jesse Livezey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tests pass with new casting
上级
b00ab8eb
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
0 行删除
+31
-0
corr.py
theano/tensor/nnet/corr.py
+31
-0
没有找到文件。
theano/tensor/nnet/corr.py
浏览文件 @
12b63cdc
...
@@ -75,6 +75,34 @@ class BaseCorrMM(gof.Op):
...
@@ -75,6 +75,34 @@ class BaseCorrMM(gof.Op):
str
(
self
.
subsample
),
str
(
self
.
subsample
),
str
(
self
.
filter_dilation
))
str
(
self
.
filter_dilation
))
def
cast
(
self
,
in1
,
in2
):
"""
Upcast input variables if neccesary.
"""
float_types
=
[
'float32'
,
'float64'
]
dtype_1
=
in1
.
type
.
dtype
dtype_2
=
in2
.
type
.
dtype
assert
dtype_1
in
float_types
assert
dtype_2
in
float_types
if
dtype_1
==
'float64'
or
dtype_2
==
'float64'
:
dtype_o
=
'float64'
else
:
dtype_o
=
'float32'
if
dtype_1
!=
dtype_o
:
out1
=
in1
.
astype
(
dtype_o
)
else
:
out1
=
in1
if
dtype_2
!=
dtype_o
:
out2
=
in2
.
astype
(
dtype_o
)
else
:
out2
=
in2
return
out1
,
out2
def
c_support_code
(
self
):
def
c_support_code
(
self
):
return
blas_header_text
()
return
blas_header_text
()
...
@@ -383,6 +411,7 @@ class CorrMM(BaseCorrMM):
...
@@ -383,6 +411,7 @@ class CorrMM(BaseCorrMM):
def
make_node
(
self
,
img
,
kern
):
def
make_node
(
self
,
img
,
kern
):
img
=
as_tensor_variable
(
img
)
img
=
as_tensor_variable
(
img
)
kern
=
as_tensor_variable
(
kern
)
kern
=
as_tensor_variable
(
kern
)
img
,
kern
=
self
.
cast
(
img
,
kern
)
if
img
.
type
.
ndim
!=
4
:
if
img
.
type
.
ndim
!=
4
:
raise
TypeError
(
'img must be 4D tensor'
)
raise
TypeError
(
'img must be 4D tensor'
)
if
kern
.
type
.
ndim
!=
4
:
if
kern
.
type
.
ndim
!=
4
:
...
@@ -445,6 +474,7 @@ class CorrMM_gradWeights(BaseCorrMM):
...
@@ -445,6 +474,7 @@ class CorrMM_gradWeights(BaseCorrMM):
def
make_node
(
self
,
img
,
topgrad
,
shape
=
None
):
def
make_node
(
self
,
img
,
topgrad
,
shape
=
None
):
img
=
as_tensor_variable
(
img
)
img
=
as_tensor_variable
(
img
)
topgrad
=
as_tensor_variable
(
topgrad
)
topgrad
=
as_tensor_variable
(
topgrad
)
img
,
topgrad
=
self
.
cast
(
img
,
topgrad
)
if
img
.
type
.
ndim
!=
4
:
if
img
.
type
.
ndim
!=
4
:
raise
TypeError
(
'img must be 4D tensor'
)
raise
TypeError
(
'img must be 4D tensor'
)
if
topgrad
.
type
.
ndim
!=
4
:
if
topgrad
.
type
.
ndim
!=
4
:
...
@@ -546,6 +576,7 @@ class CorrMM_gradInputs(BaseCorrMM):
...
@@ -546,6 +576,7 @@ class CorrMM_gradInputs(BaseCorrMM):
def
make_node
(
self
,
kern
,
topgrad
,
shape
=
None
):
def
make_node
(
self
,
kern
,
topgrad
,
shape
=
None
):
kern
=
as_tensor_variable
(
kern
)
kern
=
as_tensor_variable
(
kern
)
topgrad
=
as_tensor_variable
(
topgrad
)
topgrad
=
as_tensor_variable
(
topgrad
)
kern
,
topgrad
=
self
.
cast
(
kern
,
topgrad
)
if
kern
.
type
.
ndim
!=
4
:
if
kern
.
type
.
ndim
!=
4
:
raise
TypeError
(
'kern must be 4D tensor'
)
raise
TypeError
(
'kern must be 4D tensor'
)
if
topgrad
.
type
.
ndim
!=
4
:
if
topgrad
.
type
.
ndim
!=
4
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论