Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
bbe8f7bd
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
bbe8f7bd
编写于
7月 20, 2020
作者:
L
LutaoChu
提交者:
GitHub
7月 20, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update cross op parameters for API 2.0
* update cross op parameters
上级
1ab60544
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
34 deletion
+45
-34
python/paddle/fluid/tests/unittests/test_cross_op.py
python/paddle/fluid/tests/unittests/test_cross_op.py
+10
-2
python/paddle/tensor/linalg.py
python/paddle/tensor/linalg.py
+35
-32
未找到文件。
python/paddle/fluid/tests/unittests/test_cross_op.py
浏览文件 @
bbe8f7bd
...
...
@@ -79,7 +79,7 @@ class TestCrossAPI(unittest.TestCase):
with
program_guard
(
Program
(),
Program
()):
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
-
1
,
3
])
y
=
fluid
.
layers
.
data
(
name
=
'y'
,
shape
=
[
-
1
,
3
])
z
=
paddle
.
cross
(
x
,
y
,
dim
=
1
)
z
=
paddle
.
cross
(
x
,
y
,
axis
=
1
)
exe
=
fluid
.
Executor
(
fluid
.
CPUPlace
())
res
,
=
exe
.
run
(
feed
=
{
'x'
:
self
.
data_x
,
'y'
:
self
.
data_y
},
...
...
@@ -103,6 +103,14 @@ class TestCrossAPI(unittest.TestCase):
[
-
1.0
,
-
1.0
,
-
1.0
]])
self
.
assertTrue
(
np
.
allclose
(
expect_out
,
np
.
array
(
res
)))
# case 3:
with
program_guard
(
Program
(),
Program
()):
x
=
fluid
.
data
(
name
=
"x"
,
shape
=
[
-
1
,
3
],
dtype
=
"float32"
)
y
=
fluid
.
data
(
name
=
'y'
,
shape
=
[
-
1
,
3
],
dtype
=
'float32'
)
y_1
=
paddle
.
cross
(
x
,
y
,
name
=
'result'
)
self
.
assertEqual
((
'result'
in
y_1
.
name
),
True
)
def
test_dygraph_api
(
self
):
self
.
input_data
()
# case 1:
...
...
@@ -119,7 +127,7 @@ class TestCrossAPI(unittest.TestCase):
with
fluid
.
dygraph
.
guard
():
x
=
fluid
.
dygraph
.
to_variable
(
self
.
data_x
)
y
=
fluid
.
dygraph
.
to_variable
(
self
.
data_y
)
z
=
paddle
.
cross
(
x
,
y
,
dim
=
1
)
z
=
paddle
.
cross
(
x
,
y
,
axis
=
1
)
np_z
=
z
.
numpy
()
expect_out
=
np
.
array
([[
0.0
,
0.0
,
0.0
],
[
0.0
,
0.0
,
0.0
],
[
0.0
,
0.0
,
0.0
]])
...
...
python/paddle/tensor/linalg.py
浏览文件 @
bbe8f7bd
...
...
@@ -583,66 +583,69 @@ def t(input, name=None):
return
out
def
cross
(
input
,
other
,
dim
=
None
):
def
cross
(
x
,
y
,
axis
=
None
,
name
=
None
):
"""
:alias_main: paddle.cross
:alias: paddle.cross,paddle.tensor.cross,paddle.tensor.linalg.cross
Returns the cross product of vectors in dimension `dim` of the `input` and `other` tensor.
Inputs must have the same shape, and the
size of their dim-th dimension should be equla to 3.
If `
dim` is not given, it defaults to the first dimension found with the size
3.
Computes the cross product between two tensors along an axis.
Inputs must have the same shape, and the
length of their axes should be equal to 3.
If `
axis` is not given, it defaults to the first axis found with the length
3.
Args:
input (Variable): The first input tensor variable.
other (Variable): The second input tensor variable.
dim (int): The dimension to take the cross-product in.
x (Variable): The first input tensor variable.
y (Variable): The second input tensor variable.
axis (int, optional): The axis along which to compute the cross product. It defaults to the first axis found with the length 3.
name (str, optional): The default value is None. Normally there is no need for
user to set this property. For more information, please refer to :ref:`api_guide_Name`
Returns:
Variable: A Tensor with same data type as `
input
`.
Variable: A Tensor with same data type as `
x
`.
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
from paddle.imperative import to_variable
import numpy as np
paddle.enable_imperative()
data_x = np.array([[1.0, 1.0, 1.0],
[2.0, 2.0, 2.0],
[3.0, 3.0, 3.0]])
data_y = np.array([[1.0, 1.0, 1.0],
[1.0, 1.0, 1.0],
[1.0, 1.0, 1.0]])
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(data_x)
y = fluid.dygraph.to_variable(data_
y)
out_z1 = paddle.cross(x, y
)
print(out_z1.numpy())
#[[-1. -1. -1
.]
# [ 2. 2. 2.
]
# [-1. -1. -1.]]
out_z2 = paddle.cross(x, y, dim
=1)
print(out_
z2.numpy())
#
[[0. 0. 0.]
#
[0. 0. 0.]
#
[0. 0. 0.]]
x = to_variable(data_x)
y = to_variable(data_y)
z1 = paddle.cross(x,
y)
print(z1.numpy()
)
# [[-1. -1. -1.]
# [ 2. 2. 2
.]
# [-1. -1. -1.]
]
z2 = paddle.cross(x, y, axis
=1)
print(
z2.numpy())
#
[[0. 0. 0.]
#
[0. 0. 0.]
#
[0. 0. 0.]]
"""
helper
=
LayerHelper
(
"cross"
,
**
locals
())
if
in_dygraph_mode
():
if
dim
:
return
core
.
ops
.
cross
(
input
,
other
,
'dim'
,
dim
)
if
axis
:
return
core
.
ops
.
cross
(
x
,
y
,
'dim'
,
axis
)
else
:
return
core
.
ops
.
cross
(
input
,
other
)
return
core
.
ops
.
cross
(
x
,
y
)
out
=
helper
.
create_variable_for_type_inference
(
input
.
dtype
)
helper
=
LayerHelper
(
"cross"
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
x
.
dtype
)
attrs
=
dict
()
if
dim
:
attrs
[
'dim'
]
=
dim
attrs
[
'dim'
]
=
axis
helper
.
append_op
(
type
=
'cross'
,
inputs
=
{
'X'
:
input
,
'Y'
:
other
},
inputs
=
{
'X'
:
x
,
'Y'
:
y
},
outputs
=
{
'Out'
:
out
},
attrs
=
attrs
)
return
out
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录