Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e5d09827
提交
e5d09827
authored
4月 19, 2017
作者:
Frédéric Bastien
提交者:
GitHub
4月 19, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5853 from Amrithasuresh/master
Updated numpy as np #4218
上级
c82f6e51
3d8ab35a
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
152 行增加
和
152 行删除
+152
-152
__init__.py
theano/__init__.py
+2
-2
configdefaults.py
theano/configdefaults.py
+6
-6
test_params_type.py
theano/gof/tests/test_params_type.py
+12
-12
rng_mrg.py
theano/gpuarray/rng_mrg.py
+2
-2
basic.py
theano/scalar/basic.py
+120
-120
basic_scipy.py
theano/scalar/basic_scipy.py
+6
-6
sharedvar.py
theano/scalar/sharedvar.py
+4
-4
没有找到文件。
theano/__init__.py
浏览文件 @
e5d09827
...
@@ -134,7 +134,7 @@ if (config.device.startswith('cuda') or
...
@@ -134,7 +134,7 @@ if (config.device.startswith('cuda') or
import
theano.gpuarray
import
theano.gpuarray
# Use config.numpy to call numpy.seterr
# Use config.numpy to call numpy.seterr
import
numpy
import
numpy
as
np
if
config
.
numpy
.
seterr_all
==
'None'
:
if
config
.
numpy
.
seterr_all
==
'None'
:
_all
=
None
_all
=
None
...
@@ -156,7 +156,7 @@ if config.numpy.seterr_invalid == 'None':
...
@@ -156,7 +156,7 @@ if config.numpy.seterr_invalid == 'None':
_invalid
=
None
_invalid
=
None
else
:
else
:
_invalid
=
config
.
numpy
.
seterr_invalid
_invalid
=
config
.
numpy
.
seterr_invalid
n
umpy
.
seterr
(
n
p
.
seterr
(
all
=
_all
,
all
=
_all
,
divide
=
_divide
,
divide
=
_divide
,
over
=
_over
,
over
=
_over
,
...
...
theano/configdefaults.py
浏览文件 @
e5d09827
...
@@ -3,7 +3,7 @@ import errno
...
@@ -3,7 +3,7 @@ import errno
import
os
import
os
import
sys
import
sys
import
logging
import
logging
import
numpy
import
numpy
as
np
import
platform
import
platform
import
textwrap
import
textwrap
import
re
import
re
...
@@ -1052,7 +1052,7 @@ AddConfigVar('profiling.ignore_first_call',
...
@@ -1052,7 +1052,7 @@ AddConfigVar('profiling.ignore_first_call',
AddConfigVar
(
'optdb.position_cutoff'
,
AddConfigVar
(
'optdb.position_cutoff'
,
'Where to stop eariler during optimization. It represent the'
'Where to stop eariler during optimization. It represent the'
' position of the optimizer where to stop.'
,
' position of the optimizer where to stop.'
,
FloatParam
(
n
umpy
.
inf
),
FloatParam
(
n
p
.
inf
),
in_c_key
=
False
)
in_c_key
=
False
)
AddConfigVar
(
'optdb.max_use_ratio'
,
AddConfigVar
(
'optdb.max_use_ratio'
,
...
@@ -1106,11 +1106,11 @@ def default_blas_ldflags():
...
@@ -1106,11 +1106,11 @@ def default_blas_ldflags():
global
numpy
global
numpy
warn_record
=
[]
warn_record
=
[]
try
:
try
:
if
(
hasattr
(
n
umpy
.
distutils
,
'__config__'
)
and
if
(
hasattr
(
n
p
.
distutils
,
'__config__'
)
and
n
umpy
.
distutils
.
__config__
):
n
p
.
distutils
.
__config__
):
# If the old private interface is available use it as it
# If the old private interface is available use it as it
# don't print information to the user.
# don't print information to the user.
blas_info
=
n
umpy
.
distutils
.
__config__
.
blas_opt_info
blas_info
=
n
p
.
distutils
.
__config__
.
blas_opt_info
else
:
else
:
# We do this import only here, as in some setup, if we
# We do this import only here, as in some setup, if we
# just import theano and exit, with the import at global
# just import theano and exit, with the import at global
...
@@ -1494,7 +1494,7 @@ compiledir_format_dict = {
...
@@ -1494,7 +1494,7 @@ compiledir_format_dict = {
"python_bitwidth"
:
local_bitwidth
(),
"python_bitwidth"
:
local_bitwidth
(),
"python_int_bitwidth"
:
python_int_bitwidth
(),
"python_int_bitwidth"
:
python_int_bitwidth
(),
"theano_version"
:
theano
.
__version__
,
"theano_version"
:
theano
.
__version__
,
"numpy_version"
:
n
umpy
.
__version__
,
"numpy_version"
:
n
p
.
__version__
,
"gxx_version"
:
gcc_version_str
.
replace
(
" "
,
"_"
),
"gxx_version"
:
gcc_version_str
.
replace
(
" "
,
"_"
),
"hostname"
:
socket
.
gethostname
()}
"hostname"
:
socket
.
gethostname
()}
...
...
theano/gof/tests/test_params_type.py
浏览文件 @
e5d09827
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
theano
import
theano
import
numpy
import
numpy
as
np
from
unittest
import
TestCase
from
unittest
import
TestCase
from
theano.gof
import
Op
,
COp
,
Apply
from
theano.gof
import
Op
,
COp
,
Apply
from
theano
import
Generic
from
theano
import
Generic
...
@@ -121,21 +121,21 @@ class TestParamsType(TestCase):
...
@@ -121,21 +121,21 @@ class TestParamsType(TestCase):
npy_scalar
=
TensorType
(
'float64'
,
tuple
()))
npy_scalar
=
TensorType
(
'float64'
,
tuple
()))
wp2
=
ParamsType
(
a
=
Generic
(),
array
=
TensorType
(
'int64'
,
(
False
,)),
floatting
=
Scalar
(
'float64'
),
wp2
=
ParamsType
(
a
=
Generic
(),
array
=
TensorType
(
'int64'
,
(
False
,)),
floatting
=
Scalar
(
'float64'
),
npy_scalar
=
TensorType
(
'float64'
,
tuple
()))
npy_scalar
=
TensorType
(
'float64'
,
tuple
()))
w1
=
Params
(
wp1
,
a
=
1
,
array
=
n
umpy
.
asarray
([
1
,
2
,
4
,
5
,
7
]),
floatting
=-
4.5
,
npy_scalar
=
numpy
.
asarray
(
12
))
w1
=
Params
(
wp1
,
a
=
1
,
array
=
n
p
.
asarray
([
1
,
2
,
4
,
5
,
7
]),
floatting
=-
4.5
,
npy_scalar
=
np
.
asarray
(
12
))
w2
=
Params
(
wp2
,
a
=
1
,
array
=
n
umpy
.
asarray
([
1
,
2
,
4
,
5
,
7
]),
floatting
=-
4.5
,
npy_scalar
=
numpy
.
asarray
(
12
))
w2
=
Params
(
wp2
,
a
=
1
,
array
=
n
p
.
asarray
([
1
,
2
,
4
,
5
,
7
]),
floatting
=-
4.5
,
npy_scalar
=
np
.
asarray
(
12
))
assert
w1
==
w2
assert
w1
==
w2
assert
not
(
w1
!=
w2
)
assert
not
(
w1
!=
w2
)
assert
hash
(
w1
)
==
hash
(
w2
)
assert
hash
(
w1
)
==
hash
(
w2
)
# Changing attributes names only (a -> other_name).
# Changing attributes names only (a -> other_name).
wp2_other
=
ParamsType
(
other_name
=
Generic
(),
array
=
TensorType
(
'int64'
,
(
False
,)),
floatting
=
Scalar
(
'float64'
),
wp2_other
=
ParamsType
(
other_name
=
Generic
(),
array
=
TensorType
(
'int64'
,
(
False
,)),
floatting
=
Scalar
(
'float64'
),
npy_scalar
=
TensorType
(
'float64'
,
tuple
()))
npy_scalar
=
TensorType
(
'float64'
,
tuple
()))
w2
=
Params
(
wp2_other
,
other_name
=
1
,
array
=
n
umpy
.
asarray
([
1
,
2
,
4
,
5
,
7
]),
floatting
=-
4.5
,
npy_scalar
=
numpy
.
asarray
(
12
))
w2
=
Params
(
wp2_other
,
other_name
=
1
,
array
=
n
p
.
asarray
([
1
,
2
,
4
,
5
,
7
]),
floatting
=-
4.5
,
npy_scalar
=
np
.
asarray
(
12
))
assert
w1
!=
w2
assert
w1
!=
w2
# Changing attributes values only (now a=2).
# Changing attributes values only (now a=2).
w2
=
Params
(
wp2
,
a
=
2
,
array
=
n
umpy
.
asarray
([
1
,
2
,
4
,
5
,
7
]),
floatting
=-
4.5
,
npy_scalar
=
numpy
.
asarray
(
12
))
w2
=
Params
(
wp2
,
a
=
2
,
array
=
n
p
.
asarray
([
1
,
2
,
4
,
5
,
7
]),
floatting
=-
4.5
,
npy_scalar
=
np
.
asarray
(
12
))
assert
w1
!=
w2
assert
w1
!=
w2
# Changing NumPy array values (5 -> -5).
# Changing NumPy array values (5 -> -5).
w2
=
Params
(
wp2
,
a
=
1
,
array
=
n
umpy
.
asarray
([
1
,
2
,
4
,
-
5
,
7
]),
floatting
=-
4.5
,
npy_scalar
=
numpy
.
asarray
(
12
))
w2
=
Params
(
wp2
,
a
=
1
,
array
=
n
p
.
asarray
([
1
,
2
,
4
,
-
5
,
7
]),
floatting
=-
4.5
,
npy_scalar
=
np
.
asarray
(
12
))
assert
w1
!=
w2
assert
w1
!=
w2
def
test_hash_and_eq_params_type
(
self
):
def
test_hash_and_eq_params_type
(
self
):
...
@@ -168,7 +168,7 @@ class TestParamsType(TestCase):
...
@@ -168,7 +168,7 @@ class TestParamsType(TestCase):
def
test_params_type_filtering
(
self
):
def
test_params_type_filtering
(
self
):
shape_tensor5
=
(
1
,
2
,
2
,
3
,
2
)
shape_tensor5
=
(
1
,
2
,
2
,
3
,
2
)
size_tensor5
=
shape_tensor5
[
0
]
*
shape_tensor5
[
1
]
*
shape_tensor5
[
2
]
*
shape_tensor5
[
3
]
*
shape_tensor5
[
4
]
size_tensor5
=
shape_tensor5
[
0
]
*
shape_tensor5
[
1
]
*
shape_tensor5
[
2
]
*
shape_tensor5
[
3
]
*
shape_tensor5
[
4
]
random_tensor
=
n
umpy
.
random
.
normal
(
size
=
size_tensor5
)
.
reshape
(
shape_tensor5
)
random_tensor
=
n
p
.
random
.
normal
(
size
=
size_tensor5
)
.
reshape
(
shape_tensor5
)
w
=
ParamsType
(
a1
=
TensorType
(
'int32'
,
(
False
,
False
)),
w
=
ParamsType
(
a1
=
TensorType
(
'int32'
,
(
False
,
False
)),
a2
=
TensorType
(
'float64'
,
(
False
,
False
,
False
,
False
,
False
)),
a2
=
TensorType
(
'float64'
,
(
False
,
False
,
False
,
False
,
False
)),
...
@@ -176,7 +176,7 @@ class TestParamsType(TestCase):
...
@@ -176,7 +176,7 @@ class TestParamsType(TestCase):
# With a value that does not match the params type.
# With a value that does not match the params type.
o
=
Params
(
w
,
o
=
Params
(
w
,
a1
=
n
umpy
.
asarray
([[
1
,
2
,
3
,
4
,
5
,
6
],
[
7
,
8
,
9
,
10
,
11
,
12
]])
.
astype
(
'int64'
),
a1
=
n
p
.
asarray
([[
1
,
2
,
3
,
4
,
5
,
6
],
[
7
,
8
,
9
,
10
,
11
,
12
]])
.
astype
(
'int64'
),
a2
=
random_tensor
.
astype
(
'float32'
),
a2
=
random_tensor
.
astype
(
'float32'
),
a3
=
2000
)
a3
=
2000
)
# should fail (o.a1 is not int32, o.a2 is not float64)
# should fail (o.a1 is not int32, o.a2 is not float64)
...
@@ -188,7 +188,7 @@ class TestParamsType(TestCase):
...
@@ -188,7 +188,7 @@ class TestParamsType(TestCase):
# With a value that matches the params type.
# With a value that matches the params type.
o1
=
Params
(
w
,
o1
=
Params
(
w
,
a1
=
n
umpy
.
asarray
([[
1
,
2
,
3
,
4
,
5
,
6
],
[
7
,
8
,
9
,
10
,
11
,
12
]])
.
astype
(
'int32'
),
a1
=
n
p
.
asarray
([[
1
,
2
,
3
,
4
,
5
,
6
],
[
7
,
8
,
9
,
10
,
11
,
12
]])
.
astype
(
'int32'
),
a2
=
random_tensor
.
astype
(
'float64'
),
a2
=
random_tensor
.
astype
(
'float64'
),
a3
=
2000
)
a3
=
2000
)
# All should pass.
# All should pass.
...
@@ -198,7 +198,7 @@ class TestParamsType(TestCase):
...
@@ -198,7 +198,7 @@ class TestParamsType(TestCase):
# Check values_eq and values_eq_approx.
# Check values_eq and values_eq_approx.
o2
=
Params
(
w
,
o2
=
Params
(
w
,
a1
=
n
umpy
.
asarray
([[
1
,
2
,
3
,
4
,
5
,
6
],
[
7
,
8
,
9
,
10
,
11
,
12
]])
.
astype
(
'int32'
),
a1
=
n
p
.
asarray
([[
1
,
2
,
3
,
4
,
5
,
6
],
[
7
,
8
,
9
,
10
,
11
,
12
]])
.
astype
(
'int32'
),
a2
=
random_tensor
.
astype
(
'float64'
),
a2
=
random_tensor
.
astype
(
'float64'
),
a3
=
2000
)
a3
=
2000
)
assert
w
.
values_eq
(
o1
,
o2
)
assert
w
.
values_eq
(
o1
,
o2
)
...
@@ -208,7 +208,7 @@ class TestParamsType(TestCase):
...
@@ -208,7 +208,7 @@ class TestParamsType(TestCase):
# NB: I don't know exactly which kind of differences is rejected by values_eq but accepted by values_eq_approx.
# NB: I don't know exactly which kind of differences is rejected by values_eq but accepted by values_eq_approx.
# So, I just play a little with float values.
# So, I just play a little with float values.
o3
=
Params
(
w
,
o3
=
Params
(
w
,
a1
=
n
umpy
.
asarray
([[
1
,
2
,
3
,
4
,
5
,
6
],
[
7
,
8
,
9
,
10
,
11
,
12
]])
.
astype
(
'int32'
),
a1
=
n
p
.
asarray
([[
1
,
2
,
3
,
4
,
5
,
6
],
[
7
,
8
,
9
,
10
,
11
,
12
]])
.
astype
(
'int32'
),
a2
=
(
random_tensor
.
astype
(
'float32'
)
*
10
/
2.2
*
2.19999999999
/
10
)
.
astype
(
'float64'
),
a2
=
(
random_tensor
.
astype
(
'float32'
)
*
10
/
2.2
*
2.19999999999
/
10
)
.
astype
(
'float64'
),
a3
=
2000.0
-
0.00000000000000001
)
a3
=
2000.0
-
0.00000000000000001
)
assert
w
.
values_eq_approx
(
o1
,
o3
)
assert
w
.
values_eq_approx
(
o1
,
o3
)
...
@@ -250,7 +250,7 @@ class TestParamsType(TestCase):
...
@@ -250,7 +250,7 @@ class TestParamsType(TestCase):
f1
=
theano
.
function
([
x
],
y1
)
f1
=
theano
.
function
([
x
],
y1
)
f2
=
theano
.
function
([
x
],
y2
)
f2
=
theano
.
function
([
x
],
y2
)
shape
=
(
100
,
100
)
shape
=
(
100
,
100
)
vx
=
n
umpy
.
random
.
normal
(
size
=
shape
[
0
]
*
shape
[
1
])
.
astype
(
'float64'
)
.
reshape
(
*
shape
)
vx
=
n
p
.
random
.
normal
(
size
=
shape
[
0
]
*
shape
[
1
])
.
astype
(
'float64'
)
.
reshape
(
*
shape
)
vy1
=
f1
(
vx
)
vy1
=
f1
(
vx
)
vy2
=
f2
(
vx
)
vy2
=
f2
(
vx
)
ref
=
a
*
(
vx
**
2
)
+
b
*
vx
+
c
ref
=
a
*
(
vx
**
2
)
+
b
*
vx
+
c
...
...
theano/gpuarray/rng_mrg.py
浏览文件 @
e5d09827
...
@@ -7,7 +7,7 @@ http://www.iro.umontreal.ca/~simardr/ssj/indexe.html
...
@@ -7,7 +7,7 @@ http://www.iro.umontreal.ca/~simardr/ssj/indexe.html
"""
"""
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
from
theano
import
Apply
,
tensor
from
theano
import
Apply
,
tensor
from
theano.gof
import
local_optimizer
from
theano.gof
import
local_optimizer
...
@@ -170,7 +170,7 @@ class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base):
...
@@ -170,7 +170,7 @@ class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base):
o_rstate
,
o_sample
=
out
o_rstate
,
o_sample
=
out
inplace
=
int
(
self
.
inplace
)
inplace
=
int
(
self
.
inplace
)
ndim
=
self
.
output_type
.
ndim
ndim
=
self
.
output_type
.
ndim
o_type_num
=
n
umpy
.
asarray
(
0
,
dtype
=
self
.
output_type
.
dtype
)
.
dtype
.
num
o_type_num
=
n
p
.
asarray
(
0
,
dtype
=
self
.
output_type
.
dtype
)
.
dtype
.
num
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
ctx
=
sub
[
'params'
]
ctx
=
sub
[
'params'
]
kname
=
self
.
gpu_kernels
(
node
,
nodename
)[
0
]
.
objvar
kname
=
self
.
gpu_kernels
(
node
,
nodename
)[
0
]
.
objvar
...
...
theano/scalar/basic.py
浏览文件 @
e5d09827
...
@@ -17,7 +17,7 @@ import warnings
...
@@ -17,7 +17,7 @@ import warnings
from
copy
import
copy
from
copy
import
copy
from
textwrap
import
dedent
from
textwrap
import
dedent
import
numpy
import
numpy
as
np
import
six
import
six
from
six.moves
import
xrange
from
six.moves
import
xrange
...
@@ -72,7 +72,7 @@ def upcast(dtype, *dtypes):
...
@@ -72,7 +72,7 @@ def upcast(dtype, *dtypes):
keep_float16
[
0
]
=
False
keep_float16
[
0
]
=
False
if
dt
==
'float32'
:
if
dt
==
'float32'
:
keep_float16
[
0
]
=
False
keep_float16
[
0
]
=
False
return
n
umpy
.
zeros
((),
dtype
=
dt
)
return
n
p
.
zeros
((),
dtype
=
dt
)
z
=
make_array
(
dtype
)
z
=
make_array
(
dtype
)
for
dt
in
dtypes
:
for
dt
in
dtypes
:
z
=
z
+
make_array
(
dt
=
dt
)
z
=
z
+
make_array
(
dt
=
dt
)
...
@@ -168,12 +168,12 @@ class NumpyAutocaster(object):
...
@@ -168,12 +168,12 @@ class NumpyAutocaster(object):
# Make sure we only deal with scalars.
# Make sure we only deal with scalars.
assert
(
isinstance
(
x
,
six
.
integer_types
)
or
assert
(
isinstance
(
x
,
six
.
integer_types
)
or
isinstance
(
x
,
builtin_float
)
or
isinstance
(
x
,
builtin_float
)
or
(
isinstance
(
x
,
n
umpy
.
ndarray
)
and
x
.
ndim
==
0
))
(
isinstance
(
x
,
n
p
.
ndarray
)
and
x
.
ndim
==
0
))
if
config
.
cast_policy
==
'numpy'
:
if
config
.
cast_policy
==
'numpy'
:
return
n
umpy
.
asarray
(
x
)
return
n
p
.
asarray
(
x
)
elif
config
.
cast_policy
==
'numpy+floatX'
:
elif
config
.
cast_policy
==
'numpy+floatX'
:
rval
=
n
umpy
.
asarray
(
x
)
rval
=
n
p
.
asarray
(
x
)
if
((
not
hasattr
(
x
,
'dtype'
)
and
if
((
not
hasattr
(
x
,
'dtype'
)
and
rval
.
dtype
in
(
'float64'
,
'float32'
)
and
rval
.
dtype
in
(
'float64'
,
'float32'
)
and
rval
.
dtype
!=
config
.
floatX
)):
rval
.
dtype
!=
config
.
floatX
)):
...
@@ -191,7 +191,7 @@ class NumpyAutocaster(object):
...
@@ -191,7 +191,7 @@ class NumpyAutocaster(object):
# No need to cast `x` into a new dtype. Note that we still
# No need to cast `x` into a new dtype. Note that we still
# need to convert it into an array, because it may not be
# need to convert it into an array, because it may not be
# one already (e.g. if x == numpy.float64(1.1)).
# one already (e.g. if x == numpy.float64(1.1)).
return
n
umpy
.
asarray
(
x
)
return
n
p
.
asarray
(
x
)
except
AttributeError
:
except
AttributeError
:
# Means `x` has no 'dtype' attribute.
# Means `x` has no 'dtype' attribute.
pass
pass
...
@@ -209,7 +209,7 @@ class NumpyAutocaster(object):
...
@@ -209,7 +209,7 @@ class NumpyAutocaster(object):
for
dtype
in
try_dtypes
:
for
dtype
in
try_dtypes
:
x_
=
theano
.
_asarray
(
x
,
dtype
=
dtype
)
x_
=
theano
.
_asarray
(
x
,
dtype
=
dtype
)
if
n
umpy
.
all
(
x
==
x_
):
if
n
p
.
all
(
x
==
x_
):
break
break
# returns either an exact x_==x, or the last cast x_
# returns either an exact x_==x, or the last cast x_
return
x_
return
x_
...
@@ -272,16 +272,16 @@ def convert(x, dtype=None):
...
@@ -272,16 +272,16 @@ def convert(x, dtype=None):
x_
=
theano
.
_asarray
(
x
,
dtype
=
'uint64'
)
x_
=
theano
.
_asarray
(
x
,
dtype
=
'uint64'
)
elif
isinstance
(
x
,
builtin_float
):
elif
isinstance
(
x
,
builtin_float
):
x_
=
autocast_float
(
x
)
x_
=
autocast_float
(
x
)
elif
isinstance
(
x
,
n
umpy
.
ndarray
):
elif
isinstance
(
x
,
n
p
.
ndarray
):
x_
=
x
x_
=
x
else
:
else
:
# Here x is probably a list or a tuple. If it contains a
# Here x is probably a list or a tuple. If it contains a
# long, we will behave like the current NumPy version: it
# long, we will behave like the current NumPy version: it
# will work if the long fits in int64 or uint64.
# will work if the long fits in int64 or uint64.
x_
=
n
umpy
.
asarray
(
x
)
x_
=
n
p
.
asarray
(
x
)
if
x_
.
size
==
0
and
not
hasattr
(
x
,
'dtype'
):
if
x_
.
size
==
0
and
not
hasattr
(
x
,
'dtype'
):
x_
=
n
umpy
.
asarray
(
x
,
dtype
=
config
.
floatX
)
x_
=
n
p
.
asarray
(
x
,
dtype
=
config
.
floatX
)
assert
type
(
x_
)
in
[
n
umpy
.
ndarray
,
numpy
.
memmap
]
assert
type
(
x_
)
in
[
n
p
.
ndarray
,
np
.
memmap
]
return
x_
return
x_
...
@@ -396,21 +396,21 @@ class Scalar(Type):
...
@@ -396,21 +396,21 @@ class Scalar(Type):
print(dtype, np.zeros(1, dtype=dtype).dtype.num)
print(dtype, np.zeros(1, dtype=dtype).dtype.num)
"""
"""
return
{
# dtype: (py_type, c_type, cls_name)
return
{
# dtype: (py_type, c_type, cls_name)
'float16'
:
(
n
umpy
.
float16
,
'npy_float16'
,
'Float16'
),
'float16'
:
(
n
p
.
float16
,
'npy_float16'
,
'Float16'
),
'float32'
:
(
n
umpy
.
float32
,
'npy_float32'
,
'Float32'
),
'float32'
:
(
n
p
.
float32
,
'npy_float32'
,
'Float32'
),
'float64'
:
(
n
umpy
.
float64
,
'npy_float64'
,
'Float64'
),
'float64'
:
(
n
p
.
float64
,
'npy_float64'
,
'Float64'
),
'complex128'
:
(
n
umpy
.
complex128
,
'theano_complex128'
,
'complex128'
:
(
n
p
.
complex128
,
'theano_complex128'
,
'Complex128'
),
'Complex128'
),
'complex64'
:
(
n
umpy
.
complex64
,
'theano_complex64'
,
'Complex64'
),
'complex64'
:
(
n
p
.
complex64
,
'theano_complex64'
,
'Complex64'
),
'bool'
:
(
n
umpy
.
bool_
,
'npy_bool'
,
'Bool'
),
'bool'
:
(
n
p
.
bool_
,
'npy_bool'
,
'Bool'
),
'uint8'
:
(
n
umpy
.
uint8
,
'npy_uint8'
,
'UInt8'
),
'uint8'
:
(
n
p
.
uint8
,
'npy_uint8'
,
'UInt8'
),
'int8'
:
(
n
umpy
.
int8
,
'npy_int8'
,
'Int8'
),
'int8'
:
(
n
p
.
int8
,
'npy_int8'
,
'Int8'
),
'uint16'
:
(
n
umpy
.
uint16
,
'npy_uint16'
,
'UInt16'
),
'uint16'
:
(
n
p
.
uint16
,
'npy_uint16'
,
'UInt16'
),
'int16'
:
(
n
umpy
.
int16
,
'npy_int16'
,
'Int16'
),
'int16'
:
(
n
p
.
int16
,
'npy_int16'
,
'Int16'
),
'uint32'
:
(
n
umpy
.
uint32
,
'npy_uint32'
,
'UInt32'
),
'uint32'
:
(
n
p
.
uint32
,
'npy_uint32'
,
'UInt32'
),
'int32'
:
(
n
umpy
.
int32
,
'npy_int32'
,
'Int32'
),
'int32'
:
(
n
p
.
int32
,
'npy_int32'
,
'Int32'
),
'uint64'
:
(
n
umpy
.
uint64
,
'npy_uint64'
,
'UInt64'
),
'uint64'
:
(
n
p
.
uint64
,
'npy_uint64'
,
'UInt64'
),
'int64'
:
(
n
umpy
.
int64
,
'npy_int64'
,
'Int64'
)
'int64'
:
(
n
p
.
int64
,
'npy_int64'
,
'Int64'
)
}[
self
.
dtype
]
}[
self
.
dtype
]
except
KeyError
:
except
KeyError
:
raise
TypeError
(
"Unsupported dtype for
%
s:
%
s"
%
(
raise
TypeError
(
"Unsupported dtype for
%
s:
%
s"
%
(
...
@@ -505,8 +505,8 @@ class Scalar(Type):
...
@@ -505,8 +505,8 @@ class Scalar(Type):
# If the 'int' C type is not exactly the same as an existing
# If the 'int' C type is not exactly the same as an existing
# 'npy_intX', some C code may not compile, e.g. when assigning
# 'npy_intX', some C code may not compile, e.g. when assigning
# the value 0 (cast to 'int' in C) to a theano_complex64.
# the value 0 (cast to 'int' in C) to a theano_complex64.
if
(
n
umpy
.
dtype
(
'intc'
)
.
num
not
in
if
(
n
p
.
dtype
(
'intc'
)
.
num
not
in
[
n
umpy
.
dtype
(
d
[
4
:])
.
num
for
d
in
real_types
]):
[
n
p
.
dtype
(
d
[
4
:])
.
num
for
d
in
real_types
]):
# In that case we add the 'int' type to the real types.
# In that case we add the 'int' type to the real types.
real_types
.
append
(
'int'
)
real_types
.
append
(
'int'
)
...
@@ -645,7 +645,7 @@ class Scalar(Type):
...
@@ -645,7 +645,7 @@ class Scalar(Type):
return
[
"import_array();"
]
return
[
"import_array();"
]
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
13
,
n
umpy
.
__version__
)
return
(
13
,
n
p
.
__version__
)
def
get_shape_info
(
self
,
obj
):
def
get_shape_info
(
self
,
obj
):
return
obj
.
itemsize
return
obj
.
itemsize
...
@@ -1247,7 +1247,7 @@ class LT(LogicalComparison):
...
@@ -1247,7 +1247,7 @@ class LT(LogicalComparison):
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
# built-in < don't support complex
# built-in < don't support complex
return
n
umpy
.
less
(
x
,
y
)
return
n
p
.
less
(
x
,
y
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,
y
)
=
inputs
(
x
,
y
)
=
inputs
...
@@ -1266,7 +1266,7 @@ class GT(LogicalComparison):
...
@@ -1266,7 +1266,7 @@ class GT(LogicalComparison):
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
# built-in > don't support complex
# built-in > don't support complex
return
n
umpy
.
greater
(
x
,
y
)
return
n
p
.
greater
(
x
,
y
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,
y
)
=
inputs
(
x
,
y
)
=
inputs
...
@@ -1285,7 +1285,7 @@ class LE(LogicalComparison):
...
@@ -1285,7 +1285,7 @@ class LE(LogicalComparison):
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
# built-in <= don't support complex
# built-in <= don't support complex
return
n
umpy
.
less_equal
(
x
,
y
)
return
n
p
.
less_equal
(
x
,
y
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,
y
)
=
inputs
(
x
,
y
)
=
inputs
...
@@ -1304,7 +1304,7 @@ class GE(LogicalComparison):
...
@@ -1304,7 +1304,7 @@ class GE(LogicalComparison):
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
# built-in >= don't support complex
# built-in >= don't support complex
return
n
umpy
.
greater_equal
(
x
,
y
)
return
n
p
.
greater_equal
(
x
,
y
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,
y
)
=
inputs
(
x
,
y
)
=
inputs
...
@@ -1353,7 +1353,7 @@ class IsNan(FixedLogicalComparison):
...
@@ -1353,7 +1353,7 @@ class IsNan(FixedLogicalComparison):
nfunc_spec
=
(
'isnan'
,
1
,
1
)
nfunc_spec
=
(
'isnan'
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
n
umpy
.
isnan
(
x
)
return
n
p
.
isnan
(
x
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -1378,7 +1378,7 @@ class IsInf(FixedLogicalComparison):
...
@@ -1378,7 +1378,7 @@ class IsInf(FixedLogicalComparison):
nfunc_spec
=
(
'isinf'
,
1
,
1
)
nfunc_spec
=
(
'isinf'
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
n
umpy
.
isinf
(
x
)
return
n
p
.
isinf
(
x
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -1596,7 +1596,7 @@ class Maximum(BinaryScalarOp):
...
@@ -1596,7 +1596,7 @@ class Maximum(BinaryScalarOp):
def
impl
(
self
,
*
inputs
):
def
impl
(
self
,
*
inputs
):
# The built-in max function don't support complex type
# The built-in max function don't support complex type
return
n
umpy
.
maximum
(
*
inputs
)
return
n
p
.
maximum
(
*
inputs
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,
y
)
=
inputs
(
x
,
y
)
=
inputs
...
@@ -1633,7 +1633,7 @@ class Minimum(BinaryScalarOp):
...
@@ -1633,7 +1633,7 @@ class Minimum(BinaryScalarOp):
def
impl
(
self
,
*
inputs
):
def
impl
(
self
,
*
inputs
):
# The built-in min function don't support complex type
# The built-in min function don't support complex type
return
n
umpy
.
minimum
(
*
inputs
)
return
n
p
.
minimum
(
*
inputs
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,
y
)
=
inputs
(
x
,
y
)
=
inputs
...
@@ -1709,7 +1709,7 @@ class Mul(ScalarOp):
...
@@ -1709,7 +1709,7 @@ class Mul(ScalarOp):
nfunc_spec
=
(
'multiply'
,
2
,
1
)
nfunc_spec
=
(
'multiply'
,
2
,
1
)
def
impl
(
self
,
*
inputs
):
def
impl
(
self
,
*
inputs
):
return
n
umpy
.
product
(
inputs
)
return
n
p
.
product
(
inputs
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
z
,)
=
outputs
(
z
,)
=
outputs
...
@@ -1859,10 +1859,10 @@ class TrueDiv(BinaryScalarOp):
...
@@ -1859,10 +1859,10 @@ class TrueDiv(BinaryScalarOp):
return
super
(
TrueDiv
,
self
)
.
output_types
(
types
)
return
super
(
TrueDiv
,
self
)
.
output_types
(
types
)
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
x
=
n
umpy
.
asarray
(
x
)
x
=
n
p
.
asarray
(
x
)
y
=
n
umpy
.
asarray
(
y
)
y
=
n
p
.
asarray
(
y
)
if
all
(
a
.
dtype
in
discrete_types
for
a
in
(
x
,
y
)):
if
all
(
a
.
dtype
in
discrete_types
for
a
in
(
x
,
y
)):
return
n
umpy
.
sctypeDict
[
config
.
floatX
](
float
(
x
)
/
y
)
return
n
p
.
sctypeDict
[
config
.
floatX
](
float
(
x
)
/
y
)
else
:
else
:
return
x
/
y
return
x
/
y
...
@@ -1999,7 +1999,7 @@ class Mod(BinaryScalarOp):
...
@@ -1999,7 +1999,7 @@ class Mod(BinaryScalarOp):
"complex numbers, since numpy deprecated it."
)
"complex numbers, since numpy deprecated it."
)
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
if
isinstance
(
x
,
n
umpy
.
complex
)
or
isinstance
(
y
,
numpy
.
complex
):
if
isinstance
(
x
,
n
p
.
complex
)
or
isinstance
(
y
,
np
.
complex
):
raise
self
.
complex_error
raise
self
.
complex_error
return
x
%
y
return
x
%
y
...
@@ -2249,7 +2249,7 @@ class Cast(UnaryScalarOp):
...
@@ -2249,7 +2249,7 @@ class Cast(UnaryScalarOp):
raise
TypeError
(
o_type
)
raise
TypeError
(
o_type
)
super
(
Cast
,
self
)
.
__init__
(
specific_out
(
o_type
),
name
=
name
)
super
(
Cast
,
self
)
.
__init__
(
specific_out
(
o_type
),
name
=
name
)
self
.
o_type
=
o_type
self
.
o_type
=
o_type
self
.
ctor
=
getattr
(
n
umpy
,
o_type
.
dtype
)
self
.
ctor
=
getattr
(
n
p
,
o_type
.
dtype
)
def
__str__
(
self
):
def
__str__
(
self
):
return
'
%
s{
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
o_type
.
dtype
)
return
'
%
s{
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
o_type
.
dtype
)
...
@@ -2360,7 +2360,7 @@ class Abs(UnaryScalarOp):
...
@@ -2360,7 +2360,7 @@ class Abs(UnaryScalarOp):
return
Apply
(
self
,
inputs
,
outputs
)
return
Apply
(
self
,
inputs
,
outputs
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
n
umpy
.
abs
(
x
)
return
n
p
.
abs
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2400,7 +2400,7 @@ class Sgn(UnaryScalarOp):
...
@@ -2400,7 +2400,7 @@ class Sgn(UnaryScalarOp):
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
# casting to output type is handled by filter
# casting to output type is handled by filter
return
n
umpy
.
sign
(
x
)
return
n
p
.
sign
(
x
)
def
grad
(
self
,
inputs
,
gout
):
def
grad
(
self
,
inputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2437,7 +2437,7 @@ class Ceil(UnaryScalarOp):
...
@@ -2437,7 +2437,7 @@ class Ceil(UnaryScalarOp):
nfunc_spec
=
(
'ceil'
,
1
,
1
)
nfunc_spec
=
(
'ceil'
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
n
umpy
.
ceil
(
x
)
return
n
p
.
ceil
(
x
)
def
grad
(
self
,
inputs
,
gout
):
def
grad
(
self
,
inputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2460,7 +2460,7 @@ class Floor(UnaryScalarOp):
...
@@ -2460,7 +2460,7 @@ class Floor(UnaryScalarOp):
nfunc_spec
=
(
'floor'
,
1
,
1
)
nfunc_spec
=
(
'floor'
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
n
umpy
.
floor
(
x
)
return
n
p
.
floor
(
x
)
def
grad
(
self
,
inputs
,
gout
):
def
grad
(
self
,
inputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2483,7 +2483,7 @@ class Trunc(UnaryScalarOp):
...
@@ -2483,7 +2483,7 @@ class Trunc(UnaryScalarOp):
nfunc_spec
=
(
'trunc'
,
1
,
1
)
nfunc_spec
=
(
'trunc'
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
n
umpy
.
trunc
(
x
)
return
n
p
.
trunc
(
x
)
def
grad
(
self
,
inputs
,
gout
):
def
grad
(
self
,
inputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2508,7 +2508,7 @@ class RoundHalfToEven(UnaryScalarOp):
...
@@ -2508,7 +2508,7 @@ class RoundHalfToEven(UnaryScalarOp):
nfunc_spec
=
(
'around'
,
1
,
1
)
nfunc_spec
=
(
'around'
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
n
umpy
.
round
(
x
)
return
n
p
.
round
(
x
)
def
grad
(
self
,
inputs
,
gout
):
def
grad
(
self
,
inputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2561,21 +2561,21 @@ round_half_to_even = RoundHalfToEven(same_out_float_only)
...
@@ -2561,21 +2561,21 @@ round_half_to_even = RoundHalfToEven(same_out_float_only)
def
round_half_away_from_zero_
(
a
):
def
round_half_away_from_zero_
(
a
):
if
a
>
0
:
if
a
>
0
:
return
n
umpy
.
floor
(
a
+
0.5
)
return
n
p
.
floor
(
a
+
0.5
)
else
:
else
:
return
n
umpy
.
ceil
(
a
-
0.5
)
return
n
p
.
ceil
(
a
-
0.5
)
round_half_away_from_zero_vec64
=
n
umpy
.
vectorize
(
round_half_away_from_zero_vec64
=
n
p
.
vectorize
(
round_half_away_from_zero_
,
round_half_away_from_zero_
,
doc
=
'round_half_away_from_zero_vec64'
)
doc
=
'round_half_away_from_zero_vec64'
)
round_half_away_from_zero_vec32
=
n
umpy
.
vectorize
(
round_half_away_from_zero_vec32
=
n
p
.
vectorize
(
round_half_away_from_zero_
,
round_half_away_from_zero_
,
doc
=
'round_half_away_from_zero_vec32'
,
doc
=
'round_half_away_from_zero_vec32'
,
otypes
=
[
'float32'
])
otypes
=
[
'float32'
])
def
round_half_away_from_zero_vec
(
a
):
def
round_half_away_from_zero_vec
(
a
):
if
getattr
(
a
,
'dtype'
,
None
)
==
n
umpy
.
float32
:
if
getattr
(
a
,
'dtype'
,
None
)
==
n
p
.
float32
:
return
round_half_away_from_zero_vec32
(
a
)
return
round_half_away_from_zero_vec32
(
a
)
return
round_half_away_from_zero_vec64
(
a
)
return
round_half_away_from_zero_vec64
(
a
)
...
@@ -2653,7 +2653,7 @@ class Inv(UnaryScalarOp):
...
@@ -2653,7 +2653,7 @@ class Inv(UnaryScalarOp):
"""
"""
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
n
umpy
.
float32
(
1.0
)
/
x
return
n
p
.
float32
(
1.0
)
/
x
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2691,8 +2691,8 @@ class Log(UnaryScalarOp):
...
@@ -2691,8 +2691,8 @@ class Log(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
log
(
x
,
sig
=
'f'
)
return
n
p
.
log
(
x
,
sig
=
'f'
)
return
n
umpy
.
log
(
x
)
return
n
p
.
log
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2733,8 +2733,8 @@ class Log2(UnaryScalarOp):
...
@@ -2733,8 +2733,8 @@ class Log2(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
log2
(
x
,
sig
=
'f'
)
return
n
p
.
log2
(
x
,
sig
=
'f'
)
return
n
umpy
.
log2
(
x
)
return
n
p
.
log2
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2747,7 +2747,7 @@ class Log2(UnaryScalarOp):
...
@@ -2747,7 +2747,7 @@ class Log2(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
return
gz
/
(
x
*
n
umpy
.
asarray
(
math
.
log
(
2.0
))
.
astype
(
x
.
dtype
)),
return
gz
/
(
x
*
n
p
.
asarray
(
math
.
log
(
2.0
))
.
astype
(
x
.
dtype
)),
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2772,8 +2772,8 @@ class Log10(UnaryScalarOp):
...
@@ -2772,8 +2772,8 @@ class Log10(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
log10
(
x
,
sig
=
'f'
)
return
n
p
.
log10
(
x
,
sig
=
'f'
)
return
n
umpy
.
log10
(
x
)
return
n
p
.
log10
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2786,7 +2786,7 @@ class Log10(UnaryScalarOp):
...
@@ -2786,7 +2786,7 @@ class Log10(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
return
gz
/
(
x
*
n
umpy
.
log
(
10.0
)),
return
gz
/
(
x
*
n
p
.
log
(
10.0
)),
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2809,8 +2809,8 @@ class Log1p(UnaryScalarOp):
...
@@ -2809,8 +2809,8 @@ class Log1p(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
log1p
(
x
,
sig
=
'f'
)
return
n
p
.
log1p
(
x
,
sig
=
'f'
)
return
n
umpy
.
log1p
(
x
)
return
n
p
.
log1p
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2844,8 +2844,8 @@ class Exp(UnaryScalarOp):
...
@@ -2844,8 +2844,8 @@ class Exp(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
exp
(
x
,
sig
=
'f'
)
return
n
p
.
exp
(
x
,
sig
=
'f'
)
return
n
umpy
.
exp
(
x
)
return
n
p
.
exp
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2877,8 +2877,8 @@ class Exp2(UnaryScalarOp):
...
@@ -2877,8 +2877,8 @@ class Exp2(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
exp2
(
x
,
sig
=
'f'
)
return
n
p
.
exp2
(
x
,
sig
=
'f'
)
return
n
umpy
.
exp2
(
x
)
return
n
p
.
exp2
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2891,7 +2891,7 @@ class Exp2(UnaryScalarOp):
...
@@ -2891,7 +2891,7 @@ class Exp2(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
return
gz
*
exp2
(
x
)
*
log
(
n
umpy
.
cast
[
x
.
type
](
2
)),
return
gz
*
exp2
(
x
)
*
log
(
n
p
.
cast
[
x
.
type
](
2
)),
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2910,8 +2910,8 @@ class Expm1(UnaryScalarOp):
...
@@ -2910,8 +2910,8 @@ class Expm1(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
expm1
(
x
,
sig
=
'f'
)
return
n
p
.
expm1
(
x
,
sig
=
'f'
)
return
n
umpy
.
expm1
(
x
)
return
n
p
.
expm1
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -2972,8 +2972,8 @@ class Sqrt(UnaryScalarOp):
...
@@ -2972,8 +2972,8 @@ class Sqrt(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
sqrt
(
x
,
sig
=
'f'
)
return
n
p
.
sqrt
(
x
,
sig
=
'f'
)
return
n
umpy
.
sqrt
(
x
)
return
n
p
.
sqrt
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3005,8 +3005,8 @@ class Deg2Rad(UnaryScalarOp):
...
@@ -3005,8 +3005,8 @@ class Deg2Rad(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
deg2rad
(
x
,
sig
=
'f'
)
return
n
p
.
deg2rad
(
x
,
sig
=
'f'
)
return
n
umpy
.
deg2rad
(
x
)
return
n
p
.
deg2rad
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3019,7 +3019,7 @@ class Deg2Rad(UnaryScalarOp):
...
@@ -3019,7 +3019,7 @@ class Deg2Rad(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
return
gz
*
n
umpy
.
asarray
(
numpy
.
pi
/
180
,
gz
.
type
),
return
gz
*
n
p
.
asarray
(
np
.
pi
/
180
,
gz
.
type
),
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3038,8 +3038,8 @@ class Rad2Deg(UnaryScalarOp):
...
@@ -3038,8 +3038,8 @@ class Rad2Deg(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
rad2deg
(
x
,
sig
=
'f'
)
return
n
p
.
rad2deg
(
x
,
sig
=
'f'
)
return
n
umpy
.
rad2deg
(
x
)
return
n
p
.
rad2deg
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3052,7 +3052,7 @@ class Rad2Deg(UnaryScalarOp):
...
@@ -3052,7 +3052,7 @@ class Rad2Deg(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
return
gz
*
n
umpy
.
asarray
(
180.
/
numpy
.
pi
,
gz
.
type
),
return
gz
*
n
p
.
asarray
(
180.
/
np
.
pi
,
gz
.
type
),
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3073,8 +3073,8 @@ class Cos(UnaryScalarOp):
...
@@ -3073,8 +3073,8 @@ class Cos(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
cos
(
x
,
sig
=
'f'
)
return
n
p
.
cos
(
x
,
sig
=
'f'
)
return
n
umpy
.
cos
(
x
)
return
n
p
.
cos
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3106,8 +3106,8 @@ class ArcCos(UnaryScalarOp):
...
@@ -3106,8 +3106,8 @@ class ArcCos(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
arccos
(
x
,
sig
=
'f'
)
return
n
p
.
arccos
(
x
,
sig
=
'f'
)
return
n
umpy
.
arccos
(
x
)
return
n
p
.
arccos
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3120,7 +3120,7 @@ class ArcCos(UnaryScalarOp):
...
@@ -3120,7 +3120,7 @@ class ArcCos(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
return
-
gz
/
sqrt
(
n
umpy
.
cast
[
x
.
type
](
1
)
-
sqr
(
x
)),
return
-
gz
/
sqrt
(
n
p
.
cast
[
x
.
type
](
1
)
-
sqr
(
x
)),
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3141,8 +3141,8 @@ class Sin(UnaryScalarOp):
...
@@ -3141,8 +3141,8 @@ class Sin(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
sin
(
x
,
sig
=
'f'
)
return
n
p
.
sin
(
x
,
sig
=
'f'
)
return
n
umpy
.
sin
(
x
)
return
n
p
.
sin
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3174,8 +3174,8 @@ class ArcSin(UnaryScalarOp):
...
@@ -3174,8 +3174,8 @@ class ArcSin(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
arcsin
(
x
,
sig
=
'f'
)
return
n
p
.
arcsin
(
x
,
sig
=
'f'
)
return
n
umpy
.
arcsin
(
x
)
return
n
p
.
arcsin
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3188,7 +3188,7 @@ class ArcSin(UnaryScalarOp):
...
@@ -3188,7 +3188,7 @@ class ArcSin(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
return
gz
/
sqrt
(
n
umpy
.
cast
[
x
.
type
](
1
)
-
sqr
(
x
)),
return
gz
/
sqrt
(
n
p
.
cast
[
x
.
type
](
1
)
-
sqr
(
x
)),
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3207,8 +3207,8 @@ class Tan(UnaryScalarOp):
...
@@ -3207,8 +3207,8 @@ class Tan(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
tan
(
x
,
sig
=
'f'
)
return
n
p
.
tan
(
x
,
sig
=
'f'
)
return
n
umpy
.
tan
(
x
)
return
n
p
.
tan
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3240,8 +3240,8 @@ class ArcTan(UnaryScalarOp):
...
@@ -3240,8 +3240,8 @@ class ArcTan(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
arctan
(
x
,
sig
=
'f'
)
return
n
p
.
arctan
(
x
,
sig
=
'f'
)
return
n
umpy
.
arctan
(
x
)
return
n
p
.
arctan
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3254,7 +3254,7 @@ class ArcTan(UnaryScalarOp):
...
@@ -3254,7 +3254,7 @@ class ArcTan(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
return
gz
/
(
n
umpy
.
cast
[
x
.
type
](
1
)
+
sqr
(
x
)),
return
gz
/
(
n
p
.
cast
[
x
.
type
](
1
)
+
sqr
(
x
)),
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3275,8 +3275,8 @@ class ArcTan2(BinaryScalarOp):
...
@@ -3275,8 +3275,8 @@ class ArcTan2(BinaryScalarOp):
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
y_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
y_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
y_dtype
in
(
'int8'
,
'uint8'
):
if
y_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
arctan2
(
y
,
x
,
sig
=
'f'
)
return
n
p
.
arctan2
(
y
,
x
,
sig
=
'f'
)
return
n
umpy
.
arctan2
(
y
,
x
)
return
n
p
.
arctan2
(
y
,
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
y
,
x
)
=
inputs
(
y
,
x
)
=
inputs
...
@@ -3322,8 +3322,8 @@ class Cosh(UnaryScalarOp):
...
@@ -3322,8 +3322,8 @@ class Cosh(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
cosh
(
x
,
sig
=
'f'
)
return
n
p
.
cosh
(
x
,
sig
=
'f'
)
return
n
umpy
.
cosh
(
x
)
return
n
p
.
cosh
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3355,8 +3355,8 @@ class ArcCosh(UnaryScalarOp):
...
@@ -3355,8 +3355,8 @@ class ArcCosh(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
arccosh
(
x
,
sig
=
'f'
)
return
n
p
.
arccosh
(
x
,
sig
=
'f'
)
return
n
umpy
.
arccosh
(
x
)
return
n
p
.
arccosh
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3369,7 +3369,7 @@ class ArcCosh(UnaryScalarOp):
...
@@ -3369,7 +3369,7 @@ class ArcCosh(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
return
gz
/
sqrt
(
sqr
(
x
)
-
n
umpy
.
cast
[
x
.
type
](
1
)),
return
gz
/
sqrt
(
sqr
(
x
)
-
n
p
.
cast
[
x
.
type
](
1
)),
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3392,8 +3392,8 @@ class Sinh(UnaryScalarOp):
...
@@ -3392,8 +3392,8 @@ class Sinh(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
sinh
(
x
,
sig
=
'f'
)
return
n
p
.
sinh
(
x
,
sig
=
'f'
)
return
n
umpy
.
sinh
(
x
)
return
n
p
.
sinh
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3425,8 +3425,8 @@ class ArcSinh(UnaryScalarOp):
...
@@ -3425,8 +3425,8 @@ class ArcSinh(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
arcsinh
(
x
,
sig
=
'f'
)
return
n
p
.
arcsinh
(
x
,
sig
=
'f'
)
return
n
umpy
.
arcsinh
(
x
)
return
n
p
.
arcsinh
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3439,7 +3439,7 @@ class ArcSinh(UnaryScalarOp):
...
@@ -3439,7 +3439,7 @@ class ArcSinh(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
return
gz
/
sqrt
(
sqr
(
x
)
+
n
umpy
.
cast
[
x
.
type
](
1
)),
return
gz
/
sqrt
(
sqr
(
x
)
+
n
p
.
cast
[
x
.
type
](
1
)),
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3463,8 +3463,8 @@ class Tanh(UnaryScalarOp):
...
@@ -3463,8 +3463,8 @@ class Tanh(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
tanh
(
x
,
sig
=
'f'
)
return
n
p
.
tanh
(
x
,
sig
=
'f'
)
return
n
umpy
.
tanh
(
x
)
return
n
p
.
tanh
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3496,8 +3496,8 @@ class ArcTanh(UnaryScalarOp):
...
@@ -3496,8 +3496,8 @@ class ArcTanh(UnaryScalarOp):
# half-precision (float16), where we want float32.
# half-precision (float16), where we want float32.
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
x_dtype
=
str
(
getattr
(
x
,
'dtype'
,
''
))
if
x_dtype
in
(
'int8'
,
'uint8'
):
if
x_dtype
in
(
'int8'
,
'uint8'
):
return
n
umpy
.
arctanh
(
x
,
sig
=
'f'
)
return
n
p
.
arctanh
(
x
,
sig
=
'f'
)
return
n
umpy
.
arctanh
(
x
)
return
n
p
.
arctanh
(
x
)
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
def
L_op
(
self
,
inputs
,
outputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3510,7 +3510,7 @@ class ArcTanh(UnaryScalarOp):
...
@@ -3510,7 +3510,7 @@ class ArcTanh(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
return
gz
/
(
n
umpy
.
cast
[
x
.
type
](
1
)
-
sqr
(
x
)),
return
gz
/
(
n
p
.
cast
[
x
.
type
](
1
)
-
sqr
(
x
)),
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3530,7 +3530,7 @@ class Real(UnaryScalarOp):
...
@@ -3530,7 +3530,7 @@ class Real(UnaryScalarOp):
# nfunc_spec = ('real', 1, 1)
# nfunc_spec = ('real', 1, 1)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
n
umpy
.
real
(
x
)
return
n
p
.
real
(
x
)
def
grad
(
self
,
inputs
,
gout
):
def
grad
(
self
,
inputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3544,7 +3544,7 @@ class Imag(UnaryScalarOp):
...
@@ -3544,7 +3544,7 @@ class Imag(UnaryScalarOp):
nfunc_spec
=
(
'imag'
,
1
,
1
)
nfunc_spec
=
(
'imag'
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
n
umpy
.
imag
(
x
)
return
n
p
.
imag
(
x
)
def
grad
(
self
,
inputs
,
gout
):
def
grad
(
self
,
inputs
,
gout
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3563,7 +3563,7 @@ class Angle(UnaryScalarOp):
...
@@ -3563,7 +3563,7 @@ class Angle(UnaryScalarOp):
nfunc_spec
=
(
'angle'
,
1
,
1
)
nfunc_spec
=
(
'angle'
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
n
umpy
.
angle
(
x
)
return
n
p
.
angle
(
x
)
def
grad
(
self
,
inputs
,
gout
):
def
grad
(
self
,
inputs
,
gout
):
# y = x.imag
# y = x.imag
...
@@ -3610,7 +3610,7 @@ class Complex(BinaryScalarOp):
...
@@ -3610,7 +3610,7 @@ class Complex(BinaryScalarOp):
return
[
complex64
]
return
[
complex64
]
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
n
umpy
.
complex
(
x
,
y
)
return
n
p
.
complex
(
x
,
y
)
def
grad
(
self
,
inputs
,
gout
):
def
grad
(
self
,
inputs
,
gout
):
(
x
,
y
)
=
inputs
(
x
,
y
)
=
inputs
...
@@ -3624,7 +3624,7 @@ class Conj(UnaryScalarOp):
...
@@ -3624,7 +3624,7 @@ class Conj(UnaryScalarOp):
nfunc_spec
=
(
'conj'
,
1
,
1
)
nfunc_spec
=
(
'conj'
,
1
,
1
)
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
n
umpy
.
conj
(
x
)
return
n
p
.
conj
(
x
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,)
=
inputs
(
x
,)
=
inputs
...
@@ -3646,12 +3646,12 @@ class ComplexFromPolar(BinaryScalarOp):
...
@@ -3646,12 +3646,12 @@ class ComplexFromPolar(BinaryScalarOp):
def
impl
(
self
,
r
,
theta
):
def
impl
(
self
,
r
,
theta
):
if
r
<
0
:
if
r
<
0
:
raise
ValueError
(
'polar radius must be non-negative'
,
r
)
raise
ValueError
(
'polar radius must be non-negative'
,
r
)
x
=
r
*
n
umpy
.
cos
(
theta
)
x
=
r
*
n
p
.
cos
(
theta
)
y
=
r
*
n
umpy
.
sin
(
theta
)
y
=
r
*
n
p
.
sin
(
theta
)
if
x
.
dtype
==
'float32'
:
if
x
.
dtype
==
'float32'
:
return
n
umpy
.
complex64
(
numpy
.
complex
(
x
,
y
))
return
n
p
.
complex64
(
np
.
complex
(
x
,
y
))
else
:
else
:
return
n
umpy
.
complex128
(
numpy
.
complex
(
x
,
y
))
return
n
p
.
complex128
(
np
.
complex
(
x
,
y
))
def
grad
(
self
,
inputs
,
gout
):
def
grad
(
self
,
inputs
,
gout
):
(
r
,
theta
)
=
inputs
(
r
,
theta
)
=
inputs
...
...
theano/scalar/basic_scipy.py
浏览文件 @
e5d09827
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
# Definitions of theano.scalar ops that have their python implementation taken
# Definitions of theano.scalar ops that have their python implementation taken
# from SciPy. As SciPy is not always available, we treat them separately.
# from SciPy. As SciPy is not always available, we treat them separately.
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano.gradient
import
grad_not_implemented
from
theano.gradient
import
grad_not_implemented
...
@@ -43,7 +43,7 @@ class Erf(UnaryScalarOp):
...
@@ -43,7 +43,7 @@ class Erf(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
cst
=
n
umpy
.
asarray
(
2.
/
numpy
.
sqrt
(
numpy
.
pi
),
cst
=
n
p
.
asarray
(
2.
/
np
.
sqrt
(
np
.
pi
),
dtype
=
upcast
(
x
.
type
.
dtype
,
gz
.
type
.
dtype
))
dtype
=
upcast
(
x
.
type
.
dtype
,
gz
.
type
.
dtype
))
return
gz
*
cst
*
exp
(
-
x
*
x
),
return
gz
*
cst
*
exp
(
-
x
*
x
),
...
@@ -74,7 +74,7 @@ class Erfc(UnaryScalarOp):
...
@@ -74,7 +74,7 @@ class Erfc(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
cst
=
n
umpy
.
asarray
(
2.
/
numpy
.
sqrt
(
numpy
.
pi
),
cst
=
n
p
.
asarray
(
2.
/
np
.
sqrt
(
np
.
pi
),
dtype
=
upcast
(
x
.
type
.
dtype
,
gz
.
type
.
dtype
))
dtype
=
upcast
(
x
.
type
.
dtype
,
gz
.
type
.
dtype
))
return
-
gz
*
cst
*
exp
(
-
x
*
x
),
return
-
gz
*
cst
*
exp
(
-
x
*
x
),
...
@@ -120,7 +120,7 @@ class Erfcx(UnaryScalarOp):
...
@@ -120,7 +120,7 @@ class Erfcx(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
cst
=
n
umpy
.
asarray
(
2.
/
numpy
.
sqrt
(
numpy
.
pi
),
cst
=
n
p
.
asarray
(
2.
/
np
.
sqrt
(
np
.
pi
),
dtype
=
upcast
(
x
.
type
.
dtype
,
gz
.
type
.
dtype
))
dtype
=
upcast
(
x
.
type
.
dtype
,
gz
.
type
.
dtype
))
return
gz
*
(
-
cst
+
(
2.
*
x
)
*
erfcx
(
x
)),
return
gz
*
(
-
cst
+
(
2.
*
x
)
*
erfcx
(
x
)),
...
@@ -155,7 +155,7 @@ class Erfinv(UnaryScalarOp):
...
@@ -155,7 +155,7 @@ class Erfinv(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
cst
=
n
umpy
.
asarray
(
numpy
.
sqrt
(
numpy
.
pi
)
/
2.
,
cst
=
n
p
.
asarray
(
np
.
sqrt
(
np
.
pi
)
/
2.
,
dtype
=
upcast
(
x
.
type
.
dtype
,
gz
.
type
.
dtype
))
dtype
=
upcast
(
x
.
type
.
dtype
,
gz
.
type
.
dtype
))
return
gz
*
cst
*
exp
(
erfinv
(
x
)
**
2
),
return
gz
*
cst
*
exp
(
erfinv
(
x
)
**
2
),
...
@@ -188,7 +188,7 @@ class Erfcinv(UnaryScalarOp):
...
@@ -188,7 +188,7 @@ class Erfcinv(UnaryScalarOp):
else
:
else
:
return
[
x
.
zeros_like
()]
return
[
x
.
zeros_like
()]
cst
=
n
umpy
.
asarray
(
numpy
.
sqrt
(
numpy
.
pi
)
/
2.
,
cst
=
n
p
.
asarray
(
np
.
sqrt
(
np
.
pi
)
/
2.
,
dtype
=
upcast
(
x
.
type
.
dtype
,
gz
.
type
.
dtype
))
dtype
=
upcast
(
x
.
type
.
dtype
,
gz
.
type
.
dtype
))
return
-
gz
*
cst
*
exp
(
erfcinv
(
x
)
**
2
),
return
-
gz
*
cst
*
exp
(
erfcinv
(
x
)
**
2
),
...
...
theano/scalar/sharedvar.py
浏览文件 @
e5d09827
...
@@ -16,7 +16,7 @@ way (as scan does) to create a shared variable of this kind.
...
@@ -16,7 +16,7 @@ way (as scan does) to create a shared variable of this kind.
"""
"""
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
from
six
import
integer_types
from
six
import
integer_types
from
theano.compile
import
SharedVariable
from
theano.compile
import
SharedVariable
...
@@ -48,15 +48,15 @@ def shared(value, name=None, strict=False, allow_downcast=None):
...
@@ -48,15 +48,15 @@ def shared(value, name=None, strict=False, allow_downcast=None):
We implement this using 0-d tensors for now.
We implement this using 0-d tensors for now.
"""
"""
if
not
isinstance
(
value
,
(
n
umpy
.
number
,
float
,
integer_types
,
complex
)):
if
not
isinstance
(
value
,
(
n
p
.
number
,
float
,
integer_types
,
complex
)):
raise
TypeError
()
raise
TypeError
()
try
:
try
:
dtype
=
value
.
dtype
dtype
=
value
.
dtype
except
AttributeError
:
except
AttributeError
:
dtype
=
n
umpy
.
asarray
(
value
)
.
dtype
dtype
=
n
p
.
asarray
(
value
)
.
dtype
dtype
=
str
(
dtype
)
dtype
=
str
(
dtype
)
value
=
getattr
(
n
umpy
,
dtype
)(
value
)
value
=
getattr
(
n
p
,
dtype
)(
value
)
scalar_type
=
Scalar
(
dtype
=
dtype
)
scalar_type
=
Scalar
(
dtype
=
dtype
)
rval
=
ScalarSharedVariable
(
rval
=
ScalarSharedVariable
(
type
=
scalar_type
,
type
=
scalar_type
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论