Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8055c6b6
提交
8055c6b6
authored
5月 03, 2008
作者:
Joseph Turian
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
13abf473
c4c73a6f
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
49 行增加
和
1 行删除
+49
-1
_test_tensor.py
_test_tensor.py
+27
-0
elemwise.py
elemwise.py
+2
-0
tensor.py
tensor.py
+20
-1
没有找到文件。
_test_tensor.py
浏览文件 @
8055c6b6
...
@@ -1335,7 +1335,34 @@ class t_gemm(unittest.TestCase):
...
@@ -1335,7 +1335,34 @@ class t_gemm(unittest.TestCase):
return
return
self
.
fail
()
self
.
fail
()
class
T_tensorfromscalar
(
unittest
.
TestCase
):
def
test0
(
self
):
s
=
scal
.
constant
(
56
)
t
=
tensor_from_scalar
(
s
)
self
.
failUnless
(
t
.
owner
.
__class__
is
TensorFromScalar
)
self
.
failUnless
(
t
.
broadcastable
==
(),
t
.
broadcastable
)
self
.
failUnless
(
t
.
ndim
==
0
,
t
.
ndim
)
self
.
failUnless
(
t
.
dtype
==
s
.
dtype
)
v
=
eval_outputs
([
t
])
self
.
failUnless
(
v
==
56
,
v
)
self
.
failUnless
(
isinstance
(
v
,
numpy
.
ndarray
))
self
.
failUnless
(
v
.
shape
==
(),
v
.
shape
)
def
test1
(
self
):
s
=
scal
.
constant
(
56
)
t
=
astensor
(
s
)
self
.
failUnless
(
t
.
owner
.
__class__
is
TensorFromScalar
)
self
.
failUnless
(
t
.
broadcastable
==
(),
t
.
broadcastable
)
self
.
failUnless
(
t
.
ndim
==
0
,
t
.
ndim
)
self
.
failUnless
(
t
.
dtype
==
s
.
dtype
)
v
=
eval_outputs
([
t
])
self
.
failUnless
(
v
==
56
,
v
)
self
.
failUnless
(
isinstance
(
v
,
numpy
.
ndarray
))
self
.
failUnless
(
v
.
shape
==
(),
v
.
shape
)
def
_tensor
(
data
,
broadcastable
=
None
,
name
=
None
):
def
_tensor
(
data
,
broadcastable
=
None
,
name
=
None
):
...
...
elemwise.py
浏览文件 @
8055c6b6
...
@@ -10,9 +10,11 @@ from gof.python25 import all
...
@@ -10,9 +10,11 @@ from gof.python25 import all
def
astensor
(
data
):
def
astensor
(
data
):
#This symbol is replaced when we import tensor.py, ask Olivier why.
raise
Exception
(
"Circular dependencies prevent using this here. import tensor before elemwise"
)
raise
Exception
(
"Circular dependencies prevent using this here. import tensor before elemwise"
)
def
Tensor
(
*
inputs
,
**
kwargs
):
def
Tensor
(
*
inputs
,
**
kwargs
):
#This symbol is replaced when we import tensor.py, ask Olivier why.
raise
Exception
(
"Circular dependencies prevent using this here. import tensor before elemwise"
)
raise
Exception
(
"Circular dependencies prevent using this here. import tensor before elemwise"
)
...
...
tensor.py
浏览文件 @
8055c6b6
...
@@ -318,8 +318,11 @@ def astensor(data, broadcastable=None, name=None):
...
@@ -318,8 +318,11 @@ def astensor(data, broadcastable=None, name=None):
if
name
is
not
None
and
name
!=
data
.
name
:
if
name
is
not
None
and
name
!=
data
.
name
:
raise
ValueError
(
"Cannot rename an existing Tensor."
)
raise
ValueError
(
"Cannot rename an existing Tensor."
)
return
data
return
data
elif
isinstance
(
data
,
scal
.
Scalar
):
return
tensor_from_scalar
(
data
)
elif
isinstance
(
data
,
Result
):
elif
isinstance
(
data
,
Result
):
raise
TypeError
(
"Cannot make a Tensor out of a
r
esult that is not an instance of Tensor:
%
s (
%
s)"
%
(
data
,
data
.
__class__
.
__name__
),
data
)
raise
TypeError
(
"Cannot make a Tensor out of a
R
esult that is not an instance of Tensor:
%
s (
%
s)"
%
(
data
,
data
.
__class__
.
__name__
),
data
)
if
data
is
None
and
broadcastable
is
None
:
if
data
is
None
and
broadcastable
is
None
:
raise
TypeError
(
"Cannot make a Tensor out of None."
)
raise
TypeError
(
"Cannot make a Tensor out of None."
)
...
@@ -442,6 +445,21 @@ class _Op(Op):
...
@@ -442,6 +445,21 @@ class _Op(Op):
return
[
rval
.
pop
()]
*
self
.
nout
return
[
rval
.
pop
()]
*
self
.
nout
#########################
# Casting Operations
#########################
class
TensorFromScalar
(
Op
):
def
__init__
(
self
,
s
,
**
kwargs
):
assert
isinstance
(
s
,
scal
.
Scalar
)
Op
.
__init__
(
self
,
**
kwargs
)
self
.
inputs
=
[
s
]
self
.
outputs
=
[
Tensor
(
s
.
dtype
,
broadcastable
=
[])]
def
perform
(
self
):
self
.
outputs
[
0
]
.
data
=
self
.
inputs
[
0
]
.
data
def
grad
(
self
,
(
s
,),
(
dt
,)):
raise
NotImplementedError
(
'todo: ScalarFromTensor'
)
tensor_from_scalar
=
gof
.
op
.
constructor
(
TensorFromScalar
)
##########################
##########################
# Unary Operations
# Unary Operations
...
@@ -797,6 +815,7 @@ def horizontal_stack(x, y, **kwargs):
...
@@ -797,6 +815,7 @@ def horizontal_stack(x, y, **kwargs):
return
transpose
(
vertical_stack
(
x
.
T
,
y
.
T
,
**
kwargs
))
return
transpose
(
vertical_stack
(
x
.
T
,
y
.
T
,
**
kwargs
))
#########################
#########################
# Linalg : Dot
# Linalg : Dot
#########################
#########################
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论