Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
470b9d60
提交
470b9d60
authored
3月 19, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
3月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename Scalar to ScalarType
上级
9136eb66
隐藏空白字符变更
内嵌
并排
正在显示
31 个修改的文件
包含
135 行增加
和
142 行删除
+135
-142
dnn.py
aesara/gpuarray/dnn.py
+1
-1
elemwise.py
aesara/gpuarray/elemwise.py
+7
-7
opt.py
aesara/gpuarray/opt.py
+3
-3
basic.py
aesara/link/c/basic.py
+2
-2
params_type.py
aesara/link/c/params_type.py
+13
-13
basic.py
aesara/link/numba/dispatch/basic.py
+2
-2
multinomial.py
aesara/sandbox/multinomial.py
+3
-3
basic.py
aesara/scalar/basic.py
+43
-37
sharedvar.py
aesara/scalar/sharedvar.py
+2
-6
utils.py
aesara/scan/utils.py
+1
-1
__init__.py
aesara/tensor/__init__.py
+1
-1
basic.py
aesara/tensor/basic.py
+2
-2
elemwise.py
aesara/tensor/elemwise.py
+2
-2
abstract_conv.py
aesara/tensor/nnet/abstract_conv.py
+3
-3
basic.py
aesara/tensor/nnet/basic.py
+4
-3
batchnorm.py
aesara/tensor/nnet/batchnorm.py
+5
-5
sigm.py
aesara/tensor/nnet/sigm.py
+1
-1
subtensor.py
aesara/tensor/subtensor.py
+3
-3
subtensor_opt.py
aesara/tensor/subtensor_opt.py
+3
-3
ctype.rst
doc/extending/ctype.rst
+1
-1
other_ops.rst
doc/extending/other_ops.rst
+1
-1
how_to_make_ops.rst
doc/sandbox/how_to_make_ops.rst
+4
-4
test_unify.py
tests/graph/test_unify.py
+3
-3
test_quadratic_function.c
tests/link/c/c_code/test_quadratic_function.c
+1
-1
test_params_type.py
tests/link/c/test_params_type.py
+6
-6
test_basic.py
tests/scalar/test_basic.py
+3
-13
test_type.py
tests/scalar/test_type.py
+6
-6
test_basic.py
tests/tensor/test_basic.py
+1
-1
test_basic_opt.py
tests/tensor/test_basic_opt.py
+6
-6
test_math.py
tests/tensor/test_math.py
+1
-1
test_subtensor.py
tests/tensor/test_subtensor.py
+1
-1
没有找到文件。
aesara/gpuarray/dnn.py
浏览文件 @
470b9d60
...
@@ -717,7 +717,7 @@ def ensure_dt(val, default, name, dtype):
...
@@ -717,7 +717,7 @@ def ensure_dt(val, default, name, dtype):
val
=
constant
(
val
)
val
=
constant
(
val
)
if
hasattr
(
val
,
"ndim"
)
and
val
.
ndim
==
0
:
if
hasattr
(
val
,
"ndim"
)
and
val
.
ndim
==
0
:
val
=
as_scalar
(
val
)
val
=
as_scalar
(
val
)
if
not
isinstance
(
val
.
type
,
aesara
.
scalar
.
Scalar
):
if
not
isinstance
(
val
.
type
,
aesara
.
scalar
.
Scalar
Type
):
raise
TypeError
(
f
"{name}: expected a scalar value"
)
raise
TypeError
(
f
"{name}: expected a scalar value"
)
if
val
.
type
.
dtype
!=
dtype
:
if
val
.
type
.
dtype
!=
dtype
:
val
=
val
.
astype
(
dtype
)
val
=
val
.
astype
(
dtype
)
...
...
aesara/gpuarray/elemwise.py
浏览文件 @
470b9d60
...
@@ -8,7 +8,7 @@ from aesara.graph.basic import Apply
...
@@ -8,7 +8,7 @@ from aesara.graph.basic import Apply
from
aesara.graph.op
import
_NoPythonOp
from
aesara.graph.op
import
_NoPythonOp
from
aesara.graph.utils
import
MethodNotDefined
from
aesara.graph.utils
import
MethodNotDefined
from
aesara.link.c.interface
import
HideC
from
aesara.link.c.interface
import
HideC
from
aesara.scalar
import
Composite
,
Scalar
from
aesara.scalar
import
Composite
,
Scalar
Type
from
aesara.scalar.basic
import
complex_types
,
upgrade_to_float_no_complex
from
aesara.scalar.basic
import
complex_types
,
upgrade_to_float_no_complex
from
aesara.scalar.math
import
Erfcinv
,
Erfinv
from
aesara.scalar.math
import
Erfcinv
,
Erfinv
from
aesara.tensor.elemwise
import
CAReduceDtype
,
DimShuffle
,
Elemwise
from
aesara.tensor.elemwise
import
CAReduceDtype
,
DimShuffle
,
Elemwise
...
@@ -1083,7 +1083,7 @@ class GpuCAReduceCuda(GpuKernelBase, HideC, CAReduceDtype, _NoPythonOp):
...
@@ -1083,7 +1083,7 @@ class GpuCAReduceCuda(GpuKernelBase, HideC, CAReduceDtype, _NoPythonOp):
if
self
.
pre_scalar_op
:
# TODO: multiple dtypes
if
self
.
pre_scalar_op
:
# TODO: multiple dtypes
# dtype = node.inputs[0].dtype
# dtype = node.inputs[0].dtype
dummy_var
=
aes
.
Scalar
(
dtype
=
dtype
)()
dummy_var
=
aes
.
Scalar
Type
(
dtype
=
dtype
)()
dummy_node
=
self
.
pre_scalar_op
.
make_node
(
dummy_var
)
dummy_node
=
self
.
pre_scalar_op
.
make_node
(
dummy_var
)
...
@@ -1128,8 +1128,8 @@ class GpuCAReduceCuda(GpuKernelBase, HideC, CAReduceDtype, _NoPythonOp):
...
@@ -1128,8 +1128,8 @@ class GpuCAReduceCuda(GpuKernelBase, HideC, CAReduceDtype, _NoPythonOp):
in_dtype
=
x
.
dtype
in_dtype
=
x
.
dtype
out_dtype
=
node
.
outputs
[
0
]
.
dtype
out_dtype
=
node
.
outputs
[
0
]
.
dtype
dummy_left
=
Scalar
(
dtype
=
out_dtype
)()
dummy_left
=
Scalar
Type
(
dtype
=
out_dtype
)()
dummy_right
=
Scalar
(
dtype
=
in_dtype
)()
dummy_right
=
Scalar
Type
(
dtype
=
in_dtype
)()
dummy_node
=
self
.
scalar_op
.
make_node
(
dummy_left
,
dummy_right
)
dummy_node
=
self
.
scalar_op
.
make_node
(
dummy_left
,
dummy_right
)
...
@@ -1955,12 +1955,12 @@ class GpuCAReduceCuda(GpuKernelBase, HideC, CAReduceDtype, _NoPythonOp):
...
@@ -1955,12 +1955,12 @@ class GpuCAReduceCuda(GpuKernelBase, HideC, CAReduceDtype, _NoPythonOp):
# now we insert versions for the ops on which we depend...
# now we insert versions for the ops on which we depend...
scalar_node
=
Apply
(
scalar_node
=
Apply
(
self
.
scalar_op
,
self
.
scalar_op
,
[
Scalar
(
dtype
=
input
.
type
.
dtype
)()
for
input
in
node
.
inputs
],
[
Scalar
Type
(
dtype
=
input
.
type
.
dtype
)()
for
input
in
node
.
inputs
],
[
Scalar
(
dtype
=
output
.
type
.
dtype
)()
for
output
in
node
.
outputs
],
[
Scalar
Type
(
dtype
=
output
.
type
.
dtype
)()
for
output
in
node
.
outputs
],
)
)
version
.
extend
(
self
.
scalar_op
.
c_code_cache_version_apply
(
scalar_node
))
version
.
extend
(
self
.
scalar_op
.
c_code_cache_version_apply
(
scalar_node
))
for
i
in
node
.
inputs
+
node
.
outputs
:
for
i
in
node
.
inputs
+
node
.
outputs
:
version
.
extend
(
Scalar
(
dtype
=
i
.
type
.
dtype
)
.
c_code_cache_version
())
version
.
extend
(
Scalar
Type
(
dtype
=
i
.
type
.
dtype
)
.
c_code_cache_version
())
version
.
extend
(
self
.
kernel_version
(
node
))
version
.
extend
(
self
.
kernel_version
(
node
))
if
all
(
version
):
if
all
(
version
):
return
tuple
(
version
)
return
tuple
(
version
)
...
...
aesara/gpuarray/opt.py
浏览文件 @
470b9d60
...
@@ -161,7 +161,7 @@ from aesara.ifelse import IfElse
...
@@ -161,7 +161,7 @@ from aesara.ifelse import IfElse
from
aesara.link.c.basic
import
CLinker
from
aesara.link.c.basic
import
CLinker
from
aesara.misc.ordered_set
import
OrderedSet
from
aesara.misc.ordered_set
import
OrderedSet
from
aesara.raise_op
import
Assert
from
aesara.raise_op
import
Assert
from
aesara.scalar.basic
import
Cast
,
Pow
,
Scalar
,
log
,
neg
,
true_div
from
aesara.scalar.basic
import
Cast
,
Pow
,
Scalar
Type
,
log
,
neg
,
true_div
from
aesara.scalar.math
import
Erfcinv
,
Erfinv
from
aesara.scalar.math
import
Erfcinv
,
Erfinv
from
aesara.scan.op
import
Scan
from
aesara.scan.op
import
Scan
from
aesara.scan.opt
import
ScanInplaceOptimizer
from
aesara.scan.opt
import
ScanInplaceOptimizer
...
@@ -811,7 +811,7 @@ def local_gpua_elemwise(fgraph, op, context_name, inputs, outputs):
...
@@ -811,7 +811,7 @@ def local_gpua_elemwise(fgraph, op, context_name, inputs, outputs):
new_inputs
=
[]
new_inputs
=
[]
for
inp
in
inputs
:
for
inp
in
inputs
:
if
inp
.
dtype
!=
out_dtype
:
if
inp
.
dtype
!=
out_dtype
:
gpu_cast_op
=
GpuElemwise
(
Cast
(
Scalar
(
out_dtype
)))
gpu_cast_op
=
GpuElemwise
(
Cast
(
Scalar
Type
(
out_dtype
)))
new_inputs
.
append
(
gpu_cast_op
(
as_gpuarray_variable
(
inp
,
context_name
)))
new_inputs
.
append
(
gpu_cast_op
(
as_gpuarray_variable
(
inp
,
context_name
)))
else
:
else
:
new_inputs
.
append
(
as_gpuarray_variable
(
inp
,
context_name
))
new_inputs
.
append
(
as_gpuarray_variable
(
inp
,
context_name
))
...
@@ -1387,7 +1387,7 @@ def local_gpua_gemmbatch(fgraph, op, context_name, inputs, outputs):
...
@@ -1387,7 +1387,7 @@ def local_gpua_gemmbatch(fgraph, op, context_name, inputs, outputs):
# In case of mismatched dtypes, we also have to upcast
# In case of mismatched dtypes, we also have to upcast
out_dtype
=
outputs
[
0
]
.
dtype
out_dtype
=
outputs
[
0
]
.
dtype
if
a
.
dtype
!=
out_dtype
or
b
.
dtype
!=
out_dtype
:
if
a
.
dtype
!=
out_dtype
or
b
.
dtype
!=
out_dtype
:
gpu_cast_op
=
GpuElemwise
(
Cast
(
Scalar
(
out_dtype
)))
gpu_cast_op
=
GpuElemwise
(
Cast
(
Scalar
Type
(
out_dtype
)))
if
a
.
dtype
!=
out_dtype
:
if
a
.
dtype
!=
out_dtype
:
a
=
gpu_cast_op
(
a
)
a
=
gpu_cast_op
(
a
)
if
b
.
dtype
!=
out_dtype
:
if
b
.
dtype
!=
out_dtype
:
...
...
aesara/link/c/basic.py
浏览文件 @
470b9d60
...
@@ -649,9 +649,9 @@ class CLinker(Linker):
...
@@ -649,9 +649,9 @@ class CLinker(Linker):
for
r
in
self
.
variables
for
r
in
self
.
variables
if
isinstance
(
r
,
Constant
)
and
r
not
in
self
.
inputs
if
isinstance
(
r
,
Constant
)
and
r
not
in
self
.
inputs
)
)
# C type constants (aesara.scalar.Scalar). They don't request an object
# C type constants (aesara.scalar.Scalar
Type
). They don't request an object
self
.
consts
=
[]
self
.
consts
=
[]
# Move c type from orphans (aesara.scalar.Scalar) to self.consts
# Move c type from orphans (aesara.scalar.Scalar
Type
) to self.consts
for
variable
in
self
.
orphans
:
for
variable
in
self
.
orphans
:
if
(
if
(
isinstance
(
variable
,
Constant
)
isinstance
(
variable
,
Constant
)
...
...
aesara/link/c/params_type.py
浏览文件 @
470b9d60
...
@@ -7,7 +7,7 @@ used to create a Params object that is compatible with the ParamsType defined.
...
@@ -7,7 +7,7 @@ used to create a Params object that is compatible with the ParamsType defined.
The Params object will be available in both Python code (as a standard Python object) and C code
The Params object will be available in both Python code (as a standard Python object) and C code
(as a specific struct with parameters as struct fields). To be fully-available in C code, Aesara
(as a specific struct with parameters as struct fields). To be fully-available in C code, Aesara
types wrapped into a ParamsType must provide a C interface (e.g. TensorType, Scalar, GpuArrayType,
types wrapped into a ParamsType must provide a C interface (e.g. TensorType, Scalar
Type
, GpuArrayType,
or your own type. See :ref:`extending_op_params` for more details).
or your own type. See :ref:`extending_op_params` for more details).
Example of usage
Example of usage
...
@@ -23,13 +23,13 @@ Importation:
...
@@ -23,13 +23,13 @@ Importation:
# If you want to use a tensor and a scalar as parameters,
# If you want to use a tensor and a scalar as parameters,
# you should import required Aesara types.
# you should import required Aesara types.
from aesara.tensor.type import TensorType
from aesara.tensor.type import TensorType
from aesara.scalar import Scalar
from aesara.scalar import Scalar
Type
In your Op sub-class:
In your Op sub-class:
.. code-block:: python
.. code-block:: python
params_type = ParamsType(attr1=TensorType('int32', (False, False)), attr2=Scalar('float64'))
params_type = ParamsType(attr1=TensorType('int32', (False, False)), attr2=Scalar
Type
('float64'))
If your op contains attributes ``attr1`` **and** ``attr2``, the default ``op.get_params()``
If your op contains attributes ``attr1`` **and** ``attr2``, the default ``op.get_params()``
implementation will automatically try to look for it and generate an appropriate Params object.
implementation will automatically try to look for it and generate an appropriate Params object.
...
@@ -236,11 +236,11 @@ class Params(dict):
...
@@ -236,11 +236,11 @@ class Params(dict):
.. code-block:: python
.. code-block:: python
from aesara.link.c.params_type import ParamsType, Params
from aesara.link.c.params_type import ParamsType, Params
from aesara.scalar import Scalar
from aesara.scalar import Scalar
Type
# You must create a ParamsType first:
# You must create a ParamsType first:
params_type = ParamsType(attr1=Scalar('int32'),
params_type = ParamsType(attr1=Scalar
Type
('int32'),
key2=Scalar('float32'),
key2=Scalar
Type
('float32'),
field3=Scalar('int64'))
field3=Scalar
Type
('int64'))
# Then you can create a Params object with
# Then you can create a Params object with
# the params type defined above and values for attributes.
# the params type defined above and values for attributes.
params = Params(params_type, attr1=1, key2=2.0, field3=3)
params = Params(params_type, attr1=1, key2=2.0, field3=3)
...
@@ -498,9 +498,9 @@ class ParamsType(CType):
...
@@ -498,9 +498,9 @@ class ParamsType(CType):
from aesara.graph.params_type import ParamsType
from aesara.graph.params_type import ParamsType
from aesara.link.c.type import EnumType, EnumList
from aesara.link.c.type import EnumType, EnumList
from aesara.scalar import Scalar
from aesara.scalar import Scalar
Type
wrapper = ParamsType(scalar=Scalar('int32'),
wrapper = ParamsType(scalar=Scalar
Type
('int32'),
letters=EnumType(A=1, B=2, C=3),
letters=EnumType(A=1, B=2, C=3),
digits=EnumList('ZERO', 'ONE', 'TWO'))
digits=EnumList('ZERO', 'ONE', 'TWO'))
print(wrapper.get_enum('C')) # 3
print(wrapper.get_enum('C')) # 3
...
@@ -527,9 +527,9 @@ class ParamsType(CType):
...
@@ -527,9 +527,9 @@ class ParamsType(CType):
from aesara.graph.params_type import ParamsType
from aesara.graph.params_type import ParamsType
from aesara.link.c.type import EnumType, EnumList
from aesara.link.c.type import EnumType, EnumList
from aesara.scalar import Scalar
from aesara.scalar import Scalar
Type
wrapper = ParamsType(scalar=Scalar('int32'),
wrapper = ParamsType(scalar=Scalar
Type
('int32'),
letters=EnumType(A=(1, 'alpha'), B=(2, 'beta'), C=3),
letters=EnumType(A=(1, 'alpha'), B=(2, 'beta'), C=3),
digits=EnumList(('ZERO', 'nothing'), ('ONE', 'unit'), ('TWO', 'couple')))
digits=EnumList(('ZERO', 'nothing'), ('ONE', 'unit'), ('TWO', 'couple')))
print(wrapper.get_enum('C')) # 3
print(wrapper.get_enum('C')) # 3
...
@@ -574,14 +574,14 @@ class ParamsType(CType):
...
@@ -574,14 +574,14 @@ class ParamsType(CType):
import numpy
import numpy
from aesara.graph.params_type import ParamsType
from aesara.graph.params_type import ParamsType
from aesara.tensor.type import dmatrix
from aesara.tensor.type import dmatrix
from aesara.scalar import Scalar
from aesara.scalar import Scalar
Type
class MyObject:
class MyObject:
def __init__(self):
def __init__(self):
self.a = 10
self.a = 10
self.b = numpy.asarray([[1, 2, 3], [4, 5, 6]])
self.b = numpy.asarray([[1, 2, 3], [4, 5, 6]])
params_type = ParamsType(a=Scalar
('int32'), b=dmatrix, c=Scalar
('bool'))
params_type = ParamsType(a=Scalar
Type('int32'), b=dmatrix, c=ScalarType
('bool'))
o = MyObject()
o = MyObject()
value_for_c = False
value_for_c = False
...
...
aesara/link/numba/dispatch/basic.py
浏览文件 @
470b9d60
...
@@ -25,7 +25,7 @@ from aesara.link.utils import (
...
@@ -25,7 +25,7 @@ from aesara.link.utils import (
fgraph_to_python
,
fgraph_to_python
,
unique_name_generator
,
unique_name_generator
,
)
)
from
aesara.scalar.basic
import
Scalar
from
aesara.scalar.basic
import
Scalar
Type
from
aesara.scalar.math
import
Softplus
from
aesara.scalar.math
import
Softplus
from
aesara.tensor.blas
import
BatchedDot
from
aesara.tensor.blas
import
BatchedDot
from
aesara.tensor.math
import
Dot
from
aesara.tensor.math
import
Dot
...
@@ -86,7 +86,7 @@ def get_numba_type(
...
@@ -86,7 +86,7 @@ def get_numba_type(
):
):
return
numba_dtype
return
numba_dtype
return
numba
.
types
.
Array
(
numba_dtype
,
aesara_type
.
ndim
,
layout
)
return
numba
.
types
.
Array
(
numba_dtype
,
aesara_type
.
ndim
,
layout
)
elif
isinstance
(
aesara_type
,
Scalar
):
elif
isinstance
(
aesara_type
,
Scalar
Type
):
dtype
=
np
.
dtype
(
aesara_type
.
dtype
)
dtype
=
np
.
dtype
(
aesara_type
.
dtype
)
numba_dtype
=
numba
.
from_dtype
(
dtype
)
numba_dtype
=
numba
.
from_dtype
(
dtype
)
return
numba_dtype
return
numba_dtype
...
...
aesara/sandbox/multinomial.py
浏览文件 @
470b9d60
...
@@ -8,7 +8,7 @@ import aesara.tensor as at
...
@@ -8,7 +8,7 @@ import aesara.tensor as at
from
aesara.configdefaults
import
config
from
aesara.configdefaults
import
config
from
aesara.graph.basic
import
Apply
from
aesara.graph.basic
import
Apply
from
aesara.link.c.op
import
COp
from
aesara.link.c.op
import
COp
from
aesara.scalar
import
Scalar
,
as_scalar
from
aesara.scalar
import
Scalar
Type
,
as_scalar
from
aesara.tensor.type
import
discrete_dtypes
from
aesara.tensor.type
import
discrete_dtypes
...
@@ -72,7 +72,7 @@ class MultinomialFromUniform(COp):
...
@@ -72,7 +72,7 @@ class MultinomialFromUniform(COp):
if
self
.
odtype
==
"auto"
:
if
self
.
odtype
==
"auto"
:
t
=
f
"PyArray_TYPE({pvals})"
t
=
f
"PyArray_TYPE({pvals})"
else
:
else
:
t
=
Scalar
(
self
.
odtype
)
.
dtype_specs
()[
1
]
t
=
Scalar
Type
(
self
.
odtype
)
.
dtype_specs
()[
1
]
if
t
.
startswith
(
"aesara_complex"
):
if
t
.
startswith
(
"aesara_complex"
):
t
=
t
.
replace
(
"aesara_complex"
,
"NPY_COMPLEX"
)
t
=
t
.
replace
(
"aesara_complex"
,
"NPY_COMPLEX"
)
else
:
else
:
...
@@ -264,7 +264,7 @@ class ChoiceFromUniform(MultinomialFromUniform):
...
@@ -264,7 +264,7 @@ class ChoiceFromUniform(MultinomialFromUniform):
if
self
.
odtype
==
"auto"
:
if
self
.
odtype
==
"auto"
:
t
=
"NPY_INT64"
t
=
"NPY_INT64"
else
:
else
:
t
=
Scalar
(
self
.
odtype
)
.
dtype_specs
()[
1
]
t
=
Scalar
Type
(
self
.
odtype
)
.
dtype_specs
()[
1
]
if
t
.
startswith
(
"aesara_complex"
):
if
t
.
startswith
(
"aesara_complex"
):
t
=
t
.
replace
(
"aesara_complex"
,
"NPY_COMPLEX"
)
t
=
t
.
replace
(
"aesara_complex"
,
"NPY_COMPLEX"
)
else
:
else
:
...
...
aesara/scalar/basic.py
浏览文件 @
470b9d60
...
@@ -102,7 +102,7 @@ def upcast(dtype, *dtypes):
...
@@ -102,7 +102,7 @@ def upcast(dtype, *dtypes):
def
as_common_dtype
(
*
vars
):
def
as_common_dtype
(
*
vars
):
"""
"""
For for aesara.scalar.Scalar and TensorVariable.
For for aesara.scalar.Scalar
Type
and TensorVariable.
"""
"""
dtype
=
upcast
(
*
[
v
.
dtype
for
v
in
vars
])
dtype
=
upcast
(
*
[
v
.
dtype
for
v
in
vars
])
return
(
v
.
astype
(
dtype
)
for
v
in
vars
)
return
(
v
.
astype
(
dtype
)
for
v
in
vars
)
...
@@ -275,7 +275,7 @@ def convert(x, dtype=None):
...
@@ -275,7 +275,7 @@ def convert(x, dtype=None):
return
x_
return
x_
class
Scalar
(
CType
,
HasDataType
):
class
Scalar
Type
(
CType
,
HasDataType
):
"""
"""
Internal class, should not be used by clients.
Internal class, should not be used by clients.
...
@@ -356,7 +356,7 @@ class Scalar(CType, HasDataType):
...
@@ -356,7 +356,7 @@ class Scalar(CType, HasDataType):
def
c_headers
(
self
,
c_compiler
=
None
,
**
kwargs
):
def
c_headers
(
self
,
c_compiler
=
None
,
**
kwargs
):
l
=
[
"<math.h>"
]
l
=
[
"<math.h>"
]
# These includes are needed by Scalar and TensorType,
# These includes are needed by Scalar
Type
and TensorType,
# we declare them here and they will be re-used by TensorType
# we declare them here and they will be re-used by TensorType
l
.
append
(
"<numpy/arrayobject.h>"
)
l
.
append
(
"<numpy/arrayobject.h>"
)
l
.
append
(
"<numpy/arrayscalars.h>"
)
l
.
append
(
"<numpy/arrayscalars.h>"
)
...
@@ -428,7 +428,7 @@ class Scalar(CType, HasDataType):
...
@@ -428,7 +428,7 @@ class Scalar(CType, HasDataType):
return
str
(
self
.
dtype
)
return
str
(
self
.
dtype
)
def
__repr__
(
self
):
def
__repr__
(
self
):
return
f
"Scalar({self.dtype})"
return
f
"Scalar
Type
({self.dtype})"
def
c_literal
(
self
,
data
):
def
c_literal
(
self
,
data
):
if
"complex"
in
self
.
dtype
:
if
"complex"
in
self
.
dtype
:
...
@@ -677,15 +677,19 @@ class Scalar(CType, HasDataType):
...
@@ -677,15 +677,19 @@ class Scalar(CType, HasDataType):
return
shape_info
return
shape_info
def
get_scalar_type
(
dtype
)
->
Scalar
:
# Deprecated alias for backward compatibility
Scalar
=
ScalarType
def
get_scalar_type
(
dtype
)
->
ScalarType
:
"""
"""
Return a Scalar(dtype) object.
Return a Scalar
Type
(dtype) object.
This caches objects to save allocation and run time.
This caches objects to save allocation and run time.
"""
"""
if
dtype
not
in
get_scalar_type
.
cache
:
if
dtype
not
in
get_scalar_type
.
cache
:
get_scalar_type
.
cache
[
dtype
]
=
Scalar
(
dtype
=
dtype
)
get_scalar_type
.
cache
[
dtype
]
=
Scalar
Type
(
dtype
=
dtype
)
return
get_scalar_type
.
cache
[
dtype
]
return
get_scalar_type
.
cache
[
dtype
]
...
@@ -694,7 +698,7 @@ get_scalar_type.cache = {}
...
@@ -694,7 +698,7 @@ get_scalar_type.cache = {}
# Register C code for ViewOp on Scalars.
# Register C code for ViewOp on Scalars.
aesara
.
compile
.
register_view_op_c_code
(
aesara
.
compile
.
register_view_op_c_code
(
Scalar
,
Scalar
Type
,
"""
"""
%(oname)
s =
%(iname)
s;
%(oname)
s =
%(iname)
s;
"""
,
"""
,
...
@@ -702,22 +706,22 @@ aesara.compile.register_view_op_c_code(
...
@@ -702,22 +706,22 @@ aesara.compile.register_view_op_c_code(
)
)
bool
:
Scalar
=
get_scalar_type
(
"bool"
)
bool
:
Scalar
Type
=
get_scalar_type
(
"bool"
)
int8
:
Scalar
=
get_scalar_type
(
"int8"
)
int8
:
Scalar
Type
=
get_scalar_type
(
"int8"
)
int16
:
Scalar
=
get_scalar_type
(
"int16"
)
int16
:
Scalar
Type
=
get_scalar_type
(
"int16"
)
int32
:
Scalar
=
get_scalar_type
(
"int32"
)
int32
:
Scalar
Type
=
get_scalar_type
(
"int32"
)
int64
:
Scalar
=
get_scalar_type
(
"int64"
)
int64
:
Scalar
Type
=
get_scalar_type
(
"int64"
)
uint8
:
Scalar
=
get_scalar_type
(
"uint8"
)
uint8
:
Scalar
Type
=
get_scalar_type
(
"uint8"
)
uint16
:
Scalar
=
get_scalar_type
(
"uint16"
)
uint16
:
Scalar
Type
=
get_scalar_type
(
"uint16"
)
uint32
:
Scalar
=
get_scalar_type
(
"uint32"
)
uint32
:
Scalar
Type
=
get_scalar_type
(
"uint32"
)
uint64
:
Scalar
=
get_scalar_type
(
"uint64"
)
uint64
:
Scalar
Type
=
get_scalar_type
(
"uint64"
)
float16
:
Scalar
=
get_scalar_type
(
"float16"
)
float16
:
Scalar
Type
=
get_scalar_type
(
"float16"
)
float32
:
Scalar
=
get_scalar_type
(
"float32"
)
float32
:
Scalar
Type
=
get_scalar_type
(
"float32"
)
float64
:
Scalar
=
get_scalar_type
(
"float64"
)
float64
:
Scalar
Type
=
get_scalar_type
(
"float64"
)
complex64
:
Scalar
=
get_scalar_type
(
"complex64"
)
complex64
:
Scalar
Type
=
get_scalar_type
(
"complex64"
)
complex128
:
Scalar
=
get_scalar_type
(
"complex128"
)
complex128
:
Scalar
Type
=
get_scalar_type
(
"complex128"
)
_ScalarTypes
:
TypeAlias
=
Tuple
[
Scalar
,
...
]
_ScalarTypes
:
TypeAlias
=
Tuple
[
Scalar
Type
,
...
]
int_types
:
_ScalarTypes
=
(
int8
,
int16
,
int32
,
int64
)
int_types
:
_ScalarTypes
=
(
int8
,
int16
,
int32
,
int64
)
uint_types
:
_ScalarTypes
=
(
uint8
,
uint16
,
uint32
,
uint64
)
uint_types
:
_ScalarTypes
=
(
uint8
,
uint16
,
uint32
,
uint64
)
float_types
:
_ScalarTypes
=
(
float16
,
float32
,
float64
)
float_types
:
_ScalarTypes
=
(
float16
,
float32
,
float64
)
...
@@ -732,7 +736,7 @@ discrete_dtypes = tuple(t.dtype for t in discrete_types)
...
@@ -732,7 +736,7 @@ discrete_dtypes = tuple(t.dtype for t in discrete_types)
class
_scalar_py_operators
:
class
_scalar_py_operators
:
# So that we can simplify checking code when we have a mixture of Scalar
# So that we can simplify checking code when we have a mixture of Scalar
Type
# variables and Tensor variables
# variables and Tensor variables
ndim
=
0
ndim
=
0
...
@@ -844,7 +848,7 @@ class ScalarVariable(_scalar_py_operators, Variable):
...
@@ -844,7 +848,7 @@ class ScalarVariable(_scalar_py_operators, Variable):
pass
pass
Scalar
.
variable_type
=
ScalarVariable
Scalar
Type
.
variable_type
=
ScalarVariable
class
ScalarConstant
(
ScalarVariable
,
Constant
):
class
ScalarConstant
(
ScalarVariable
,
Constant
):
...
@@ -852,8 +856,8 @@ class ScalarConstant(ScalarVariable, Constant):
...
@@ -852,8 +856,8 @@ class ScalarConstant(ScalarVariable, Constant):
Constant
.
__init__
(
self
,
*
args
,
**
kwargs
)
Constant
.
__init__
(
self
,
*
args
,
**
kwargs
)
# Register ScalarConstant as the type of Constant corresponding to Scalar
# Register ScalarConstant as the type of Constant corresponding to Scalar
Type
Scalar
.
constant_type
=
ScalarConstant
Scalar
Type
.
constant_type
=
ScalarConstant
def
constant
(
x
,
name
=
None
,
dtype
=
None
)
->
ScalarConstant
:
def
constant
(
x
,
name
=
None
,
dtype
=
None
)
->
ScalarConstant
:
...
@@ -876,16 +880,16 @@ def as_scalar(x, name=None) -> ScalarConstant:
...
@@ -876,16 +880,16 @@ def as_scalar(x, name=None) -> ScalarConstant:
else
:
else
:
x
=
x
.
outputs
[
0
]
x
=
x
.
outputs
[
0
]
if
isinstance
(
x
,
Variable
):
if
isinstance
(
x
,
Variable
):
if
isinstance
(
x
.
type
,
Scalar
):
if
isinstance
(
x
.
type
,
Scalar
Type
):
return
x
return
x
elif
isinstance
(
x
.
type
,
TensorType
)
and
x
.
ndim
==
0
:
elif
isinstance
(
x
.
type
,
TensorType
)
and
x
.
ndim
==
0
:
return
scalar_from_tensor
(
x
)
return
scalar_from_tensor
(
x
)
else
:
else
:
raise
TypeError
(
"Variable type field must be a Scalar."
,
x
,
x
.
type
)
raise
TypeError
(
"Variable type field must be a Scalar
Type
."
,
x
,
x
.
type
)
try
:
try
:
return
constant
(
x
)
return
constant
(
x
)
except
TypeError
:
except
TypeError
:
raise
TypeError
(
f
"Cannot convert {x} to Scalar"
,
type
(
x
))
raise
TypeError
(
f
"Cannot convert {x} to Scalar
Type
"
,
type
(
x
))
# Easy constructors
# Easy constructors
...
@@ -898,7 +902,7 @@ complexs128 = apply_across_args(complex128)
...
@@ -898,7 +902,7 @@ complexs128 = apply_across_args(complex128)
def
upcast_out
(
*
types
):
def
upcast_out
(
*
types
):
dtype
=
Scalar
.
upcast
(
*
types
)
dtype
=
Scalar
Type
.
upcast
(
*
types
)
return
(
get_scalar_type
(
dtype
),)
return
(
get_scalar_type
(
dtype
),)
...
@@ -932,7 +936,9 @@ def upgrade_to_float(*types):
...
@@ -932,7 +936,9 @@ def upgrade_to_float(*types):
uint32
:
float64
,
uint32
:
float64
,
uint64
:
float64
,
uint64
:
float64
,
}
}
return
(
get_scalar_type
(
Scalar
.
upcast
(
*
[
conv
.
get
(
type
,
type
)
for
type
in
types
])),)
return
(
get_scalar_type
(
ScalarType
.
upcast
(
*
[
conv
.
get
(
type
,
type
)
for
type
in
types
])),
)
def
upgrade_to_float64
(
*
types
):
def
upgrade_to_float64
(
*
types
):
...
@@ -962,7 +968,7 @@ def same_out_min8(type):
...
@@ -962,7 +968,7 @@ def same_out_min8(type):
def
upcast_out_no_complex
(
*
types
):
def
upcast_out_no_complex
(
*
types
):
if
any
(
type
in
complex_types
for
type
in
types
):
if
any
(
type
in
complex_types
for
type
in
types
):
raise
TypeError
(
"complex type are not supported"
)
raise
TypeError
(
"complex type are not supported"
)
return
(
get_scalar_type
(
dtype
=
Scalar
.
upcast
(
*
types
)),)
return
(
get_scalar_type
(
dtype
=
Scalar
Type
.
upcast
(
*
types
)),)
def
same_out_float_only
(
type
):
def
same_out_float_only
(
type
):
...
@@ -2452,7 +2458,7 @@ identity = Identity(same_out, name="identity")
...
@@ -2452,7 +2458,7 @@ identity = Identity(same_out, name="identity")
# CASTING OPERATIONS
# CASTING OPERATIONS
class
Cast
(
UnaryScalarOp
):
class
Cast
(
UnaryScalarOp
):
def
__init__
(
self
,
o_type
,
name
=
None
):
def
__init__
(
self
,
o_type
,
name
=
None
):
if
not
isinstance
(
o_type
,
Scalar
):
if
not
isinstance
(
o_type
,
Scalar
Type
):
raise
TypeError
(
o_type
)
raise
TypeError
(
o_type
)
super
()
.
__init__
(
specific_out
(
o_type
),
name
=
name
)
super
()
.
__init__
(
specific_out
(
o_type
),
name
=
name
)
self
.
o_type
=
o_type
self
.
o_type
=
o_type
...
@@ -2539,7 +2545,7 @@ _cast_mapping = {
...
@@ -2539,7 +2545,7 @@ _cast_mapping = {
def
cast
(
x
,
dtype
):
def
cast
(
x
,
dtype
):
"""
"""
Symbolically cast `x` to a Scalar of given `dtype`.
Symbolically cast `x` to a Scalar
Type
of given `dtype`.
"""
"""
if
dtype
==
"floatX"
:
if
dtype
==
"floatX"
:
...
@@ -3926,7 +3932,7 @@ class Complex(BinaryScalarOp):
...
@@ -3926,7 +3932,7 @@ class Complex(BinaryScalarOp):
if
y
in
complex_types
:
if
y
in
complex_types
:
raise
TypeError
(
y
)
raise
TypeError
(
y
)
up
=
Scalar
.
upcast
(
x
,
y
)
up
=
Scalar
Type
.
upcast
(
x
,
y
)
if
up
in
(
"float64"
,
"int64"
,
"uint64"
,
"int32"
,
"uint32"
):
if
up
in
(
"float64"
,
"int64"
,
"uint64"
,
"int32"
,
"uint32"
):
return
[
complex128
]
return
[
complex128
]
else
:
else
:
...
...
aesara/scalar/sharedvar.py
浏览文件 @
470b9d60
...
@@ -19,11 +19,7 @@ way (as scan does) to create a shared variable of this kind.
...
@@ -19,11 +19,7 @@ way (as scan does) to create a shared variable of this kind.
import
numpy
as
np
import
numpy
as
np
from
aesara.compile
import
SharedVariable
from
aesara.compile
import
SharedVariable
from
aesara.scalar.basic
import
ScalarType
,
_scalar_py_operators
from
.basic
import
Scalar
,
_scalar_py_operators
__docformat__
=
"restructuredtext en"
class
ScalarSharedVariable
(
_scalar_py_operators
,
SharedVariable
):
class
ScalarSharedVariable
(
_scalar_py_operators
,
SharedVariable
):
...
@@ -54,7 +50,7 @@ def shared(value, name=None, strict=False, allow_downcast=None):
...
@@ -54,7 +50,7 @@ def shared(value, name=None, strict=False, allow_downcast=None):
dtype
=
str
(
dtype
)
dtype
=
str
(
dtype
)
value
=
getattr
(
np
,
dtype
)(
value
)
value
=
getattr
(
np
,
dtype
)(
value
)
scalar_type
=
Scalar
(
dtype
=
dtype
)
scalar_type
=
Scalar
Type
(
dtype
=
dtype
)
rval
=
ScalarSharedVariable
(
rval
=
ScalarSharedVariable
(
type
=
scalar_type
,
type
=
scalar_type
,
value
=
value
,
value
=
value
,
...
...
aesara/scan/utils.py
浏览文件 @
470b9d60
...
@@ -62,7 +62,7 @@ def safe_new(
...
@@ -62,7 +62,7 @@ def safe_new(
return
nwx
return
nwx
else
:
else
:
return
x
return
x
# Note, `as_tensor_variable` will convert the `Scalar` into a
# Note, `as_tensor_variable` will convert the `Scalar
Type
` into a
# `TensorScalar` that will require a `ScalarFromTensor` `Op`, making the
# `TensorScalar` that will require a `ScalarFromTensor` `Op`, making the
# push-out optimization fail
# push-out optimization fail
elif
isinstance
(
x
,
aes
.
ScalarVariable
):
elif
isinstance
(
x
,
aes
.
ScalarVariable
):
...
...
aesara/tensor/__init__.py
浏览文件 @
470b9d60
...
@@ -12,7 +12,7 @@ def as_tensor_variable(
...
@@ -12,7 +12,7 @@ def as_tensor_variable(
)
->
"TensorVariable"
:
)
->
"TensorVariable"
:
"""Convert `x` into an equivalent `TensorVariable`.
"""Convert `x` into an equivalent `TensorVariable`.
This function can be used to turn ndarrays, numbers, `Scalar` instances,
This function can be used to turn ndarrays, numbers, `Scalar
Type
` instances,
`Apply` instances and `TensorVariable` instances into valid input list
`Apply` instances and `TensorVariable` instances into valid input list
elements.
elements.
...
...
aesara/tensor/basic.py
浏览文件 @
470b9d60
...
@@ -537,8 +537,8 @@ class TensorFromScalar(Op):
...
@@ -537,8 +537,8 @@ class TensorFromScalar(Op):
__props__
=
()
__props__
=
()
def
make_node
(
self
,
s
):
def
make_node
(
self
,
s
):
if
not
isinstance
(
s
.
type
,
aes
.
Scalar
):
if
not
isinstance
(
s
.
type
,
aes
.
Scalar
Type
):
raise
TypeError
(
"Input must be a `Scalar` `Type`"
)
raise
TypeError
(
"Input must be a `Scalar
Type
` `Type`"
)
return
Apply
(
self
,
[
s
],
[
tensor
(
dtype
=
s
.
type
.
dtype
,
shape
=
())])
return
Apply
(
self
,
[
s
],
[
tensor
(
dtype
=
s
.
type
.
dtype
,
shape
=
())])
...
...
aesara/tensor/elemwise.py
浏览文件 @
470b9d60
...
@@ -16,7 +16,7 @@ from aesara.misc.frozendict import frozendict
...
@@ -16,7 +16,7 @@ from aesara.misc.frozendict import frozendict
from
aesara.misc.safe_asarray
import
_asarray
from
aesara.misc.safe_asarray
import
_asarray
from
aesara.printing
import
FunctionPrinter
,
Printer
,
pprint
from
aesara.printing
import
FunctionPrinter
,
Printer
,
pprint
from
aesara.scalar
import
get_scalar_type
from
aesara.scalar
import
get_scalar_type
from
aesara.scalar.basic
import
Scalar
from
aesara.scalar.basic
import
Scalar
Type
from
aesara.scalar.basic
import
bool
as
scalar_bool
from
aesara.scalar.basic
import
bool
as
scalar_bool
from
aesara.scalar.basic
import
identity
as
scalar_identity
from
aesara.scalar.basic
import
identity
as
scalar_identity
from
aesara.scalar.basic
import
transfer_type
,
upcast
from
aesara.scalar.basic
import
transfer_type
,
upcast
...
@@ -815,7 +815,7 @@ second dimension
...
@@ -815,7 +815,7 @@ second dimension
# there must be some input that is not broadcastable in
# there must be some input that is not broadcastable in
# dimension 'dim'
# dimension 'dim'
for
ishp
,
i
in
zip
(
i_shapes
,
node
.
inputs
):
for
ishp
,
i
in
zip
(
i_shapes
,
node
.
inputs
):
if
isinstance
(
i
.
type
,
Scalar
):
if
isinstance
(
i
.
type
,
Scalar
Type
):
continue
# we skip scalar
continue
# we skip scalar
if
not
i
.
type
.
broadcastable
[
dim
]:
if
not
i
.
type
.
broadcastable
[
dim
]:
# input i is not broadcastable in position dim
# input i is not broadcastable in position dim
...
...
aesara/tensor/nnet/abstract_conv.py
浏览文件 @
470b9d60
...
@@ -1811,7 +1811,7 @@ def bilinear_kernel_2D(ratio, normalize=True):
...
@@ -1811,7 +1811,7 @@ def bilinear_kernel_2D(ratio, normalize=True):
Parameters
Parameters
----------
----------
ratio: int or Constant/Scalar Aesara tensor of int* dtype
ratio: int or Constant/Scalar
Type
Aesara tensor of int* dtype
the ratio by which an image will be upsampled by the returned filter
the ratio by which an image will be upsampled by the returned filter
in the 2D space.
in the 2D space.
...
@@ -1847,7 +1847,7 @@ def bilinear_kernel_1D(ratio, normalize=True):
...
@@ -1847,7 +1847,7 @@ def bilinear_kernel_1D(ratio, normalize=True):
Parameters
Parameters
----------
----------
ratio: int or Constant/Scalar Aesara tensor of int* dtype
ratio: int or Constant/Scalar
Type
Aesara tensor of int* dtype
the ratio by which an image will be upsampled by the returned filter
the ratio by which an image will be upsampled by the returned filter
in the 2D space.
in the 2D space.
...
@@ -1998,7 +1998,7 @@ def bilinear_upsampling(
...
@@ -1998,7 +1998,7 @@ def bilinear_upsampling(
input: symbolic 4D tensor
input: symbolic 4D tensor
mini-batch of feature map stacks, of shape (batch size,
mini-batch of feature map stacks, of shape (batch size,
input channels, input rows, input columns) that will be upsampled.
input channels, input rows, input columns) that will be upsampled.
ratio: `int or Constant or Scalar Tensor of int* dtype`
ratio: `int or Constant or Scalar
Type
Tensor of int* dtype`
the ratio by which the input is upsampled in the 2D space (row and
the ratio by which the input is upsampled in the 2D space (row and
col size).
col size).
frac_ratio: None, tuple of int or tuple of tuples of int
frac_ratio: None, tuple of int or tuple of tuples of int
...
...
aesara/tensor/nnet/basic.py
浏览文件 @
470b9d60
...
@@ -30,7 +30,6 @@ from aesara.link.c.op import COp
...
@@ -30,7 +30,6 @@ from aesara.link.c.op import COp
from
aesara.raise_op
import
Assert
from
aesara.raise_op
import
Assert
from
aesara.scalar
import
UnaryScalarOp
from
aesara.scalar
import
UnaryScalarOp
from
aesara.tensor
import
basic
as
at
from
aesara.tensor
import
basic
as
at
from
aesara.tensor
import
extra_ops
,
math_opt
from
aesara.tensor.basic
import
ARange
,
as_tensor_variable
from
aesara.tensor.basic
import
ARange
,
as_tensor_variable
from
aesara.tensor.basic_opt
import
(
from
aesara.tensor.basic_opt
import
(
register_canonicalize
,
register_canonicalize
,
...
@@ -39,6 +38,7 @@ from aesara.tensor.basic_opt import (
...
@@ -39,6 +38,7 @@ from aesara.tensor.basic_opt import (
)
)
from
aesara.tensor.elemwise
import
DimShuffle
,
Elemwise
from
aesara.tensor.elemwise
import
DimShuffle
,
Elemwise
from
aesara.tensor.exceptions
import
NotScalarConstantError
from
aesara.tensor.exceptions
import
NotScalarConstantError
from
aesara.tensor.extra_ops
import
Unique
from
aesara.tensor.math
import
(
from
aesara.tensor.math
import
(
MaxAndArgmax
,
MaxAndArgmax
,
Sum
,
Sum
,
...
@@ -57,6 +57,7 @@ from aesara.tensor.math import (
...
@@ -57,6 +57,7 @@ from aesara.tensor.math import (
)
)
from
aesara.tensor.math
import
sum
as
at_sum
from
aesara.tensor.math
import
sum
as
at_sum
from
aesara.tensor.math
import
tanh
,
tensordot
,
true_div
from
aesara.tensor.math
import
tanh
,
tensordot
,
true_div
from
aesara.tensor.math_opt
import
local_mul_canonizer
from
aesara.tensor.nnet.blocksparse
import
sparse_block_dot
from
aesara.tensor.nnet.blocksparse
import
sparse_block_dot
from
aesara.tensor.shape
import
Shape
,
shape_padleft
from
aesara.tensor.shape
import
Shape
,
shape_padleft
from
aesara.tensor.subtensor
import
AdvancedIncSubtensor
,
AdvancedSubtensor
from
aesara.tensor.subtensor
import
AdvancedIncSubtensor
,
AdvancedSubtensor
...
@@ -1291,7 +1292,7 @@ def softmax_simplifier(numerators, denominators):
...
@@ -1291,7 +1292,7 @@ def softmax_simplifier(numerators, denominators):
return
numerators
,
denominators
return
numerators
,
denominators
math_opt
.
local_mul_canonizer
.
add_simplifier
(
softmax_simplifier
,
"softmax_simplifier"
)
local_mul_canonizer
.
add_simplifier
(
softmax_simplifier
,
"softmax_simplifier"
)
class
CrossentropySoftmaxArgmax1HotWithBias
(
COp
):
class
CrossentropySoftmaxArgmax1HotWithBias
(
COp
):
...
@@ -2974,7 +2975,7 @@ def confusion_matrix(actual, pred):
...
@@ -2974,7 +2975,7 @@ def confusion_matrix(actual, pred):
if
pred
.
ndim
!=
1
:
if
pred
.
ndim
!=
1
:
raise
ValueError
(
"pred must be 1-d tensor variable"
)
raise
ValueError
(
"pred must be 1-d tensor variable"
)
order
=
extra_ops
.
Unique
(
False
,
False
,
False
)(
at
.
concatenate
([
actual
,
pred
]))
order
=
Unique
(
False
,
False
,
False
)(
at
.
concatenate
([
actual
,
pred
]))
colA
=
actual
.
dimshuffle
(
0
,
"x"
)
colA
=
actual
.
dimshuffle
(
0
,
"x"
)
colP
=
pred
.
dimshuffle
(
0
,
"x"
)
colP
=
pred
.
dimshuffle
(
0
,
"x"
)
...
...
aesara/tensor/nnet/batchnorm.py
浏览文件 @
470b9d60
...
@@ -21,11 +21,11 @@ class BNComposite(Composite):
...
@@ -21,11 +21,11 @@ class BNComposite(Composite):
@config.change_flags
(
compute_test_value
=
"off"
)
@config.change_flags
(
compute_test_value
=
"off"
)
def
__init__
(
self
,
dtype
):
def
__init__
(
self
,
dtype
):
self
.
dtype
=
dtype
self
.
dtype
=
dtype
x
=
aesara
.
scalar
.
Scalar
(
dtype
=
dtype
)
.
make_variable
()
x
=
aesara
.
scalar
.
Scalar
Type
(
dtype
=
dtype
)
.
make_variable
()
mean
=
aesara
.
scalar
.
Scalar
(
dtype
=
dtype
)
.
make_variable
()
mean
=
aesara
.
scalar
.
Scalar
Type
(
dtype
=
dtype
)
.
make_variable
()
std
=
aesara
.
scalar
.
Scalar
(
dtype
=
dtype
)
.
make_variable
()
std
=
aesara
.
scalar
.
Scalar
Type
(
dtype
=
dtype
)
.
make_variable
()
gamma
=
aesara
.
scalar
.
Scalar
(
dtype
=
dtype
)
.
make_variable
()
gamma
=
aesara
.
scalar
.
Scalar
Type
(
dtype
=
dtype
)
.
make_variable
()
beta
=
aesara
.
scalar
.
Scalar
(
dtype
=
dtype
)
.
make_variable
()
beta
=
aesara
.
scalar
.
Scalar
Type
(
dtype
=
dtype
)
.
make_variable
()
o
=
add
(
mul
(
true_div
(
sub
(
x
,
mean
),
std
),
gamma
),
beta
)
o
=
add
(
mul
(
true_div
(
sub
(
x
,
mean
),
std
),
gamma
),
beta
)
inputs
=
[
x
,
mean
,
std
,
gamma
,
beta
]
inputs
=
[
x
,
mean
,
std
,
gamma
,
beta
]
outputs
=
[
o
]
outputs
=
[
o
]
...
...
aesara/tensor/nnet/sigm.py
浏览文件 @
470b9d60
...
@@ -150,7 +150,7 @@ def hard_sigmoid(x):
...
@@ -150,7 +150,7 @@ def hard_sigmoid(x):
"""
"""
# Use the same dtype as determined by "upgrade_to_float",
# Use the same dtype as determined by "upgrade_to_float",
# and perform computation in that dtype.
# and perform computation in that dtype.
out_dtype
=
aes
.
upgrade_to_float
(
aes
.
Scalar
(
dtype
=
x
.
dtype
))[
0
]
.
dtype
out_dtype
=
aes
.
upgrade_to_float
(
aes
.
Scalar
Type
(
dtype
=
x
.
dtype
))[
0
]
.
dtype
slope
=
constant
(
0.2
,
dtype
=
out_dtype
)
slope
=
constant
(
0.2
,
dtype
=
out_dtype
)
shift
=
constant
(
0.5
,
dtype
=
out_dtype
)
shift
=
constant
(
0.5
,
dtype
=
out_dtype
)
x
=
(
x
*
slope
)
+
shift
x
=
(
x
*
slope
)
+
shift
...
...
aesara/tensor/subtensor.py
浏览文件 @
470b9d60
...
@@ -624,7 +624,7 @@ def get_constant_idx(
...
@@ -624,7 +624,7 @@ def get_constant_idx(
Example usage where `v` and `a` are appropriately typed Aesara variables :
Example usage where `v` and `a` are appropriately typed Aesara variables :
>>> b = a[v, 1:3]
>>> b = a[v, 1:3]
>>> b.owner.op.idx_list
>>> b.owner.op.idx_list
(Scalar
(int64), slice(Scalar(int64), Scalar
(int64), None))
(Scalar
Type(int64), slice(ScalarType(int64), ScalarType
(int64), None))
>>> get_constant_idx(b.owner.op.idx_list, b.owner.inputs, allow_partial=True)
>>> get_constant_idx(b.owner.op.idx_list, b.owner.inputs, allow_partial=True)
[v, slice(1, 3, None)]
[v, slice(1, 3, None)]
>>> get_constant_idx(b.owner.op.idx_list, b.owner.inputs)
>>> get_constant_idx(b.owner.op.idx_list, b.owner.inputs)
...
@@ -656,7 +656,7 @@ def get_constant_idx(
...
@@ -656,7 +656,7 @@ def get_constant_idx(
def
as_nontensor_scalar
(
a
:
Variable
)
->
aes
.
ScalarVariable
:
def
as_nontensor_scalar
(
a
:
Variable
)
->
aes
.
ScalarVariable
:
"""Convert a value to a `Scalar` variable."""
"""Convert a value to a `Scalar
Type
` variable."""
# Since aes.as_scalar does not know about tensor types (it would
# Since aes.as_scalar does not know about tensor types (it would
# create a circular import) , this method converts either a
# create a circular import) , this method converts either a
# TensorVariable or a ScalarVariable to a scalar.
# TensorVariable or a ScalarVariable to a scalar.
...
@@ -1196,7 +1196,7 @@ class SubtensorPrinter(Printer):
...
@@ -1196,7 +1196,7 @@ class SubtensorPrinter(Printer):
sidxs
=
[]
sidxs
=
[]
getattr
(
pstate
,
"precedence"
,
None
)
getattr
(
pstate
,
"precedence"
,
None
)
for
entry
in
idxs
:
for
entry
in
idxs
:
if
isinstance
(
entry
,
aes
.
Scalar
):
if
isinstance
(
entry
,
aes
.
Scalar
Type
):
with
set_precedence
(
pstate
):
with
set_precedence
(
pstate
):
sidxs
.
append
(
pstate
.
pprinter
.
process
(
inputs
.
pop
()))
sidxs
.
append
(
pstate
.
pprinter
.
process
(
inputs
.
pop
()))
elif
isinstance
(
entry
,
slice
):
elif
isinstance
(
entry
,
slice
):
...
...
aesara/tensor/subtensor_opt.py
浏览文件 @
470b9d60
...
@@ -562,8 +562,8 @@ def local_subtensor_remove_broadcastable_index(fgraph, node):
...
@@ -562,8 +562,8 @@ def local_subtensor_remove_broadcastable_index(fgraph, node):
remove_dim
=
[]
remove_dim
=
[]
node_inputs_idx
=
1
node_inputs_idx
=
1
for
dim
,
elem
in
enumerate
(
idx
):
for
dim
,
elem
in
enumerate
(
idx
):
if
isinstance
(
elem
,
(
aes
.
Scalar
)):
if
isinstance
(
elem
,
(
aes
.
Scalar
Type
)):
# The idx is a Scalar, ie a Type. This means the actual index
# The idx is a Scalar
Type
, ie a Type. This means the actual index
# is contained in node.inputs[1]
# is contained in node.inputs[1]
dim_index
=
node
.
inputs
[
node_inputs_idx
]
dim_index
=
node
.
inputs
[
node_inputs_idx
]
if
isinstance
(
dim_index
,
aes
.
ScalarConstant
):
if
isinstance
(
dim_index
,
aes
.
ScalarConstant
):
...
@@ -741,7 +741,7 @@ def local_subtensor_make_vector(fgraph, node):
...
@@ -741,7 +741,7 @@ def local_subtensor_make_vector(fgraph, node):
if
isinstance
(
node
.
op
,
Subtensor
):
if
isinstance
(
node
.
op
,
Subtensor
):
(
idx
,)
=
node
.
op
.
idx_list
(
idx
,)
=
node
.
op
.
idx_list
if
isinstance
(
idx
,
(
aes
.
Scalar
,
TensorType
)):
if
isinstance
(
idx
,
(
aes
.
Scalar
Type
,
TensorType
)):
old_idx
,
idx
=
idx
,
node
.
inputs
[
1
]
old_idx
,
idx
=
idx
,
node
.
inputs
[
1
]
assert
idx
.
type
.
is_super
(
old_idx
)
assert
idx
.
type
.
is_super
(
old_idx
)
elif
isinstance
(
node
.
op
,
AdvancedSubtensor1
):
elif
isinstance
(
node
.
op
,
AdvancedSubtensor1
):
...
...
doc/extending/ctype.rst
浏览文件 @
470b9d60
...
@@ -130,7 +130,7 @@ prefix. The complete list can be found in the documentation for
...
@@ -130,7 +130,7 @@ prefix. The complete list can be found in the documentation for
for the variables handled by this Aesara type. For example,
for the variables handled by this Aesara type. For example,
for a matrix of 32-bit signed NumPy integers, it should return
for a matrix of 32-bit signed NumPy integers, it should return
``"npy_int32"``. If C type may change from an instance to another
``"npy_int32"``. If C type may change from an instance to another
(e.g. ``Scalar
('int32')`` vs ``Scalar
('int64')``), consider
(e.g. ``Scalar
Type('int32')`` vs ``ScalarType
('int64')``), consider
implementing this method. If C type is fixed across instances,
implementing this method. If C type is fixed across instances,
this method may be useless (as you already know the C type
this method may be useless (as you already know the C type
when you work with the C code).
when you work with the C code).
...
...
doc/extending/other_ops.rst
浏览文件 @
470b9d60
...
@@ -222,7 +222,7 @@ along with pointers to the relevant documentation.
...
@@ -222,7 +222,7 @@ along with pointers to the relevant documentation.
type). Variables of this Aesara type are represented in C as objects
type). Variables of this Aesara type are represented in C as objects
of class `PyListObject <https://docs.python.org/2/c-api/list.html>`_.
of class `PyListObject <https://docs.python.org/2/c-api/list.html>`_.
* :ref:`Scalar <libdoc_scalar>` : Aesara type that represents a C
* :ref:`Scalar
Type
<libdoc_scalar>` : Aesara type that represents a C
primitive type. The C type associated with this Aesara type is the
primitive type. The C type associated with this Aesara type is the
represented C primitive itself.
represented C primitive itself.
...
...
doc/sandbox/how_to_make_ops.rst
浏览文件 @
470b9d60
...
@@ -64,17 +64,17 @@ Example:
...
@@ -64,17 +64,17 @@ Example:
class Add(Op):
class Add(Op):
#...
#...
def make_node(self, x, y):
def make_node(self, x, y):
# note 1: constant, int64 and Scalar are defined in aesara.scalar
# note 1: constant, int64 and Scalar
Type
are defined in aesara.scalar
# note 2: constant(x) is equivalent to Constant(type = int64, data = x)
# note 2: constant(x) is equivalent to Constant(type = int64, data = x)
# note 3: the call int64() is equivalent to Variable(type = int64) or Variable(type = Scalar(dtype = 'int64'))
# note 3: the call int64() is equivalent to Variable(type = int64) or Variable(type = Scalar
Type
(dtype = 'int64'))
if isinstance(x, int):
if isinstance(x, int):
x = constant(x)
x = constant(x)
elif not isinstance(x, Variable) or not x.type == int64:
elif not isinstance(x, Variable) or not x.type == int64:
raise TypeError("expected an int64 Scalar")
raise TypeError("expected an int64 Scalar
Type
")
if isinstance(y, int):
if isinstance(y, int):
y = constant(y)
y = constant(y)
elif not isinstance(y, Variable) or not x.type == int64:
elif not isinstance(y, Variable) or not x.type == int64:
raise TypeError("expected an int64 Scalar")
raise TypeError("expected an int64 Scalar
Type
")
inputs = [x, y]
inputs = [x, y]
outputs = [int64()]
outputs = [int64()]
node = Apply(op = self, inputs = inputs, outputs = outputs)
node = Apply(op = self, inputs = inputs, outputs = outputs)
...
...
tests/graph/test_unify.py
浏览文件 @
470b9d60
...
@@ -258,10 +258,10 @@ def test_unify_Type():
...
@@ -258,10 +258,10 @@ def test_unify_Type():
s
=
unify
(
t1
,
etuple
(
TensorType
,
"float64"
,
(
1
,
None
)))
s
=
unify
(
t1
,
etuple
(
TensorType
,
"float64"
,
(
1
,
None
)))
assert
s
==
{}
assert
s
==
{}
from
aesara.scalar.basic
import
Scalar
from
aesara.scalar.basic
import
Scalar
Type
st1
=
Scalar
(
np
.
float64
)
st1
=
Scalar
Type
(
np
.
float64
)
st2
=
Scalar
(
np
.
float64
)
st2
=
Scalar
Type
(
np
.
float64
)
s
=
unify
(
st1
,
st2
)
s
=
unify
(
st1
,
st2
)
assert
s
==
{}
assert
s
==
{}
...
...
tests/link/c/c_code/test_quadratic_function.c
浏览文件 @
470b9d60
...
@@ -28,7 +28,7 @@ int APPLY_SPECIFIC(quadratic_function)(PyArrayObject* tensor, DTYPE_INPUT_0 a, D
...
@@ -28,7 +28,7 @@ int APPLY_SPECIFIC(quadratic_function)(PyArrayObject* tensor, DTYPE_INPUT_0 a, D
int
APPLY_SPECIFIC
(
compute_quadratic
)(
PyArrayObject
*
X
,
PyArrayObject
**
Y
,
PARAMS_TYPE
*
coeff
)
{
int
APPLY_SPECIFIC
(
compute_quadratic
)(
PyArrayObject
*
X
,
PyArrayObject
**
Y
,
PARAMS_TYPE
*
coeff
)
{
DTYPE_INPUT_0
a
=
(
DTYPE_INPUT_0
)
(
*
(
DTYPE_PARAM_a
*
)
PyArray_GETPTR1
(
coeff
->
a
,
0
));
// 0-D TensorType.
DTYPE_INPUT_0
a
=
(
DTYPE_INPUT_0
)
(
*
(
DTYPE_PARAM_a
*
)
PyArray_GETPTR1
(
coeff
->
a
,
0
));
// 0-D TensorType.
DTYPE_INPUT_0
b
=
coeff
->
b
;
// Scalar.
DTYPE_INPUT_0
b
=
coeff
->
b
;
// Scalar
Type
.
DTYPE_INPUT_0
c
=
(
DTYPE_INPUT_0
)
PyFloat_AsDouble
(
coeff
->
c
);
// Generic.
DTYPE_INPUT_0
c
=
(
DTYPE_INPUT_0
)
PyFloat_AsDouble
(
coeff
->
c
);
// Generic.
Py_XDECREF
(
*
Y
);
Py_XDECREF
(
*
Y
);
*
Y
=
(
PyArrayObject
*
)
PyArray_EMPTY
(
PyArray_NDIM
(
X
),
PyArray_DIMS
(
X
),
TYPENUM_INPUT_0
,
PyArray_IS_F_CONTIGUOUS
(
X
));
*
Y
=
(
PyArrayObject
*
)
PyArray_EMPTY
(
PyArray_NDIM
(
X
),
PyArray_DIMS
(
X
),
TYPENUM_INPUT_0
,
PyArray_IS_F_CONTIGUOUS
(
X
));
...
...
tests/link/c/test_params_type.py
浏览文件 @
470b9d60
...
@@ -7,13 +7,13 @@ from aesara.graph.basic import Apply
...
@@ -7,13 +7,13 @@ from aesara.graph.basic import Apply
from
aesara.link.c.op
import
COp
,
ExternalCOp
from
aesara.link.c.op
import
COp
,
ExternalCOp
from
aesara.link.c.params_type
import
Params
,
ParamsType
from
aesara.link.c.params_type
import
Params
,
ParamsType
from
aesara.link.c.type
import
EnumList
,
Generic
from
aesara.link.c.type
import
EnumList
,
Generic
from
aesara.scalar
import
Scalar
from
aesara.scalar
import
Scalar
Type
from
aesara.tensor.type
import
TensorType
,
matrix
from
aesara.tensor.type
import
TensorType
,
matrix
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
tensor_type_0d
=
TensorType
(
"float64"
,
tuple
())
tensor_type_0d
=
TensorType
(
"float64"
,
tuple
())
scalar_type
=
Scalar
(
"float64"
)
scalar_type
=
Scalar
Type
(
"float64"
)
generic_type
=
Generic
()
generic_type
=
Generic
()
...
@@ -77,7 +77,7 @@ class QuadraticOpFunc(COp):
...
@@ -77,7 +77,7 @@ class QuadraticOpFunc(COp):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
return
"""
return
"""
%(float_type)
s a = (
%(float_type)
s) (*(npy_float64*) PyArray_GETPTR1(
%(coeff)
s->a, 0)); // 0-D TensorType.
%(float_type)
s a = (
%(float_type)
s) (*(npy_float64*) PyArray_GETPTR1(
%(coeff)
s->a, 0)); // 0-D TensorType.
%(float_type)
s b =
%(coeff)
s->b; // Scalar.
%(float_type)
s b =
%(coeff)
s->b; // Scalar
Type
.
%(float_type)
s c = (
%(float_type)
s) PyFloat_AsDouble(
%(coeff)
s->c); // Generic.
%(float_type)
s c = (
%(float_type)
s) PyFloat_AsDouble(
%(coeff)
s->c); // Generic.
Py_XDECREF(
%(Y)
s);
Py_XDECREF(
%(Y)
s);
%(Y)
s = (PyArrayObject*)PyArray_EMPTY(PyArray_NDIM(
%(X)
s), PyArray_DIMS(
%(X)
s), PyArray_TYPE(
%(X)
s), PyArray_IS_F_CONTIGUOUS(
%(X)
s));
%(Y)
s = (PyArrayObject*)PyArray_EMPTY(PyArray_NDIM(
%(X)
s), PyArray_DIMS(
%(X)
s), PyArray_TYPE(
%(X)
s), PyArray_IS_F_CONTIGUOUS(
%(X)
s));
...
@@ -128,13 +128,13 @@ class TestParamsType:
...
@@ -128,13 +128,13 @@ class TestParamsType:
wp1
=
ParamsType
(
wp1
=
ParamsType
(
a
=
Generic
(),
a
=
Generic
(),
array
=
TensorType
(
"int64"
,
(
False
,)),
array
=
TensorType
(
"int64"
,
(
False
,)),
floatting
=
Scalar
(
"float64"
),
floatting
=
Scalar
Type
(
"float64"
),
npy_scalar
=
TensorType
(
"float64"
,
tuple
()),
npy_scalar
=
TensorType
(
"float64"
,
tuple
()),
)
)
wp2
=
ParamsType
(
wp2
=
ParamsType
(
a
=
Generic
(),
a
=
Generic
(),
array
=
TensorType
(
"int64"
,
(
False
,)),
array
=
TensorType
(
"int64"
,
(
False
,)),
floatting
=
Scalar
(
"float64"
),
floatting
=
Scalar
Type
(
"float64"
),
npy_scalar
=
TensorType
(
"float64"
,
tuple
()),
npy_scalar
=
TensorType
(
"float64"
,
tuple
()),
)
)
w1
=
Params
(
w1
=
Params
(
...
@@ -158,7 +158,7 @@ class TestParamsType:
...
@@ -158,7 +158,7 @@ class TestParamsType:
wp2_other
=
ParamsType
(
wp2_other
=
ParamsType
(
other_name
=
Generic
(),
other_name
=
Generic
(),
array
=
TensorType
(
"int64"
,
(
False
,)),
array
=
TensorType
(
"int64"
,
(
False
,)),
floatting
=
Scalar
(
"float64"
),
floatting
=
Scalar
Type
(
"float64"
),
npy_scalar
=
TensorType
(
"float64"
,
tuple
()),
npy_scalar
=
TensorType
(
"float64"
,
tuple
()),
)
)
w2
=
Params
(
w2
=
Params
(
...
...
tests/scalar/test_basic.py
浏览文件 @
470b9d60
"""
These routines are not well-tested. They are also old.
OB says that it is not important to test them well because Scalar Ops
are rarely used by themselves, instead they are the basis for Tensor Ops
(which should be checked thoroughly). Moreover, Scalar will be changed
to use numpy's scalar routines.
If you do want to rewrite these tests, bear in mind:
* You don't need to use Composite.
* FunctionGraph and DualLinker are old, use aesara.compile.function.function instead.
"""
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
...
@@ -20,7 +10,7 @@ from aesara.scalar.basic import (
...
@@ -20,7 +10,7 @@ from aesara.scalar.basic import (
ComplexError
,
ComplexError
,
Composite
,
Composite
,
InRange
,
InRange
,
Scalar
,
Scalar
Type
,
add
,
add
,
and_
,
and_
,
arccos
,
arccos
,
...
@@ -357,8 +347,8 @@ class TestUpgradeToFloat:
...
@@ -357,8 +347,8 @@ class TestUpgradeToFloat:
xi
=
int8
(
"xi"
)
xi
=
int8
(
"xi"
)
yi
=
int8
(
"yi"
)
yi
=
int8
(
"yi"
)
xf
=
Scalar
(
aesara
.
config
.
floatX
)(
"xf"
)
xf
=
Scalar
Type
(
aesara
.
config
.
floatX
)(
"xf"
)
yf
=
Scalar
(
aesara
.
config
.
floatX
)(
"yf"
)
yf
=
Scalar
Type
(
aesara
.
config
.
floatX
)(
"yf"
)
ei
=
true_div
(
xi
,
yi
)
ei
=
true_div
(
xi
,
yi
)
fi
=
aesara
.
function
([
xi
,
yi
],
ei
)
fi
=
aesara
.
function
([
xi
,
yi
],
ei
)
...
...
tests/scalar/test_type.py
浏览文件 @
470b9d60
...
@@ -3,7 +3,7 @@ import numpy as np
...
@@ -3,7 +3,7 @@ import numpy as np
from
aesara.configdefaults
import
config
from
aesara.configdefaults
import
config
from
aesara.scalar.basic
import
(
from
aesara.scalar.basic
import
(
IntDiv
,
IntDiv
,
Scalar
,
Scalar
Type
,
TrueDiv
,
TrueDiv
,
complex64
,
complex64
,
float32
,
float32
,
...
@@ -14,7 +14,7 @@ from aesara.scalar.basic import (
...
@@ -14,7 +14,7 @@ from aesara.scalar.basic import (
def
test_numpy_dtype
():
def
test_numpy_dtype
():
test_type
=
Scalar
(
np
.
int32
)
test_type
=
Scalar
Type
(
np
.
int32
)
assert
test_type
.
dtype
==
"int32"
assert
test_type
.
dtype
==
"int32"
...
@@ -37,9 +37,9 @@ def test_div_types():
...
@@ -37,9 +37,9 @@ def test_div_types():
def
test_filter_float_subclass
():
def
test_filter_float_subclass
():
"""Make sure `Scalar.filter` can handle `float` subclasses."""
"""Make sure `Scalar
Type
.filter` can handle `float` subclasses."""
with
config
.
change_flags
(
floatX
=
"float64"
):
with
config
.
change_flags
(
floatX
=
"float64"
):
test_type
=
Scalar
(
"float64"
)
test_type
=
Scalar
Type
(
"float64"
)
nan
=
np
.
array
([
np
.
nan
],
dtype
=
"float64"
)[
0
]
nan
=
np
.
array
([
np
.
nan
],
dtype
=
"float64"
)[
0
]
assert
isinstance
(
nan
,
float
)
assert
isinstance
(
nan
,
float
)
...
@@ -49,7 +49,7 @@ def test_filter_float_subclass():
...
@@ -49,7 +49,7 @@ def test_filter_float_subclass():
with
config
.
change_flags
(
floatX
=
"float32"
):
with
config
.
change_flags
(
floatX
=
"float32"
):
# Try again, except this time `nan` isn't a `float`
# Try again, except this time `nan` isn't a `float`
test_type
=
Scalar
(
"float32"
)
test_type
=
Scalar
Type
(
"float32"
)
nan
=
np
.
array
([
np
.
nan
],
dtype
=
"float32"
)[
0
]
nan
=
np
.
array
([
np
.
nan
],
dtype
=
"float32"
)[
0
]
assert
isinstance
(
nan
,
np
.
floating
)
assert
isinstance
(
nan
,
np
.
floating
)
...
@@ -63,6 +63,6 @@ def test_filter_float_subclass():
...
@@ -63,6 +63,6 @@ def test_filter_float_subclass():
def
test_clone
():
def
test_clone
():
st
=
Scalar
(
"int64"
)
st
=
Scalar
Type
(
"int64"
)
assert
st
==
st
.
clone
()
assert
st
==
st
.
clone
()
assert
st
.
clone
(
"float64"
)
.
dtype
==
"float64"
assert
st
.
clone
(
"float64"
)
.
dtype
==
"float64"
tests/tensor/test_basic.py
浏览文件 @
470b9d60
...
@@ -3448,7 +3448,7 @@ class TestGetScalarConstantValue:
...
@@ -3448,7 +3448,7 @@ class TestGetScalarConstantValue:
assert
get_scalar_constant_value
(
mv
[
np
.
int32
(
0
)])
==
1
assert
get_scalar_constant_value
(
mv
[
np
.
int32
(
0
)])
==
1
assert
get_scalar_constant_value
(
mv
[
np
.
int64
(
1
)])
==
2
assert
get_scalar_constant_value
(
mv
[
np
.
int64
(
1
)])
==
2
assert
get_scalar_constant_value
(
mv
[
np
.
uint
(
2
)])
==
3
assert
get_scalar_constant_value
(
mv
[
np
.
uint
(
2
)])
==
3
t
=
aes
.
Scalar
(
"int64"
)
t
=
aes
.
Scalar
Type
(
"int64"
)
with
pytest
.
raises
(
NotScalarConstantError
):
with
pytest
.
raises
(
NotScalarConstantError
):
get_scalar_constant_value
(
mv
[
t
()])
get_scalar_constant_value
(
mv
[
t
()])
...
...
tests/tensor/test_basic_opt.py
浏览文件 @
470b9d60
...
@@ -1971,7 +1971,7 @@ class TestCastCast:
...
@@ -1971,7 +1971,7 @@ class TestCastCast:
def
test_consecutive
(
self
):
def
test_consecutive
(
self
):
x
=
fmatrix
()
x
=
fmatrix
()
o
=
Elemwise
(
aes
.
Cast
(
aes
.
Scalar
(
"float64"
)))(
x
.
astype
(
"float64"
))
o
=
Elemwise
(
aes
.
Cast
(
aes
.
Scalar
Type
(
"float64"
)))(
x
.
astype
(
"float64"
))
f
=
function
([
x
],
o
,
mode
=
self
.
mode
)
f
=
function
([
x
],
o
,
mode
=
self
.
mode
)
dx
=
np
.
random
.
random
((
5
,
4
))
.
astype
(
"float32"
)
dx
=
np
.
random
.
random
((
5
,
4
))
.
astype
(
"float32"
)
f
(
dx
)
f
(
dx
)
...
@@ -1980,7 +1980,7 @@ class TestCastCast:
...
@@ -1980,7 +1980,7 @@ class TestCastCast:
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
aes
.
basic
.
Cast
)
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
aes
.
basic
.
Cast
)
x
=
dmatrix
()
x
=
dmatrix
()
o
=
Elemwise
(
aes
.
Cast
(
aes
.
Scalar
(
"float32"
)))(
x
.
astype
(
"float32"
))
o
=
Elemwise
(
aes
.
Cast
(
aes
.
Scalar
Type
(
"float32"
)))(
x
.
astype
(
"float32"
))
f
=
function
([
x
],
o
,
mode
=
self
.
mode
)
f
=
function
([
x
],
o
,
mode
=
self
.
mode
)
dx
=
np
.
random
.
random
((
5
,
4
))
dx
=
np
.
random
.
random
((
5
,
4
))
f
(
dx
)
f
(
dx
)
...
@@ -1991,7 +1991,7 @@ class TestCastCast:
...
@@ -1991,7 +1991,7 @@ class TestCastCast:
def
test_upcast
(
self
):
def
test_upcast
(
self
):
# Upcast followed by any other cast
# Upcast followed by any other cast
x
=
fmatrix
()
x
=
fmatrix
()
o
=
Elemwise
(
aes
.
Cast
(
aes
.
Scalar
(
"complex128"
)))(
x
.
astype
(
"complex64"
))
o
=
Elemwise
(
aes
.
Cast
(
aes
.
Scalar
Type
(
"complex128"
)))(
x
.
astype
(
"complex64"
))
f
=
function
([
x
],
o
,
mode
=
self
.
mode
)
f
=
function
([
x
],
o
,
mode
=
self
.
mode
)
dx
=
np
.
random
.
random
((
5
,
4
))
.
astype
(
"float32"
)
dx
=
np
.
random
.
random
((
5
,
4
))
.
astype
(
"float32"
)
f
(
dx
)
f
(
dx
)
...
@@ -2001,7 +2001,7 @@ class TestCastCast:
...
@@ -2001,7 +2001,7 @@ class TestCastCast:
# Upcast followed by a downcast back to the base type
# Upcast followed by a downcast back to the base type
x
=
fmatrix
()
x
=
fmatrix
()
o
=
Elemwise
(
aes
.
Cast
(
aes
.
Scalar
(
"float32"
)))(
x
.
astype
(
"float64"
))
o
=
Elemwise
(
aes
.
Cast
(
aes
.
Scalar
Type
(
"float32"
)))(
x
.
astype
(
"float64"
))
f
=
function
([
x
],
o
,
mode
=
self
.
mode
)
f
=
function
([
x
],
o
,
mode
=
self
.
mode
)
dx
=
np
.
random
.
random
((
5
,
4
))
.
astype
(
"float32"
)
dx
=
np
.
random
.
random
((
5
,
4
))
.
astype
(
"float32"
)
f
(
dx
)
f
(
dx
)
...
@@ -2012,7 +2012,7 @@ class TestCastCast:
...
@@ -2012,7 +2012,7 @@ class TestCastCast:
# Downcast followed by an upcast back to the base type
# Downcast followed by an upcast back to the base type
# Optimization shouldn't be applied
# Optimization shouldn't be applied
x
=
dmatrix
()
x
=
dmatrix
()
o
=
Elemwise
(
aes
.
Cast
(
aes
.
Scalar
(
"float64"
)))(
x
.
astype
(
"float32"
))
o
=
Elemwise
(
aes
.
Cast
(
aes
.
Scalar
Type
(
"float64"
)))(
x
.
astype
(
"float32"
))
f
=
function
([
x
],
o
,
mode
=
self
.
mode
)
f
=
function
([
x
],
o
,
mode
=
self
.
mode
)
dx
=
np
.
random
.
random
((
5
,
4
))
dx
=
np
.
random
.
random
((
5
,
4
))
f
(
dx
)
f
(
dx
)
...
@@ -2641,7 +2641,7 @@ def test_local_tensor_scalar_tensor(dtype):
...
@@ -2641,7 +2641,7 @@ def test_local_tensor_scalar_tensor(dtype):
],
],
)
)
def
test_local_scalar_tensor_scalar
(
dtype
):
def
test_local_scalar_tensor_scalar
(
dtype
):
s_type
=
aes
.
Scalar
(
dtype
=
dtype
)
s_type
=
aes
.
Scalar
Type
(
dtype
=
dtype
)
s
=
s_type
()
s
=
s_type
()
t
=
at
.
tensor_from_scalar
(
s
)
t
=
at
.
tensor_from_scalar
(
s
)
s2
=
at
.
scalar_from_tensor
(
t
)
s2
=
at
.
scalar_from_tensor
(
t
)
...
...
tests/tensor/test_math.py
浏览文件 @
470b9d60
...
@@ -2269,7 +2269,7 @@ class TestArithmeticCast:
...
@@ -2269,7 +2269,7 @@ class TestArithmeticCast:
return
np
.
array
([
1
],
dtype
=
dtype
)
return
np
.
array
([
1
],
dtype
=
dtype
)
def
Aesara_i_scalar
(
dtype
):
def
Aesara_i_scalar
(
dtype
):
return
aes
.
Scalar
(
str
(
dtype
))()
return
aes
.
Scalar
Type
(
str
(
dtype
))()
def
numpy_i_scalar
(
dtype
):
def
numpy_i_scalar
(
dtype
):
return
numpy_scalar
(
dtype
)
return
numpy_scalar
(
dtype
)
...
...
tests/tensor/test_subtensor.py
浏览文件 @
470b9d60
...
@@ -2621,4 +2621,4 @@ def test_index_vars_to_types():
...
@@ -2621,4 +2621,4 @@ def test_index_vars_to_types():
index_vars_to_types
(
1
)
index_vars_to_types
(
1
)
res
=
index_vars_to_types
(
iscalar
)
res
=
index_vars_to_types
(
iscalar
)
assert
isinstance
(
res
,
scal
.
Scalar
)
assert
isinstance
(
res
,
scal
.
Scalar
Type
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论