Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1e55dc82
提交
1e55dc82
authored
5月 13, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improved error messages to filter in scalar and tensor
上级
2ccbf402
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
32 行增加
和
23 行删除
+32
-23
scalar.py
scalar.py
+6
-2
tensor.py
tensor.py
+26
-21
没有找到文件。
scalar.py
浏览文件 @
1e55dc82
...
@@ -45,8 +45,12 @@ class Scalar(Type):
...
@@ -45,8 +45,12 @@ class Scalar(Type):
def
filter
(
self
,
data
,
strict
=
False
):
def
filter
(
self
,
data
,
strict
=
False
):
py_type
=
self
.
dtype_specs
()[
0
]
py_type
=
self
.
dtype_specs
()[
0
]
if
strict
:
assert
isinstance
(
data
,
py_type
)
if
strict
and
not
isinstance
(
data
,
py_type
):
return
py_type
(
data
)
raise
TypeError
(
"
%
s expected a
%
s"
%
(
self
,
self
.
dtype
),
data
)
try
:
return
py_type
(
data
)
except
Exception
,
e
:
raise
TypeError
(
"Could not convert to
%
s"
%
self
.
dtype
,
e
)
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
other
.
dtype
==
self
.
dtype
return
type
(
self
)
==
type
(
other
)
and
other
.
dtype
==
self
.
dtype
...
...
tensor.py
浏览文件 @
1e55dc82
...
@@ -12,7 +12,7 @@ import gof
...
@@ -12,7 +12,7 @@ import gof
import
blas
# for gemm, dot
import
blas
# for gemm, dot
import
gradient
import
gradient
import
elemwise
as
s2t
import
elemwise
import
scalar
as
scal
import
scalar
as
scal
from
gof.python25
import
partial
from
gof.python25
import
partial
...
@@ -91,14 +91,19 @@ class Tensor(Type):
...
@@ -91,14 +91,19 @@ class Tensor(Type):
def
filter
(
self
,
data
,
strict
=
False
):
def
filter
(
self
,
data
,
strict
=
False
):
_data
=
data
_data
=
data
if
strict
:
if
strict
:
assert
isinstance
(
data
,
numpy
.
ndarray
)
if
not
isinstance
(
data
,
numpy
.
ndarray
):
assert
str
(
data
.
dtype
)
==
self
.
dtype
raise
TypeError
(
"
%
s expected a ndarray object."
,
data
,
type
(
data
))
if
not
str
(
data
.
dtype
)
==
self
.
dtype
:
raise
TypeError
(
"
%
s expected a ndarray object with dtype =
%
s (got
%
s)."
%
(
self
,
self
.
dtype
,
data
.
dtype
))
if
not
data
.
ndim
==
self
.
ndim
:
raise
TypeError
(
"
%
s expected a ndarray object with
%
s dimensions (got
%
s)."
%
(
self
,
self
.
ndim
,
data
.
ndim
))
return
data
else
:
else
:
data
=
numpy
.
asarray
(
data
,
dtype
=
self
.
dtype
)
data
=
numpy
.
asarray
(
data
,
dtype
=
self
.
dtype
)
if
not
self
.
ndim
==
data
.
ndim
:
if
not
self
.
ndim
==
data
.
ndim
:
raise
TypeError
(
"Wrong number of dimensions: expected
%
s, got
%
s."
%
(
self
.
ndim
,
data
.
ndim
),
_data
)
raise
TypeError
(
"Wrong number of dimensions: expected
%
s, got
%
s."
%
(
self
.
ndim
,
data
.
ndim
),
_data
)
if
any
(
b
and
d
!=
1
for
d
,
b
in
zip
(
data
.
shape
,
self
.
broadcastable
)):
if
any
(
b
and
d
!=
1
for
d
,
b
in
zip
(
data
.
shape
,
self
.
broadcastable
)):
raise
Valu
eError
(
"Non-unit value on shape on a broadcastable dimension."
,
data
.
shape
,
self
.
broadcastable
)
raise
Typ
eError
(
"Non-unit value on shape on a broadcastable dimension."
,
data
.
shape
,
self
.
broadcastable
)
return
data
return
data
def
dtype_specs
(
self
):
def
dtype_specs
(
self
):
...
@@ -392,11 +397,11 @@ class TensorConstant(Constant, _tensor_py_operators):
...
@@ -392,11 +397,11 @@ class TensorConstant(Constant, _tensor_py_operators):
class
TensorValue
(
Value
,
_tensor_py_operators
):
class
TensorValue
(
Value
,
_tensor_py_operators
):
pass
pass
s2t
.
as_tensor
=
as_tensor
elemwise
.
as_tensor
=
as_tensor
s2t
.
Tensor
=
Tensor
elemwise
.
Tensor
=
Tensor
s2t
.
TensorResult
=
TensorResult
elemwise
.
TensorResult
=
TensorResult
s2t
.
TensorConstant
=
TensorConstant
elemwise
.
TensorConstant
=
TensorConstant
s2t
.
TensorValue
=
TensorValue
elemwise
.
TensorValue
=
TensorValue
...
@@ -405,9 +410,9 @@ s2t.TensorValue = TensorValue
...
@@ -405,9 +410,9 @@ s2t.TensorValue = TensorValue
#########################
#########################
def
_elemwise
(
scalar_op
,
name
):
def
_elemwise
(
scalar_op
,
name
):
straight
=
s2t
.
Elemwise
(
scalar_op
)
straight
=
elemwise
.
Elemwise
(
scalar_op
,
name
=
name
)
inplace_scalar_op
=
scalar_op
.
__class__
(
scal
.
transfer_type
(
0
))
inplace_scalar_op
=
scalar_op
.
__class__
(
scal
.
transfer_type
(
0
))
inplace
=
s2t
.
Elemwise
(
inplace_scalar_op
,
{
0
:
0
},
name
=
name
)
inplace
=
elemwise
.
Elemwise
(
inplace_scalar_op
,
{
0
:
0
},
name
=
name
+
"_inplace"
)
return
straight
,
inplace
return
straight
,
inplace
...
@@ -454,14 +459,14 @@ def cast(t, dtype):
...
@@ -454,14 +459,14 @@ def cast(t, dtype):
'complex128'
:
convert_to_complex128
}
'complex128'
:
convert_to_complex128
}
return
mapping
[
dtype
](
t
)
return
mapping
[
dtype
](
t
)
convert_to_int8
=
s2t
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
int8
)))
convert_to_int8
=
elemwise
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
int8
)))
convert_to_int16
=
s2t
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
int16
)))
convert_to_int16
=
elemwise
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
int16
)))
convert_to_int32
=
s2t
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
int32
)))
convert_to_int32
=
elemwise
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
int32
)))
convert_to_int64
=
s2t
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
int64
)))
convert_to_int64
=
elemwise
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
int64
)))
convert_to_float32
=
s2t
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
float32
)))
convert_to_float32
=
elemwise
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
float32
)))
convert_to_float64
=
s2t
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
float64
)))
convert_to_float64
=
elemwise
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
float64
)))
convert_to_complex64
=
s2t
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
complex64
)))
convert_to_complex64
=
elemwise
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
complex64
)))
convert_to_complex128
=
s2t
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
complex128
)))
convert_to_complex128
=
elemwise
.
Elemwise
(
scal
.
Identity
(
scal
.
specific_out
(
scal
.
complex128
)))
...
@@ -580,10 +585,10 @@ def ones_like(model):
...
@@ -580,10 +585,10 @@ def ones_like(model):
def
zeros_like
(
model
):
def
zeros_like
(
model
):
return
fill
(
model
,
0.0
)
return
fill
(
model
,
0.0
)
tensor_copy
=
s2t
.
Elemwise
(
scal
.
identity
)
tensor_copy
=
elemwise
.
Elemwise
(
scal
.
identity
)
def
sum
(
input
,
axis
=
None
):
def
sum
(
input
,
axis
=
None
):
return
s2t
.
Sum
(
axis
)(
input
)
return
elemwise
.
Sum
(
axis
)(
input
)
##########################
##########################
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论