Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
56f487f6
提交
56f487f6
authored
11月 24, 2008
作者:
desjagui@atchoum.iro.umontreal.ca
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Miscellaneous: comments, error message to point people towards using scalar
instead of using Join for scalar values
上级
5a1fd228
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
25 行增加
和
5 行删除
+25
-5
basic.py
theano/tensor/basic.py
+25
-5
没有找到文件。
theano/tensor/basic.py
浏览文件 @
56f487f6
...
@@ -95,7 +95,11 @@ def as_tensor(x, name = None):
...
@@ -95,7 +95,11 @@ def as_tensor(x, name = None):
try
:
try
:
return
constant
(
x
)
return
constant
(
x
)
except
TypeError
:
except
TypeError
:
raise
TypeError
(
"Cannot convert
%
s to Tensor"
%
x
,
type
(
x
))
try
:
str_x
=
str
(
x
)
except
:
str_x
=
repr
(
x
)
raise
TypeError
(
"Cannot convert
%
s to Tensor"
%
str_x
,
type
(
x
))
# this has a different name, because _as_tensor is the function which ops use
# this has a different name, because _as_tensor is the function which ops use
# to upcast their arguments... this internal-use function is a good place to put debugging stuff, better than the global astensor.
# to upcast their arguments... this internal-use function is a good place to put debugging stuff, better than the global astensor.
...
@@ -506,6 +510,8 @@ class _tensor_py_operators:
...
@@ -506,6 +510,8 @@ class _tensor_py_operators:
#TRANSPOSE
#TRANSPOSE
T
=
property
(
lambda
self
:
transpose
(
self
))
T
=
property
(
lambda
self
:
transpose
(
self
))
shape
=
property
(
lambda
self
:
shape
(
self
))
#SLICING
#SLICING
# def __getitem__(self, args): return Subtensor.from_idxs(self,
# def __getitem__(self, args): return Subtensor.from_idxs(self,
# args).outputs[0]
# args).outputs[0]
...
@@ -542,13 +548,19 @@ class _tensor_py_operators:
...
@@ -542,13 +548,19 @@ class _tensor_py_operators:
class
TensorResult
(
Result
,
_tensor_py_operators
):
class
TensorResult
(
Result
,
_tensor_py_operators
):
pass
"""Subclass to add the tensor operators to the basic `Result` class."""
class
TensorConstant
(
Constant
,
_tensor_py_operators
):
class
TensorConstant
(
Constant
,
_tensor_py_operators
):
pass
"""Subclass to add the tensor operators to the basic `Constant` class.
To create a TensorConstant, use the `constant` function in this module.
"""
class
TensorValue
(
Value
,
_tensor_py_operators
):
class
TensorValue
(
Value
,
_tensor_py_operators
):
pass
"""Subclass to add the tensor operators to the basic `Value` class.
To create a TensorValue, use the `value` function in this module.
"""
#QUESTION: why are we doing this!?
#QUESTION: why are we doing this!?
elemwise
.
as_tensor
=
as_tensor
elemwise
.
as_tensor
=
as_tensor
...
@@ -1428,6 +1440,8 @@ class Join(Op):
...
@@ -1428,6 +1440,8 @@ class Join(Op):
Of course, TensorResult instances don't have a shape, so this error can't be caught until
Of course, TensorResult instances don't have a shape, so this error can't be caught until
runtime. See `perform()`.
runtime. See `perform()`.
For joins involving scalar values, see @stack.
.. python::
.. python::
x, y, z = tensor.matrix(), tensor.matrix(), tensor.matrix()
x, y, z = tensor.matrix(), tensor.matrix(), tensor.matrix()
...
@@ -1447,6 +1461,9 @@ class Join(Op):
...
@@ -1447,6 +1461,9 @@ class Join(Op):
as_tensor_args
=
[
as_tensor
(
x
)
for
x
in
tensors
]
as_tensor_args
=
[
as_tensor
(
x
)
for
x
in
tensors
]
dtypes
=
[
x
.
type
.
dtype
for
x
in
as_tensor_args
]
dtypes
=
[
x
.
type
.
dtype
for
x
in
as_tensor_args
]
if
not
all
(
targs
.
type
.
ndim
for
targs
in
as_tensor_args
):
raise
TypeError
(
'Join cannot handle arguments of dimension 0. For joining scalar values, see @stack'
);
if
not
all
([
dtypes
[
0
]
==
dt
for
dt
in
dtypes
[
1
:]]):
if
not
all
([
dtypes
[
0
]
==
dt
for
dt
in
dtypes
[
1
:]]):
# Note that we could automatically find out the appropriate dtype
# Note that we could automatically find out the appropriate dtype
# able to store the concatenation of all tensors, but for now we
# able to store the concatenation of all tensors, but for now we
...
@@ -1468,7 +1485,10 @@ class Join(Op):
...
@@ -1468,7 +1485,10 @@ class Join(Op):
raise
ValueError
(
'Dimensions other than the given axis must'
raise
ValueError
(
'Dimensions other than the given axis must'
' match'
,
tensors
)
' match'
,
tensors
)
bcastable
[:]
=
as_tensor_args
[
0
]
.
type
.
broadcastable
bcastable
[:]
=
as_tensor_args
[
0
]
.
type
.
broadcastable
bcastable
[
axis
]
=
False
try
:
bcastable
[
axis
]
=
False
except
IndexError
,
e
:
raise
ValueError
(
'Join argument "axis" is out of range (given input dimensions)'
)
inputs
=
[
as_tensor
(
axis
)]
+
as_tensor_args
inputs
=
[
as_tensor
(
axis
)]
+
as_tensor_args
if
inputs
[
0
]
.
type
not
in
int_types
:
if
inputs
[
0
]
.
type
not
in
int_types
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论