Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
c634a848
P
Paddle
项目概览
wmsofts
/
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,发现更多精彩内容 >>
提交
c634a848
编写于
9月 28, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add SetConstant method in math_function.h
上级
7a6fcc7d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
1 deletion
+31
-1
paddle/operators/math/CMakeLists.txt
paddle/operators/math/CMakeLists.txt
+2
-1
paddle/operators/math/math_function.h
paddle/operators/math/math_function.h
+8
-0
paddle/operators/math/math_function_test.cc
paddle/operators/math/math_function_test.cc
+21
-0
未找到文件。
paddle/operators/math/CMakeLists.txt
浏览文件 @
c634a848
if
(
WITH_GPU
)
nv_library
(
math_function SRCS math_function.cc math_function.cu im2col.cc
im2col.cu DEPS cblas device_context operator
)
nv_test
(
math_function_test SRCS math_function_test.cc DEPS math_function tensor
)
nv_library
(
softmax_function SRCS softmax.cc softmax.cu
DEPS operator
)
nv_library
(
cross_entropy_function SRCS cross_entropy.cc cross_entropy.cu
...
...
@@ -8,9 +9,9 @@ if(WITH_GPU)
else
()
cc_library
(
math_function SRCS math_function.cc im2col.cc
DEPS cblas device_context operator
)
cc_test
(
math_function_test SRCS math_function_test.cc DEPS math_function tensor
)
cc_library
(
softmax_function SRCS softmax.cc DEPS operator
)
cc_library
(
cross_entropy_function SRCS cross_entropy.cc DEPS operator
)
endif
()
nv_test
(
math_function_test SRCS math_function_test.cc DEPS math_function tensor
)
cc_test
(
im2col_test SRCS im2col_test.cc DEPS math_function tensor
)
paddle/operators/math/math_function.h
浏览文件 @
c634a848
...
...
@@ -52,6 +52,7 @@ int LAPACKE_dgetri(int matrix_layout, int n, double* a, int lda,
#include <cmath>
#include "paddle/framework/eigen.h"
#include "paddle/framework/tensor.h"
#include "paddle/platform/device_context.h"
#include "paddle/platform/enforce.h"
...
...
@@ -84,6 +85,13 @@ void matmul(const platform::DeviceContext& context,
const
framework
::
Tensor
&
matrix_b
,
bool
trans_b
,
T
alpha
,
framework
::
Tensor
*
matrix_out
,
T
beta
);
template
<
typename
Place
,
typename
T
>
void
SetConstant
(
const
platform
::
DeviceContext
&
context
,
framework
::
Tensor
*
tensor
,
T
num
)
{
auto
t
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
tensor
);
t
.
device
(
*
context
.
GetEigenDevice
<
Place
>
())
=
t
.
constant
(
static_cast
<
T
>
(
num
));
}
}
// namespace math
}
// namespace operators
}
// namespace paddle
paddle/operators/math/math_function_test.cc
浏览文件 @
c634a848
...
...
@@ -243,3 +243,24 @@ TEST(math_function, gemm_trans_clbas) {
EXPECT_EQ
(
input3_ptr
[
6
],
86
);
EXPECT_EQ
(
input3_ptr
[
7
],
99
);
}
TEST
(
math_function
,
zero
)
{
paddle
::
framework
::
Tensor
tensor
;
auto
*
cpu_place
=
new
paddle
::
platform
::
CPUPlace
();
float
*
t
=
tensor
.
mutable_data
<
float
>
({
2
,
2
},
*
cpu_place
);
paddle
::
platform
::
CPUDeviceContext
context
(
*
cpu_place
);
paddle
::
operators
::
math
::
SetConstant
<
paddle
::
platform
::
CPUPlace
,
float
>
(
context
,
&
tensor
,
0
);
EXPECT_EQ
(
t
[
0
],
0
);
EXPECT_EQ
(
t
[
1
],
0
);
EXPECT_EQ
(
t
[
2
],
0
);
EXPECT_EQ
(
t
[
3
],
0
);
paddle
::
operators
::
math
::
SetConstant
<
paddle
::
platform
::
CPUPlace
,
float
>
(
context
,
&
tensor
,
1
);
EXPECT_EQ
(
t
[
0
],
1
);
EXPECT_EQ
(
t
[
1
],
1
);
EXPECT_EQ
(
t
[
2
],
1
);
EXPECT_EQ
(
t
[
3
],
1
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录