Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
afeixing77
Paddle
提交
dc070ecf
P
Paddle
项目概览
afeixing77
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
dc070ecf
编写于
11月 30, 2020
作者:
J
joejiong
提交者:
GitHub
11月 30, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove cast from paddle.pow api (#29134)
As the title
上级
4056c4f1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
8 addition
and
76 deletion
+8
-76
python/paddle/fluid/tests/unittests/test_pow.py
python/paddle/fluid/tests/unittests/test_pow.py
+8
-70
python/paddle/tensor/math.py
python/paddle/tensor/math.py
+0
-6
未找到文件。
python/paddle/fluid/tests/unittests/test_pow.py
浏览文件 @
dc070ecf
...
...
@@ -13,12 +13,13 @@
# limitations under the License.
from
__future__
import
print_function
import
unittest
import
numpy
as
np
import
paddle
import
paddle.tensor
as
tensor
import
paddle.fluid
as
fluid
from
paddle.static
import
Program
,
program_guard
import
numpy
as
np
import
unittest
DYNAMIC
=
1
STATIC
=
2
...
...
@@ -49,8 +50,8 @@ def _run_power(mode, x, y):
x_
=
paddle
.
static
.
data
(
name
=
"x"
,
shape
=
x
.
shape
,
dtype
=
x
.
dtype
)
y_
=
y
res
=
paddle
.
pow
(
x_
,
y_
)
place
=
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
place
=
paddle
.
CPUPlace
()
exe
=
paddle
.
static
.
Executor
(
place
)
outs
=
exe
.
run
(
feed
=
{
'x'
:
x
},
fetch_list
=
[
res
])
return
outs
[
0
]
# y is tensor
...
...
@@ -59,8 +60,8 @@ def _run_power(mode, x, y):
x_
=
paddle
.
static
.
data
(
name
=
"x"
,
shape
=
x
.
shape
,
dtype
=
x
.
dtype
)
y_
=
paddle
.
static
.
data
(
name
=
"y"
,
shape
=
y
.
shape
,
dtype
=
y
.
dtype
)
res
=
paddle
.
pow
(
x_
,
y_
)
place
=
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
place
=
paddle
.
CPUPlace
()
exe
=
paddle
.
static
.
Executor
(
place
)
outs
=
exe
.
run
(
feed
=
{
'x'
:
x
,
'y'
:
y
},
fetch_list
=
[
res
])
return
outs
[
0
]
...
...
@@ -105,24 +106,6 @@ class TestPowerAPI(unittest.TestCase):
res
=
_run_power
(
STATIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
# test 1-d float tensor ** 1-d int tensor
dims
=
(
np
.
random
.
randint
(
200
,
300
),
)
x
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
float64
)
y
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
int64
)
res
=
_run_power
(
DYNAMIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
res
=
_run_power
(
STATIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
# test 1-d int tensor ** 1-d float tensor
dims
=
(
np
.
random
.
randint
(
200
,
300
),
)
x
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
int64
)
y
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
float64
)
res
=
_run_power
(
DYNAMIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
res
=
_run_power
(
STATIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
# test 1-d int tensor ** 1-d int tensor
dims
=
(
np
.
random
.
randint
(
200
,
300
),
)
x
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
int64
)
...
...
@@ -141,24 +124,6 @@ class TestPowerAPI(unittest.TestCase):
res
=
_run_power
(
STATIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
# test 1-d int tensor ** 1-d int tensor
dims
=
(
np
.
random
.
randint
(
200
,
300
),
)
x
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
int64
)
y
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
int32
)
res
=
_run_power
(
DYNAMIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
res
=
_run_power
(
STATIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
# test 1-d int tensor ** 1-d int tensor
dims
=
(
np
.
random
.
randint
(
200
,
300
),
)
x
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
int32
)
y
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
int64
)
res
=
_run_power
(
DYNAMIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
res
=
_run_power
(
STATIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
# test 1-d int tensor ** 1-d int tensor
dims
=
(
np
.
random
.
randint
(
200
,
300
),
)
x
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
float32
)
...
...
@@ -168,33 +133,6 @@ class TestPowerAPI(unittest.TestCase):
res
=
_run_power
(
STATIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
# test 1-d int tensor ** 1-d int tensor
dims
=
(
np
.
random
.
randint
(
200
,
300
),
)
x
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
float64
)
y
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
float32
)
res
=
_run_power
(
DYNAMIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
res
=
_run_power
(
STATIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
# test 1-d int tensor ** 1-d int tensor
dims
=
(
np
.
random
.
randint
(
200
,
300
),
)
x
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
float64
)
y
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
int32
)
res
=
_run_power
(
DYNAMIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
res
=
_run_power
(
STATIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
# test 1-d int tensor ** 1-d int tensor
dims
=
(
np
.
random
.
randint
(
200
,
300
),
)
x
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
float32
)
y
=
(
np
.
random
.
rand
(
*
dims
)
*
10
).
astype
(
np
.
int64
)
res
=
_run_power
(
DYNAMIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
res
=
_run_power
(
STATIC
,
x
,
y
)
self
.
assertTrue
(
np
.
allclose
(
res
,
np
.
power
(
x
,
y
)))
# test broadcast
dims
=
(
np
.
random
.
randint
(
1
,
10
),
np
.
random
.
randint
(
5
,
10
),
np
.
random
.
randint
(
5
,
10
))
...
...
python/paddle/tensor/math.py
浏览文件 @
dc070ecf
...
...
@@ -184,9 +184,6 @@ def pow(x, y, name=None):
if
isinstance
(
y
,
(
int
,
float
)):
return
core
.
ops
.
pow
(
x
,
'factor'
,
y
)
elif
isinstance
(
y
,
(
paddle
.
Tensor
,
Variable
)):
if
x
.
dtype
!=
y
.
dtype
:
y
=
cast
(
y
,
dtype
=
'float64'
)
x
=
cast
(
x
,
dtype
=
'float64'
)
return
_elementwise_op_in_dygraph
(
x
,
y
,
axis
=-
1
,
act
=
None
,
op_name
=
'elementwise_pow'
)
else
:
...
...
@@ -204,9 +201,6 @@ def pow(x, y, name=None):
elif
isinstance
(
y
,
(
paddle
.
Tensor
,
Variable
)):
# TODO A potential speed improvement is supporting different types in C++ and removing the cast ops here
helper
=
LayerHelper
(
'elementwise_pow'
,
**
locals
())
if
x
.
dtype
!=
y
.
dtype
:
y
=
cast
(
y
,
dtype
=
'float64'
)
x
=
cast
(
x
,
dtype
=
'float64'
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
x
.
dtype
)
return
_elementwise_op
(
LayerHelper
(
'elementwise_pow'
,
**
locals
()))
else
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录