Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8c40bfd0
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2297
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8c40bfd0
编写于
11月 07, 2016
作者:
L
Liang Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make matrix well-conditioned when unittest inverse
上级
0c7ac3d9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
35 addition
and
5 deletion
+35
-5
paddle/math/Matrix.cpp
paddle/math/Matrix.cpp
+21
-0
paddle/math/Matrix.h
paddle/math/Matrix.h
+6
-0
paddle/math/tests/test_matrixCompare.cpp
paddle/math/tests/test_matrixCompare.cpp
+8
-5
未找到文件。
paddle/math/Matrix.cpp
浏览文件 @
8c40bfd0
...
...
@@ -202,6 +202,17 @@ void GpuMatrix::resetOne() {
CHECK
(
data_
!=
NULL
);
one
();
}
void
GpuMatrix
::
setDiag
(
real
value
)
{
CHECK
(
data_
!=
NULL
);
CHECK_EQ
(
height_
,
width_
);
zeroMem
();
for
(
size_t
i
=
0
;
i
<
height_
;
i
++
)
{
hl_memcpy_host2device
(
&
data_
[
i
*
stride_
+
i
],
&
value
,
sizeof
(
real
));
}
}
void
GpuMatrix
::
resize
(
size_t
newHeight
,
size_t
newWidth
)
{
size_t
newSize
=
newHeight
*
newWidth
;
if
(
NULL
==
memoryHandle_
.
get
()
||
...
...
@@ -1244,6 +1255,16 @@ void CpuMatrix::resetOne() {
BaseMatrix
::
one
();
}
void
CpuMatrix
::
setDiag
(
real
value
)
{
CHECK
(
data_
!=
NULL
);
CHECK_EQ
(
height_
,
width_
);
zeroMem
();
for
(
size_t
i
=
0
;
i
<
height_
;
i
++
)
{
data_
[
i
*
stride_
+
i
]
=
value
;
}
}
void
CpuMatrix
::
copyFrom
(
const
Matrix
&
src
)
{
CHECK
(
isContiguous
());
if
(
typeid
(
src
)
==
typeid
(
GpuMatrix
))
{
...
...
paddle/math/Matrix.h
浏览文件 @
8c40bfd0
...
...
@@ -195,6 +195,8 @@ public:
virtual
void
resetOne
()
{
LOG
(
FATAL
)
<<
"Not implemented"
;
}
virtual
void
setDiag
(
real
value
)
{
LOG
(
FATAL
)
<<
"Not implemented"
;
}
virtual
void
copyFrom
(
const
Matrix
&
src
)
{
LOG
(
FATAL
)
<<
"Not implemented"
;
}
virtual
void
trimFrom
(
const
CpuSparseMatrix
&
src
)
{
...
...
@@ -330,6 +332,7 @@ public:
virtual
MatrixPtr
getInverse
()
{
LOG
(
FATAL
)
<<
"Not implemented"
;
return
nullptr
;
}
/**
...
...
@@ -1016,6 +1019,7 @@ public:
void
zeroMem
();
void
resetOne
();
void
setDiag
(
real
value
);
void
resize
(
size_t
newHeight
,
size_t
newWidth
);
void
resize
(
size_t
newHeight
,
size_t
newWidth
,
...
...
@@ -1280,6 +1284,8 @@ public:
void
zeroMem
();
void
resetOne
();
void
setDiag
(
real
value
);
void
resize
(
size_t
newHeight
,
size_t
newWidth
);
void
resize
(
size_t
newHeight
,
size_t
newWidth
,
size_t
newNnz
,
/* used to allocate space */
...
...
paddle/math/tests/test_matrixCompare.cpp
浏览文件 @
8c40bfd0
...
...
@@ -647,20 +647,23 @@ void testMatrixInverse(int height) {
MatrixPtr
cpuI
=
std
::
make_shared
<
CpuMatrix
>
(
height
,
height
);
MatrixPtr
gpuI
=
std
::
make_shared
<
GpuMatrix
>
(
height
,
height
);
/* Make matrix well conditioned: cpu * cpuT + Identity */
cpu
->
randomizeUniform
();
MatrixPtr
cpuT
=
cpu
->
getTranspose
();
MatrixPtr
outputCheck
=
std
::
make_shared
<
CpuMatrix
>
(
height
,
height
);
outputCheck
->
mul
(
cpu
,
cpuT
);
cpu
->
setDiag
(
1.0
);
cpu
->
add
(
*
outputCheck
);
gpu
->
copyFrom
(
*
cpu
);
cpu
->
inverse
(
cpuI
,
false
);
gpu
->
inverse
(
gpuI
,
false
);
MatrixPtr
outputCheck
=
std
::
make_shared
<
CpuMatrix
>
(
height
,
height
);
outputCheck
->
copyFrom
(
*
gpuI
);
MatrixCheckErr
(
*
cpuI
,
*
outputCheck
);
outputCheck
->
mul
(
cpu
,
cpuI
);
cpu
->
zeroMem
();
for
(
int
i
=
0
;
i
<
height
;
i
++
)
{
cpu
->
getRowBuf
(
i
)[
i
]
=
1.0
;
}
cpu
->
setDiag
(
1.0
);
MatrixCheckErr
(
*
cpu
,
*
outputCheck
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录