Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bcea28c3
提交
bcea28c3
authored
6月 22, 2011
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reordered definitions in sparse/basic to add Constant and Variable class vars to SparseType
上级
e73e682b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
76 行增加
和
59 行删除
+76
-59
basic.py
theano/sparse/basic.py
+76
-59
没有找到文件。
theano/sparse/basic.py
浏览文件 @
bcea28c3
...
@@ -133,6 +133,79 @@ def sp_ones_like(x):
...
@@ -133,6 +133,79 @@ def sp_ones_like(x):
data
,
indices
,
indptr
,
shape
=
csm_properties
(
x
)
#TODO: don't restrict to CSM formats
data
,
indices
,
indptr
,
shape
=
csm_properties
(
x
)
#TODO: don't restrict to CSM formats
return
CSM
(
format
=
x
.
format
)(
tensor
.
ones_like
(
data
),
indices
,
indptr
,
shape
)
return
CSM
(
format
=
x
.
format
)(
tensor
.
ones_like
(
data
),
indices
,
indptr
,
shape
)
class
_sparse_py_operators
:
T
=
property
(
lambda
self
:
transpose
(
self
),
doc
=
"Return aliased transpose of self (read-only)"
)
def
__neg__
(
self
):
return
neg
(
self
)
def
__add__
(
left
,
right
):
return
add
(
left
,
right
)
def
__radd__
(
right
,
left
):
return
add
(
left
,
right
)
def
__sub__
(
left
,
right
):
return
sub
(
left
,
right
)
def
__rsub__
(
right
,
left
):
return
sub
(
left
,
right
)
def
__mul__
(
left
,
right
):
return
mul
(
left
,
right
)
def
__rmul__
(
left
,
right
):
return
mul
(
left
,
right
)
#extra pseudo-operator symbols
def
__dot__
(
left
,
right
):
return
structured_dot
(
left
,
right
)
def
__rdot__
(
right
,
left
):
return
structured_dot
(
left
,
right
)
#N.B. THIS IS COMMENTED OUT ON PURPOSE!!!
# Discussion with Fred & James (at least, and maybe others before)
# we decided that casting from a sparse to dense should be explicit
# because it's usually something you want to be pretty careful about,
# and not to do by accident.
#def _as_TensorVariable(self):
# return dense_from_sparse(self)
shape
=
property
(
lambda
self
:
tensor
.
shape
(
dense_from_sparse
(
self
)))
# don't worry!
# ... the plan is that the ShapeFeature in tensor.opt will do shape propagation
# ... and remove the dense_from_sparse from the graph. This will *NOT* actually expand
# ... your sparse matrix just to get the shape.
ndim
=
property
(
lambda
self
:
self
.
type
.
ndim
)
dtype
=
property
(
lambda
self
:
self
.
type
.
dtype
)
class
SparseVariable
(
gof
.
Variable
,
_sparse_py_operators
):
dtype
=
property
(
lambda
self
:
self
.
type
.
dtype
)
format
=
property
(
lambda
self
:
self
.
type
.
format
)
def
__str__
(
self
):
return
'
%
s{
%
s,
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
format
,
self
.
dtype
)
def
__repr__
(
self
):
return
str
(
self
)
class
SparseConstantSignature
(
tuple
):
def
__eq__
(
self
,
other
):
(
a
,
b
),
(
x
,
y
)
=
self
,
other
return
a
==
x
\
and
(
b
.
dtype
==
y
.
dtype
)
\
and
(
type
(
b
)
==
type
(
y
))
\
and
(
b
.
shape
==
y
.
shape
)
\
and
(
abs
(
b
-
y
)
.
sum
()
<
1e-6
*
b
.
nnz
)
def
__hash__
(
self
):
(
a
,
b
)
=
self
return
hash
(
type
(
self
))
^
hash
(
a
)
^
hash
(
type
(
b
))
class
SparseConstant
(
gof
.
Constant
,
_sparse_py_operators
):
dtype
=
property
(
lambda
self
:
self
.
type
.
dtype
)
format
=
property
(
lambda
self
:
self
.
type
.
format
)
def
signature
(
self
):
assert
self
.
data
is
not
None
return
SparseConstantSignature
((
self
.
type
,
self
.
data
))
def
__str__
(
self
):
return
'
%
s{
%
s,
%
s,shape=
%
s,nnz=
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
format
,
self
.
dtype
,
self
.
data
.
shape
,
self
.
data
.
nnz
)
def
__repr__
(
self
):
return
str
(
self
)
class
SparseValue
(
gof
.
Value
,
_sparse_py_operators
):
dtype
=
property
(
lambda
self
:
self
.
type
.
dtype
)
format
=
property
(
lambda
self
:
self
.
type
.
format
)
class
SparseType
(
gof
.
Type
):
class
SparseType
(
gof
.
Type
):
"""
"""
...
@@ -149,6 +222,9 @@ class SparseType(gof.Type):
...
@@ -149,6 +222,9 @@ class SparseType(gof.Type):
dtype_set
=
set
([
'int'
,
'int8'
,
'int16'
,
'int32'
,
'int64'
,
'float32'
,
'float64'
,
'complex64'
,
'complex128'
])
dtype_set
=
set
([
'int'
,
'int8'
,
'int16'
,
'int32'
,
'int64'
,
'float32'
,
'float64'
,
'complex64'
,
'complex128'
])
ndim
=
2
ndim
=
2
Variable
=
SparseVariable
Constant
=
SparseConstant
def
__init__
(
self
,
format
,
dtype
):
def
__init__
(
self
,
format
,
dtype
):
"""
"""
Fundamental way to create a sparse node.
Fundamental way to create a sparse node.
...
@@ -248,65 +324,6 @@ csr_dmatrix = SparseType(format='csr', dtype='float64')
...
@@ -248,65 +324,6 @@ csr_dmatrix = SparseType(format='csr', dtype='float64')
csc_fmatrix
=
SparseType
(
format
=
'csc'
,
dtype
=
'float32'
)
csc_fmatrix
=
SparseType
(
format
=
'csc'
,
dtype
=
'float32'
)
csr_fmatrix
=
SparseType
(
format
=
'csr'
,
dtype
=
'float32'
)
csr_fmatrix
=
SparseType
(
format
=
'csr'
,
dtype
=
'float32'
)
class
_sparse_py_operators
:
T
=
property
(
lambda
self
:
transpose
(
self
),
doc
=
"Return aliased transpose of self (read-only)"
)
def
__neg__
(
self
):
return
neg
(
self
)
def
__add__
(
left
,
right
):
return
add
(
left
,
right
)
def
__radd__
(
right
,
left
):
return
add
(
left
,
right
)
def
__sub__
(
left
,
right
):
return
sub
(
left
,
right
)
def
__rsub__
(
right
,
left
):
return
sub
(
left
,
right
)
def
__mul__
(
left
,
right
):
return
mul
(
left
,
right
)
def
__rmul__
(
left
,
right
):
return
mul
(
left
,
right
)
#extra pseudo-operator symbols
def
__dot__
(
left
,
right
):
return
structured_dot
(
left
,
right
)
def
__rdot__
(
right
,
left
):
return
structured_dot
(
left
,
right
)
#N.B. THIS IS COMMENTED OUT ON PURPOSE!!!
# Discussion with Fred & James (at least, and maybe others before)
# we decided that casting from a sparse to dense should be explicit
# because it's usually something you want to be pretty careful about,
# and not to do by accident.
#def _as_TensorVariable(self):
# return dense_from_sparse(self)
shape
=
property
(
lambda
self
:
tensor
.
shape
(
dense_from_sparse
(
self
)))
# don't worry!
# ... the plan is that the ShapeFeature in tensor.opt will do shape propagation
# ... and remove the dense_from_sparse from the graph. This will *NOT* actually expand
# ... your sparse matrix just to get the shape.
ndim
=
property
(
lambda
self
:
self
.
type
.
ndim
)
dtype
=
property
(
lambda
self
:
self
.
type
.
dtype
)
class
SparseVariable
(
gof
.
Variable
,
_sparse_py_operators
):
dtype
=
property
(
lambda
self
:
self
.
type
.
dtype
)
format
=
property
(
lambda
self
:
self
.
type
.
format
)
class
SparseConstantSignature
(
tuple
):
def
__eq__
(
self
,
other
):
(
a
,
b
),
(
x
,
y
)
=
self
,
other
return
a
==
x
\
and
(
b
.
dtype
==
y
.
dtype
)
\
and
(
type
(
b
)
==
type
(
y
))
\
and
(
b
.
shape
==
y
.
shape
)
\
and
(
abs
(
b
-
y
)
.
sum
()
<
1e-6
*
b
.
nnz
)
def
__hash__
(
self
):
(
a
,
b
)
=
self
return
hash
(
type
(
self
))
^
hash
(
a
)
^
hash
(
type
(
b
))
class
SparseConstant
(
gof
.
Constant
,
_sparse_py_operators
):
dtype
=
property
(
lambda
self
:
self
.
type
.
dtype
)
format
=
property
(
lambda
self
:
self
.
type
.
format
)
def
signature
(
self
):
assert
self
.
data
is
not
None
return
SparseConstantSignature
((
self
.
type
,
self
.
data
))
class
SparseValue
(
gof
.
Value
,
_sparse_py_operators
):
dtype
=
property
(
lambda
self
:
self
.
type
.
dtype
)
format
=
property
(
lambda
self
:
self
.
type
.
format
)
# CONSTRUCTION
# CONSTRUCTION
class
CSMProperties
(
gof
.
Op
):
class
CSMProperties
(
gof
.
Op
):
"""Extract all of .data .indices and .indptr"""
"""Extract all of .data .indices and .indptr"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论