Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1704f22a
提交
1704f22a
authored
5月 09, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
5月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Misc. refactoring in aesara.tensor.basic
上级
6cca25e3
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
9 行增加
和
40 行删除
+9
-40
basic.py
aesara/tensor/basic.py
+7
-38
var.py
aesara/tensor/var.py
+2
-2
没有找到文件。
aesara/tensor/basic.py
浏览文件 @
1704f22a
...
...
@@ -6,7 +6,6 @@ manipulation of tensors.
"""
import
builtins
import
logging
import
warnings
from
collections.abc
import
Sequence
from
functools
import
partial
...
...
@@ -65,11 +64,6 @@ from aesara.tensor.type import (
from
aesara.tensor.var
import
TensorConstant
,
TensorVariable
,
get_unique_value
_logger
=
logging
.
getLogger
(
"aesara.tensor.basic"
)
__docformat__
=
"restructuredtext en"
def
__oplist_tag
(
thing
,
tag
):
tags
=
getattr
(
thing
,
"__oplist_tags"
,
[])
tags
.
append
(
tag
)
...
...
@@ -900,24 +894,14 @@ def cast(x, dtype: Union[str, np.dtype]) -> TensorVariable:
return
_cast_mapping
[
dtype_name
](
x
)
##########################
# Condition
##########################
@scalar_elemwise
def
switch
(
cond
,
ift
,
iff
):
"""if cond then ift else iff"""
where
=
switch
##########################
# Misc
##########################
# fill, _fill_inplace = _elemwise(aes.second, 'fill',
# """fill WRITEME (elemwise)""")
@scalar_elemwise
def
second
(
a
,
b
):
"""Create a matrix by filling the shape of a with b"""
...
...
@@ -1899,11 +1883,6 @@ class Default(Op):
default
=
Default
()
##########################
# View Operations
##########################
def
extract_constant
(
x
,
elemwise
=
True
,
only_process_constants
=
False
):
"""
This function is basically a call to tensor.get_scalar_constant_value.
...
...
@@ -2783,16 +2762,11 @@ def stack(*tensors, **kwargs):
# And DebugMode can't detect error in this code as it is not in an
# optimization.
# See ticket #660
if
np
.
all
(
[
# in case there is direct int in tensors.
isinstance
(
t
,
(
np
.
number
,
float
,
int
,
builtins
.
complex
))
or
(
isinstance
(
t
,
Variable
)
and
isinstance
(
t
.
type
,
TensorType
)
and
t
.
ndim
==
0
)
for
t
in
tensors
]
if
all
(
# In case there are explicit ints in tensors
isinstance
(
t
,
(
np
.
number
,
float
,
int
,
builtins
.
complex
))
or
(
isinstance
(
t
,
Variable
)
and
isinstance
(
t
.
type
,
TensorType
)
and
t
.
ndim
==
0
)
for
t
in
tensors
):
# in case there is direct int
tensors
=
list
(
map
(
as_tensor_variable
,
tensors
))
...
...
@@ -4036,7 +4010,7 @@ def swapaxes(y, axis1, axis2):
return
y
.
dimshuffle
(
li
)
def
choose
(
a
,
choices
,
out
=
None
,
mode
=
"raise"
):
def
choose
(
a
,
choices
,
mode
=
"raise"
):
"""
Construct an array from an index array and a set of arrays to choose from.
...
...
@@ -4080,9 +4054,6 @@ def choose(a, choices, out=None, mode="raise"):
the same shape. If choices is itself an array (not recommended),
then its outermost dimension (i.e., the one corresponding to
choices.shape[0]) is taken as defining the ``sequence``.
out : array, optional
If provided, the result will be inserted into this array.
It should be of the appropriate shape and dtype.
mode : {``raise`` (default), ``wrap``, ``clip``}, optional
Specifies how indices outside [0, n-1] will be treated:
``raise`` : an exception is raised
...
...
@@ -4100,8 +4071,6 @@ def choose(a, choices, out=None, mode="raise"):
If a and each choice array are not all broadcastable to the same shape.
"""
# This is done to keep the same function signature then NumPy.
assert
out
is
None
return
Choose
(
mode
)(
a
,
choices
)
...
...
@@ -4365,9 +4334,9 @@ def expand_dims(
def
_make_along_axis_idx
(
arr_shape
,
indices
,
axis
):
"""Take from `numpy.lib.shape_base`."""
# compute dimensions to iterate over
if
str
(
indices
.
dtype
)
not
in
int_dtypes
:
raise
IndexError
(
"`indices` must be an integer array"
)
shape_ones
=
(
1
,)
*
indices
.
ndim
dest_dims
=
list
(
range
(
axis
))
+
[
None
]
+
list
(
range
(
axis
+
1
,
indices
.
ndim
))
...
...
aesara/tensor/var.py
浏览文件 @
1704f22a
...
...
@@ -788,13 +788,13 @@ class _tensor_py_operators:
"""Fill inputted tensor with the assigned value."""
return
at
.
basic
.
fill
(
self
,
value
)
def
choose
(
self
,
choices
,
out
=
None
,
mode
=
"raise"
):
def
choose
(
self
,
choices
,
mode
=
"raise"
):
"""
Construct an array from an index array and a set of arrays to choose
from.
"""
return
at
.
basic
.
choose
(
self
,
choices
,
out
=
None
,
mode
=
"raise"
)
return
at
.
basic
.
choose
(
self
,
choices
,
mode
=
"raise"
)
def
squeeze
(
self
):
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论