Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
669b911a
提交
669b911a
authored
2月 02, 2012
作者:
David Warde-Farley
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #418 from delallea/minor
Minor stuff
上级
4cfc68f2
75150064
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
25 行增加
和
25 行删除
+25
-25
NEWS.txt
doc/NEWS.txt
+1
-1
basic.py
theano/tensor/basic.py
+9
-4
elemwise.py
theano/tensor/elemwise.py
+6
-10
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+9
-10
没有找到文件。
doc/NEWS.txt
浏览文件 @
669b911a
...
...
@@ -72,7 +72,7 @@ Scan fix:
* computing grad of a function of grad of scan(reported by ?, Razvan)
before : most of the time crash, but could be wrong value with bad number of dimensions(so a visible bug)
now : do the right thing.
* gradient with respect to outputs using multiple taps(
Timothy reported
, fix by Razvan)
* gradient with respect to outputs using multiple taps(
reported by Timothy
, fix by Razvan)
before : it used to return wrong values
now : do the right thing.
Note: The reported case of this bug was happening in conjunction with the
...
...
theano/tensor/basic.py
浏览文件 @
669b911a
...
...
@@ -37,9 +37,10 @@ python_any = any
python_all
=
all
# Define common subsets of dtypes (as strings).
int_dtypes
=
map
(
str
,
scal
.
int_types
)
discrete_dtypes
=
map
(
str
,
scal
.
discrete_types
)
complex_dtypes
=
map
(
str
,
scal
.
complex_types
)
continuous_dtypes
=
map
(
str
,
scal
.
continuous_types
)
discrete_dtypes
=
map
(
str
,
scal
.
discrete_types
)
int_dtypes
=
map
(
str
,
scal
.
int_types
)
class
ShapeError
(
Exception
):
...
...
@@ -2686,8 +2687,10 @@ def mean(input, axis=None, dtype=None, op=False):
:param dtype: dtype to use for the inner summation. This will not
necessarily be the dtype of the output (in particular
if it is a discrete (int/uint) dtype, the output will
be in a float type)
:type dtype: string
be in a float type).
If None, then we use float64 for a discrete input, and the
same rules as `sum()` for a continuous input.
:type dtype: None or string
:note: for gpu, if you specify dtype=float32, everything will be done
on the gpu.
...
...
@@ -2712,6 +2715,8 @@ def mean(input, axis=None, dtype=None, op=False):
shp
=
shape
(
input
)
# Cast shp into a float type
# TODO Once we have a consistent casting policy, we could simply
# use true_div.
if
s
.
dtype
in
(
'float32'
,
'complex64'
):
shp
=
cast
(
shp
,
'float32'
)
else
:
...
...
theano/tensor/elemwise.py
浏览文件 @
669b911a
...
...
@@ -13,7 +13,6 @@ from theano.gof.python25 import all, any
config
=
theano
.
config
# tensor depends on elemwise to provide definitions for several ops
# but elemwise needs to make TensorType instances, so we have these as
# placeholders and the tensor module fills them
...
...
@@ -29,10 +28,6 @@ def TensorVariable(*inputs, **kwargs):
def
TensorConstant
(
*
inputs
,
**
kwargs
):
raise
Exception
(
"Circular dependencies prevent using this here. import tensor before elemwise"
)
# Define common subsets of dtypes (as strings).
discrete_dtypes
=
map
(
str
,
scalar
.
discrete_types
)
continuous_dtypes
=
map
(
str
,
scalar
.
continuous_types
)
##################
### DimShuffle ###
...
...
@@ -1337,9 +1332,9 @@ class CAReduceDtype(CAReduce):
:param scalar_op: a binary scalar op with only one output.
It must be commutative and associative.
:
axis:
- the dimension along which we want to reduce
- list of dimensions that we want to reduce
- if None, all dimensions are reduced
:
param axis:
- the dimension along which we want to reduce
- list of dimensions that we want to reduce
- if None, all dimensions are reduced
:param dtype: The dtype of the internal accumulator and returned
tensor. If None, then we use the default dtype which is the same as the
...
...
@@ -1365,7 +1360,7 @@ class CAReduceDtype(CAReduce):
def
_output_dtype
(
self
,
idtype
):
dtype
=
self
.
dtype
if
dtype
is
None
:
# If input has a
n
discrete dtype, upcast it to 64
# If input has a discrete dtype, upcast it to 64
return
dict
(
int8
=
'int64'
,
int16
=
'int64'
,
...
...
@@ -1374,7 +1369,8 @@ class CAReduceDtype(CAReduce):
uint16
=
'uint64'
,
uint32
=
'uint64'
,
)
.
get
(
idtype
,
idtype
)
elif
dtype
in
continuous_dtypes
and
idtype
in
discrete_dtypes
:
elif
(
dtype
in
theano
.
tensor
.
continuous_dtypes
and
idtype
in
theano
.
tensor
.
discrete_dtypes
):
# Specifying a continuous output for discrete input is OK
return
dtype
else
:
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
669b911a
...
...
@@ -13,7 +13,6 @@ from theano.compile.mode import get_default_mode
from
theano.tensor.elemwise
import
*
from
theano.tests
import
unittest_tools
complex_dtypes
=
map
(
str
,
scalar
.
complex_types
)
def
Env
(
i
,
o
):
e
=
gof
.
Env
(
i
,
o
)
...
...
@@ -534,8 +533,8 @@ class T_sum_dtype(unittest.TestCase):
# We always allow int/uint inputs with float/complex outputs.
upcasted_dtype
=
scalar
.
upcast
(
input_dtype
,
output_dtype
)
if
(
output_dtype
==
upcasted_dtype
or
(
input_dtype
in
discrete_dtypes
and
output_dtype
in
continuous_dtypes
)
(
input_dtype
in
tensor
.
discrete_dtypes
and
output_dtype
in
tensor
.
continuous_dtypes
)
):
sum_var
=
x
.
sum
(
dtype
=
output_dtype
,
axis
=
axis
)
assert
sum_var
.
dtype
==
output_dtype
...
...
@@ -559,7 +558,7 @@ class T_mean_dtype(unittest.TestCase):
for
idx
,
dtype
in
enumerate
(
imap
(
str
,
theano
.
scalar
.
all_types
)):
axis
=
axes
[
idx
%
len
(
axes
)]
x
=
tensor
.
matrix
(
dtype
=
dtype
)
.
mean
(
axis
=
axis
)
if
dtype
in
discrete_dtypes
:
if
dtype
in
tensor
.
discrete_dtypes
:
assert
x
.
dtype
==
'float64'
else
:
assert
x
.
dtype
==
dtype
,
(
x
,
x
.
dtype
,
dtype
)
...
...
@@ -582,7 +581,7 @@ class T_mean_dtype(unittest.TestCase):
pass
else
:
# Executed if no TypeError was raised
if
sum_dtype
in
discrete_dtypes
:
if
sum_dtype
in
tensor
.
discrete_dtypes
:
assert
mean_var
.
dtype
==
'float64'
,
(
mean_var
.
dtype
,
sum_dtype
)
else
:
assert
mean_var
.
dtype
==
sum_dtype
,
(
mean_var
.
dtype
,
output_dtype
)
...
...
@@ -594,7 +593,7 @@ class T_mean_dtype(unittest.TestCase):
except
NotImplementedError
:
# TrueDiv does not seem to have a gradient when
# the numerator is complex.
if
mean_var
.
dtype
in
complex_dtypes
:
if
mean_var
.
dtype
in
tensor
.
complex_dtypes
:
pass
else
:
raise
...
...
@@ -635,8 +634,8 @@ class T_prod_dtype(unittest.TestCase):
# We always allow int/uint inputs with float/complex outputs.
upcasted_dtype
=
scalar
.
upcast
(
input_dtype
,
output_dtype
)
if
(
output_dtype
==
upcasted_dtype
or
(
input_dtype
in
discrete_dtypes
and
output_dtype
in
continuous_dtypes
)
(
input_dtype
in
tensor
.
discrete_dtypes
and
output_dtype
in
tensor
.
continuous_dtypes
)
):
prod_var
=
x
.
prod
(
dtype
=
output_dtype
,
axis
=
axis
)
assert
prod_var
.
dtype
==
output_dtype
...
...
@@ -684,8 +683,8 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
# We always allow int/uint inputs with float/complex outputs.
upcasted_dtype
=
scalar
.
upcast
(
input_dtype
,
output_dtype
)
if
(
output_dtype
==
upcasted_dtype
or
(
input_dtype
in
discrete_dtypes
and
output_dtype
in
continuous_dtypes
)
(
input_dtype
in
tensor
.
discrete_dtypes
and
output_dtype
in
tensor
.
continuous_dtypes
)
):
prod_woz_var
=
ProdWithoutZeros
(
axis
=
axis
,
dtype
=
output_dtype
)(
x
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论