Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f1ff66e0
提交
f1ff66e0
authored
4月 23, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
merged
上级
a1d8376e
ef638c6a
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
48 行增加
和
15 行删除
+48
-15
__init__.py
__init__.py
+4
-2
_test_sparse.py
_test_sparse.py
+1
-5
elemwise.py
elemwise.py
+9
-2
op.py
gof/op.py
+10
-3
scalar.py
scalar.py
+7
-1
sparse.py
sparse.py
+5
-0
tensor.py
tensor.py
+12
-2
没有找到文件。
__init__.py
浏览文件 @
f1ff66e0
...
...
@@ -4,10 +4,12 @@ import tensor
import
sparse
import
compile
import
gradient
import
opt
import
tensor_opt
import
scalar_opt
from
tensor
import
*
from
compile
import
*
from
opt
import
*
from
tensor_opt
import
*
from
scalar_opt
import
*
from
gradient
import
*
_test_sparse.py
浏览文件 @
f1ff66e0
...
...
@@ -5,11 +5,7 @@ import compile
import
gradient
from
sparse
import
_is_dense
,
_is_sparse
,
_is_dense_result
,
_is_sparse_result
""" Types of sparse matrices to use for testing """
_mtypes
=
[
sparse
.
csc_matrix
,
sparse
.
csr_matrix
]
#_mtypes = [sparse.csc_matrix, sparse.csr_matrix, sparse.dok_matrix, sparse.lil_matrix, sparse.coo_matrix]
_mtype_to_str
=
{
sparse
.
csc_matrix
:
"csc"
,
sparse
.
csr_matrix
:
"csr"
}
from
sparse
import
_mtypes
,
_mtype_to_str
class
T_transpose
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
elemwise.py
浏览文件 @
f1ff66e0
...
...
@@ -321,8 +321,15 @@ class Broadcast(Op, Destroyer):
# the second calling form is used because in certain versions of numpy
# the first (faster) version leads to segfaults
ufunc_args
=
[
input
.
data
for
input
in
self
.
inputs
]
# + output_storage
#self.ufunc(*(ufunc_args+output_storage))
output_storage
[
0
][:]
=
self
.
ufunc
(
*
ufunc_args
)
results
=
self
.
ufunc
(
*
ufunc_args
)
if
self
.
ufunc
.
nout
==
1
:
results
=
[
results
]
for
result
,
storage
in
zip
(
results
,
output_storage
):
if
storage
.
shape
:
storage
[:]
=
result
else
:
storage
.
itemset
(
result
)
# the following should be used instead of the previous loop, unfortunately it tends to segfault
# self.ufunc(*(ufunc_args+output_storage))
def
_c_all
(
self
,
inames
,
onames
,
sub
):
_inames
=
inames
...
...
gof/op.py
浏览文件 @
f1ff66e0
...
...
@@ -89,6 +89,13 @@ class Op(object):
return
self
.
_hash_id
def
desc
(
self
):
"""
Description (signature) of this L{Op}. L{Op}s with the same
signature may be collapsed by the L{MergeOptimizer}.
@attention: If your L{Op} has additional options or a different
constructor you probably want to override this.
"""
return
self
.
__class__
def
strdesc
(
self
):
...
...
@@ -139,10 +146,10 @@ class Op(object):
"""
Shallow copy of this L{Op}. The inputs are the exact same, but
the outputs are recreated because of the one-owner-per-result
policy. The default behavior is to call the constructor on
this
L{Op}'s inputs.
policy. The default behavior is to call the constructor on
this
L{Op}'s inputs.
To do a bottom-up copy of a graph, use
clone_with_new_inputs
.
To do a bottom-up copy of a graph, use
L{clone_with_new_inputs}
.
@attention: If your L{Op} has additional options or a different
constructor you probably want to override this.
...
...
scalar.py
浏览文件 @
f1ff66e0
...
...
@@ -11,6 +11,11 @@ from gof import Result, GuardedOp, Env, utils
def
as_scalar
(
x
,
name
=
None
):
if
isinstance
(
x
,
gof
.
Op
):
if
len
(
x
.
outputs
)
!=
1
:
raise
ValueError
(
"It is ambiguous which output of a multi-output Op has to be fetched."
,
x
)
else
:
x
=
x
.
outputs
[
0
]
if
isinstance
(
x
,
float
):
s
=
Scalar
(
'float64'
,
name
=
name
)
s
.
data
=
x
...
...
@@ -21,6 +26,7 @@ def as_scalar(x, name = None):
return
s
if
isinstance
(
x
,
Scalar
):
return
x
raise
TypeError
(
"Cannot convert
%
s to Scalar"
%
x
)
def
constant
(
x
):
res
=
as_scalar
(
x
)
...
...
@@ -194,7 +200,7 @@ def _multi(*fns):
else
:
return
[
f
(
name
)
for
name
in
names
]
if
len
(
fns
)
==
1
:
return
partial
(
f2
,
fns
)
return
partial
(
f2
,
fns
[
0
]
)
else
:
return
[
partial
(
f2
,
f
)
for
f
in
fns
]
...
...
sparse.py
浏览文件 @
f1ff66e0
...
...
@@ -14,6 +14,11 @@ import gof.op, gof.result
import
tensor
""" Types of sparse matrices to use for testing """
_mtypes
=
[
sparse
.
csc_matrix
,
sparse
.
csr_matrix
]
#_mtypes = [sparse.csc_matrix, sparse.csr_matrix, sparse.dok_matrix, sparse.lil_matrix, sparse.coo_matrix]
_mtype_to_str
=
{
sparse
.
csc_matrix
:
"csc"
,
sparse
.
csr_matrix
:
"csr"
}
## Type checking
...
...
tensor.py
浏览文件 @
f1ff66e0
...
...
@@ -304,6 +304,12 @@ s2t.Tensor = Tensor
# alternate Tensor constructor
def
astensor
(
data
,
broadcastable
=
None
,
name
=
None
):
"""Return a L{Tensor} containing given data"""
if
isinstance
(
data
,
Op
):
if
len
(
data
.
outputs
)
!=
1
:
raise
ValueError
(
"It is ambiguous which output of a multi-output Op has to be fetched."
,
data
)
else
:
data
=
data
.
outputs
[
0
]
if
isinstance
(
data
,
Tensor
):
if
broadcastable
is
not
None
and
list
(
data
.
broadcastable
)
!=
list
(
broadcastable
):
raise
TypeError
(
"The data to wrap as a Tensor has the wrong broadcastable pattern. Expected
%
s, got
%
s."
%
(
broadcastable
,
data
.
broadcastable
))
...
...
@@ -315,13 +321,17 @@ def astensor(data, broadcastable=None, name=None):
if
data
is
None
and
broadcastable
is
None
:
raise
TypeError
(
"Cannot make a Tensor out of None."
)
_data
=
data
data
=
numpy
.
asarray
(
data
)
if
broadcastable
is
None
:
broadcastable
=
[
s
==
1
for
s
in
data
.
shape
]
elif
broadcastable
in
[
0
,
1
]:
broadcastable
=
[
broadcastable
]
*
len
(
data
.
shape
)
rval
=
Tensor
(
data
.
dtype
,
broadcastable
,
name
=
name
)
try
:
rval
=
Tensor
(
data
.
dtype
,
broadcastable
,
name
=
name
)
except
TypeError
:
raise
TypeError
(
"Cannot convert
%
s to Tensor."
%
repr
(
_data
))
rval
.
data
=
data
# will raise if broadcastable was mis-specified
return
rval
s2t
.
astensor
=
astensor
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论