Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0e0f4802
提交
0e0f4802
authored
4月 08, 2010
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
ca715940
e404993d
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
76 行增加
和
0 行删除
+76
-0
basic.txt
doc/library/tensor/basic.txt
+38
-0
basic.py
theano/tensor/basic.py
+31
-0
test_basic.py
theano/tensor/tests/test_basic.py
+7
-0
没有找到文件。
doc/library/tensor/basic.txt
浏览文件 @
0e0f4802
...
...
@@ -293,6 +293,7 @@ them perfectly, but a dscalar otherwise.
:rtype: :class:`TensorVariable` or :class:`TensorConstant`
TensorType and TensorVariable
=============================
...
...
@@ -581,6 +582,42 @@ dimensions, see :meth:`_tensor_py_operators.dimshuffle`
have shape (2, 60).
.. function:: zeros_like(x)
:param x: tensor that has same shape as output
Returns a tensor filled with 0s that has same shape as `x`.
.. function:: ones_like(x)
:param x: tensor that has same shape as output
Returns a tensor filled with 1s that has same shape as `x`.
.. function:: fill(a,b)
:param a: tensor that has same shape as output
:param b: theano scalar or value with which you want to fill the output
Create a matrix by filling the shape of `a` with `b`
.. function:: eye(n, m = None, k = 0, dtype='float64')
:param n: number of rows in output (value or theano scalar)
:param m: number of columns in output (value or theano scalar)
:param k: Index of the diagonal: 0 refers to the main diagonal,
a positive value refers to an upper diagonal, and a
negative value to a lower diagonal. It can be a theano
scalar.
:returns: An array where all elements are equal to zero, except for the `k`-th
diagonal, whose values are equal to one.
.. function:: identity_like(x)
:param x: tensor
:returns: A tensor of same shape as `x` that is filled with 0s everywhere
except for the main diagonal, whose values are equal to one. The output
will have same dtype as `x`.
Reductions
==========
...
...
@@ -743,6 +780,7 @@ Casting
Return the imaginary components of Tensor x.
For non-complex `x` this function returns zeros_like(x).
Comparisons
------------
...
...
theano/tensor/basic.py
浏览文件 @
0e0f4802
...
...
@@ -1702,6 +1702,37 @@ def zeros_like(model):
#return Zeros(model.type.ndim)(shape(model))
return
fill
(
model
,
constant
(
0.0
,
dtype
=
model
.
type
.
dtype
))
class
Eye
(
gof
.
Op
):
def
__init__
(
self
,
dtype
=
'float64'
):
self
.
dtype
=
dtype
def
make_node
(
self
,
n
,
m
,
k
):
n
=
as_tensor_variable
(
n
)
m
=
as_tensor_variable
(
m
)
k
=
as_tensor_variable
(
k
)
return
gof
.
Apply
(
self
,
[
n
,
m
,
k
],
[
TensorType
(
dtype
=
self
.
dtype
,
broadcastable
=
(
False
,
False
))()])
def
perform
(
self
,
node
,
(
n
,
m
,
k
),
(
out
,)):
out
[
0
]
=
numpy
.
eye
(
n
,
m
,
k
)
def
grad
(
self
,
(
n
,
m
,
k
),(
gout
,)):
return
[
None
,
None
,
None
]
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
self
.
dtype
==
other
.
dtype
def
__hash__
(
self
):
return
hash
(
self
.
dtype
)
^
hash
(
type
(
self
))
def
eye
(
n
,
m
=
None
,
k
=
0
,
dtype
=
'float64'
):
if
m
==
None
:
m
=
n
localop
=
Eye
(
dtype
)
return
localop
(
n
,
m
,
k
)
def
identity_like
(
x
):
return
eye
(
x
.
shape
[
0
],
x
.
shape
[
1
],
k
=
0
,
dtype
=
x
.
dtype
)
if
0
:
## COMMENTED OUT FEB 17 2010
## TODO (DOCUMENT AND WRITE TESTS) OR DELETE
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
0e0f4802
...
...
@@ -1143,6 +1143,13 @@ class test_bitwise(unittest.TestCase):
v
=
fn
(
l
,
r
)
self
.
failUnless
(
numpy
.
all
(
v
==
(
~
l
)),
(
l
,
r
,
v
))
def
test_eye
(
self
):
n
=
iscalar
()
m
=
iscalar
()
k
=
iscalar
()
fn
=
theano
.
function
([
m
,
n
,
k
],
eye
(
m
,
n
,
k
)
)
self
.
failUnless
(
numpy
.
all
(
fn
(
5
,
6
,
1
)
==
numpy
.
eye
(
5
,
6
,
1
)))
class
T_add
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论