Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
07ceb6df
提交
07ceb6df
authored
4月 18, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added utility functions to construct Tensors (i|f|)(scalar|vector|matrix|row|col)(s|)
上级
1ddd6c38
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
45 行增加
和
0 行删除
+45
-0
tensor.py
tensor.py
+45
-0
没有找到文件。
tensor.py
浏览文件 @
07ceb6df
...
@@ -14,6 +14,8 @@ import blas # for gemm, dot
...
@@ -14,6 +14,8 @@ import blas # for gemm, dot
import
elemwise
as
s2t
import
elemwise
as
s2t
import
scalar
as
scal
import
scalar
as
scal
from
functools
import
partial
class
Tensor
(
BaseTensor
):
class
Tensor
(
BaseTensor
):
"""
"""
...
@@ -100,6 +102,49 @@ def astensor(data, broadcastable=None, name=None):
...
@@ -100,6 +102,49 @@ def astensor(data, broadcastable=None, name=None):
s2t
.
astensor
=
astensor
s2t
.
astensor
=
astensor
# Easy constructors
def
_multi
(
*
fns
):
def
f2
(
f
,
names
):
if
len
(
names
)
==
1
:
return
f
(
names
)
else
:
return
[
f
(
name
)
for
name
in
names
]
if
len
(
fns
)
==
1
:
return
partial
(
f2
,
fns
)
else
:
return
[
partial
(
f2
,
f
)
for
f
in
fns
]
def
_int_float
(
f
):
return
partial
(
f
,
dtype
=
'int64'
),
partial
(
f
,
dtype
=
'float64'
)
def
scalar
(
name
,
dtype
=
'float64'
):
return
Tensor
(
name
=
name
,
dtype
=
dtype
,
broadcastable
=
())
iscalar
,
fscalar
=
_int_float
(
scalar
)
scalars
,
iscalars
,
fscalars
=
_multi
(
scalar
,
iscalar
,
fscalar
)
def
vector
(
name
,
dtype
=
'float64'
):
return
Tensor
(
name
=
name
,
dtype
=
dtype
,
broadcastable
=
(
False
))
ivector
,
fvector
=
_int_float
(
vector
)
vectors
,
ivectors
,
fvectors
=
_multi
(
vector
,
ivector
,
fvector
)
def
matrix
(
name
,
dtype
=
'float64'
):
return
Tensor
(
name
=
name
,
dtype
=
dtype
,
broadcastable
=
(
False
,
False
))
imatrix
,
fmatrix
=
_int_float
(
matrix
)
matrices
,
imatrices
,
fmatrices
=
_multi
(
matrix
,
imatrix
,
fmatrix
)
def
row
(
name
,
dtype
=
'float64'
):
return
Tensor
(
name
=
name
,
dtype
=
dtype
,
broadcastable
=
(
True
,
False
))
irow
,
frow
=
_int_float
(
row
)
rows
,
irows
,
frows
=
_multi
(
row
,
irow
,
frow
)
def
col
(
name
,
dtype
=
'float64'
):
return
Tensor
(
name
=
name
,
dtype
=
dtype
,
broadcastable
=
(
False
,
True
))
icol
,
fcol
=
_int_float
(
col
)
cols
,
icols
,
fcols
=
_multi
(
col
,
icol
,
fcol
)
############################
############################
# Supporting Ops
# Supporting Ops
############################
############################
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论