Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e49d3173
提交
e49d3173
authored
2月 27, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added is_valid_value to the Type interface
上级
11c7bab8
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
28 行增加
和
0 行删除
+28
-0
basic.py
theano/scalar/basic.py
+8
-0
basic.py
theano/sparse/basic.py
+9
-0
basic.py
theano/tensor/basic.py
+11
-0
没有找到文件。
theano/scalar/basic.py
浏览文件 @
e49d3173
...
@@ -52,6 +52,14 @@ class Scalar(Type):
...
@@ -52,6 +52,14 @@ class Scalar(Type):
except
Exception
,
e
:
except
Exception
,
e
:
raise
TypeError
(
"Could not convert
%
s (value=
%
s) to
%
s"
%
(
type
(
data
),
data
,
self
.
dtype
),
e
)
raise
TypeError
(
"Could not convert
%
s (value=
%
s) to
%
s"
%
(
type
(
data
),
data
,
self
.
dtype
),
e
)
def
values_eq_enough
(
self
,
a
,
b
):
return
abs
(
a
-
b
)
/
(
a
+
b
)
<
1e-4
def
is_valid_value
(
self
,
a
):
_a
=
numpy
.
asarray
(
a
)
rval
=
(
_a
.
ndim
==
0
)
and
(
str
(
_a
.
dtype
)
==
self
.
dtype
)
return
rval
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
...
...
theano/sparse/basic.py
浏览文件 @
e49d3173
...
@@ -9,6 +9,7 @@ To read about different sparse formats, see U{http://www-users.cs.umn.edu/~saad/
...
@@ -9,6 +9,7 @@ To read about different sparse formats, see U{http://www-users.cs.umn.edu/~saad/
import
sys
,
operator
import
sys
,
operator
import
numpy
import
numpy
from
scipy
import
sparse
from
scipy
import
sparse
import
scipy.sparse
from
..
import
gof
from
..
import
gof
from
..
import
tensor
from
..
import
tensor
...
@@ -185,6 +186,14 @@ class Sparse(gof.Type):
...
@@ -185,6 +186,14 @@ class Sparse(gof.Type):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"Sparse[
%
s,
%
s]"
%
(
str
(
self
.
dtype
),
str
(
self
.
format
))
return
"Sparse[
%
s,
%
s]"
%
(
str
(
self
.
dtype
),
str
(
self
.
format
))
def
values_eq_enough
(
self
,
a
,
b
,
eps
=
1e-6
):
return
scipy
.
sparse
.
issparse
(
a
)
\
and
scipy
.
sparse
.
issparse
(
b
)
\
and
abs
(
a
-
b
)
.
sum
()
<
(
1e-6
*
a
.
nnz
)
def
is_valid_value
(
self
,
a
):
return
scipy
.
sparse
.
issparse
(
a
)
and
(
a
.
format
==
self
.
format
)
csc_matrix
=
Sparse
(
format
=
'csc'
)
csc_matrix
=
Sparse
(
format
=
'csc'
)
csr_matrix
=
Sparse
(
format
=
'csr'
)
csr_matrix
=
Sparse
(
format
=
'csr'
)
...
...
theano/tensor/basic.py
浏览文件 @
e49d3173
...
@@ -226,6 +226,17 @@ class Tensor(Type):
...
@@ -226,6 +226,17 @@ class Tensor(Type):
return
type
(
a
)
is
numpy
.
ndarray
and
type
(
b
)
is
numpy
.
ndarray
\
return
type
(
a
)
is
numpy
.
ndarray
and
type
(
b
)
is
numpy
.
ndarray
\
and
(
a
.
shape
==
b
.
shape
)
and
numpy
.
allclose
(
a
,
b
)
and
(
a
.
shape
==
b
.
shape
)
and
numpy
.
allclose
(
a
,
b
)
def
is_valid_value
(
self
,
a
):
rval
=
(
type
(
a
)
is
numpy
.
ndarray
)
and
(
self
.
ndim
==
a
.
ndim
)
\
and
(
str
(
a
.
dtype
)
==
self
.
dtype
)
\
and
all
([((
si
==
1
)
or
not
bi
)
for
si
,
bi
in
zip
(
a
.
shape
,
self
.
broadcastable
)])
if
not
rval
:
print
type
(
a
),(
type
(
a
)
is
numpy
.
ndarray
)
print
a
.
ndim
,
(
self
.
ndim
==
a
.
ndim
)
print
a
.
dtype
,
(
str
(
a
.
dtype
)
==
self
.
dtype
)
print
a
.
shape
,
self
.
broadcastable
,
([(
shp_i
==
1
)
for
shp_i
in
a
.
shape
]
==
self
.
broadcastable
)
return
rval
def
__hash__
(
self
):
def
__hash__
(
self
):
"""Hash equal for same kinds of Tensor"""
"""Hash equal for same kinds of Tensor"""
return
hash
(
self
.
dtype
)
^
hash
(
self
.
broadcastable
)
return
hash
(
self
.
dtype
)
^
hash
(
self
.
broadcastable
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论