Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sot-dyninv
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Stack Of Tasks
sot-dyninv
Commits
2ae4f93e
Commit
2ae4f93e
authored
13 years ago
by
Nicolas Mansard
Browse files
Options
Downloads
Patches
Plain Diff
IVIGIT.
parent
64ec5e3d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
unitTesting/CMakeLists.txt
+5
-13
5 additions, 13 deletions
unitTesting/CMakeLists.txt
unitTesting/qrt.cpp
+186
-0
186 additions, 0 deletions
unitTesting/qrt.cpp
with
191 additions
and
13 deletions
unitTesting/CMakeLists.txt
+
5
−
13
View file @
2ae4f93e
...
@@ -16,16 +16,17 @@
...
@@ -16,16 +16,17 @@
ADD_DEFINITIONS
(
-DDEBUG=2
)
ADD_DEFINITIONS
(
-DDEBUG=2
)
SET
(
tests
SET
(
tests
dummy
)
dummy
qrt
)
FOREACH
(
test
${
tests
}
)
FOREACH
(
test
${
tests
}
)
SET
(
EXECUTABLE_NAME
"
${
test
}
_exe"
)
SET
(
EXECUTABLE_NAME
"
${
test
}
_exe"
)
ADD_EXECUTABLE
(
${
EXECUTABLE_NAME
}
ADD_EXECUTABLE
(
${
EXECUTABLE_NAME
}
${
test
}
.cpp
)
${
test
}
.cpp
)
TARGET_LINK_LIBRARIES
(
${
EXECUTABLE_NAME
}
#
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME}
controller-pd
#
controller-pd
)
#
)
PKG_CONFIG_USE_DEPENDENCY
(
${
EXECUTABLE_NAME
}
sot-core
)
PKG_CONFIG_USE_DEPENDENCY
(
${
EXECUTABLE_NAME
}
sot-core
)
PKG_CONFIG_USE_DEPENDENCY
(
${
EXECUTABLE_NAME
}
soth
)
PKG_CONFIG_USE_DEPENDENCY
(
${
EXECUTABLE_NAME
}
soth
)
...
@@ -35,13 +36,4 @@ FOREACH(test ${tests})
...
@@ -35,13 +36,4 @@ FOREACH(test ${tests})
TARGET_LINK_LIBRARIES
(
${
EXECUTABLE_NAME
}
"
${${
test
}
_plugins_dependencies
}
"
)
TARGET_LINK_LIBRARIES
(
${
EXECUTABLE_NAME
}
"
${${
test
}
_plugins_dependencies
}
"
)
ENDIF
(
${
test
}
_plugins_dependencies
)
ENDIF
(
${
test
}
_plugins_dependencies
)
ADD_TEST
(
${
test
}
${
EXECUTABLE_NAME
}
${
samplemodelpath
}
sample.wrl
${
samplespec
}
${
sampleljr
}
)
IF
(
UNIX
)
SET_PROPERTY
(
TEST
${
test
}
PROPERTY
ENVIRONMENT
"LD_LIBRARY_PATH=
${
CMAKE_INSTALL_PREFIX
}
/lib:
${
CMAKE_BINARY_DIR
}
/src:
${
BOOST_ROOT
}
/lib"
)
ENDIF
(
UNIX
)
ENDFOREACH
(
test
)
ENDFOREACH
(
test
)
This diff is collapsed.
Click to expand it.
unitTesting/qrt.cpp
0 → 100644
+
186
−
0
View file @
2ae4f93e
/*
* Copyright 2011, Nicolas Mansard, LAAS-CNRS
*
* This file is part of sot-dyninv.
* sot-dyninv is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* sot-dyninv is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with sot-dyninvc. If not, see <http://www.gnu.org/licenses/>.
*/
#include
<Eigen/QR>
#include
<soth/Algebra.hpp>
#include
<iostream>
std
::
ostream
&
p
(
const
char
*
n
)
{
return
std
::
cout
<<
n
<<
" = "
;
}
namespace
Eigen
{
class
FullRowRankColPivQR
:
private
ColPivHouseholderQR
<
MatrixXd
>
{
public:
void
compute
(
const
MatrixType
&
matrix
)
{
assert
(
matrix
.
rows
()
<=
matrix
.
cols
()
);
ColPivHouseholderQR
<
MatrixXd
>::
compute
(
matrix
.
transpose
()
);
assert
(
rank
()
==
matrix
.
rows
()
);
}
void
solveInPlace
(
MatrixXd
&
Gp
)
{
/* r is the rank, nxm the size of the original matrix (ie whose transpose has
* been decomposed. */
const
int
r
=
rank
(),
n
=
cols
(),
m
=
rows
();
assert
(
r
==
n
);
assert
(
Gp
.
rows
()
==
m
);
/* G'E = Q R
* => G^+ = Q R^+T E' */
/* Compute E'*X. */
Gp
.
applyOnTheLeft
(
colsPermutation
().
transpose
()
);
/* Compute R^+T E'*X. */
matrixQR
()
.
topLeftCorner
(
r
,
r
).
transpose
().
triangularView
<
Lower
>
()
.
solveInPlace
(
Gp
.
topRows
(
r
));
/* Compute Q R^+T E'*X. */
/* Q = P1*P2* ... *Pn */
VectorXd
workspace
(
n
);
for
(
int
k
=
r
-
1
;
k
>=
0
;
--
k
)
{
int
remainingSize
=
m
-
k
;
Gp
.
bottomRows
(
Gp
.
rows
()
-
k
)
.
applyHouseholderOnTheLeft
(
matrixQR
().
col
(
k
).
tail
(
remainingSize
-
1
),
hCoeffs
().
coeff
(
k
),
&
workspace
.
coeffRef
(
0
));
}
}
};
}
int
main
(
void
)
{
using
namespace
Eigen
;
using
std
::
endl
;
using
std
::
cout
;
using
soth
::
MATLAB
;
{
/* Compute the pseudo inverse of a full-col rank matrix: G = V [ R; 0 ]. */
const
unsigned
int
n
=
6
,
m
=
3
,
r
=
3
;
MatrixXd
G
=
MatrixXd
::
Random
(
n
,
m
);
p
(
"G"
)
<<
(
MATLAB
)
G
<<
endl
;
Eigen
::
ColPivHouseholderQR
<
Eigen
::
MatrixXd
>
G_qr
;
G_qr
.
compute
(
G
);
p
(
"QR"
)
<<
(
MATLAB
)
G_qr
.
matrixQR
()
<<
endl
;
{
/* Q1 = ... */
MatrixXd
Q1
=
MatrixXd
::
Identity
(
n
,
r
);
VectorXd
workspace
(
n
);
/* P0*P1*P2 ... */
for
(
int
k
=
r
-
1
;
k
>=
0
;
--
k
)
{
int
remainingSize
=
n
-
k
;
Q1
.
bottomRows
(
Q1
.
rows
()
-
k
)
.
applyHouseholderOnTheLeft
(
G_qr
.
matrixQR
().
col
(
k
).
tail
(
remainingSize
-
1
),
G_qr
.
hCoeffs
().
coeff
(
k
),
&
workspace
.
coeffRef
(
0
));
}
p
(
"Q1"
)
<<
(
MATLAB
)
Q1
<<
endl
;
}
{
/* Q1' = ... */
MatrixXd
Q1t
=
MatrixXd
::
Identity
(
r
,
n
);
VectorXd
workspace
(
n
);
/* P2*P1*P0 ... */
for
(
int
k
=
r
-
1
;
k
>=
0
;
--
k
)
{
int
remainingSize
=
n
-
k
;
Q1t
.
rightCols
(
Q1t
.
cols
()
-
k
)
.
applyHouseholderOnTheRight
(
G_qr
.
matrixQR
().
col
(
k
).
tail
(
remainingSize
-
1
),
G_qr
.
hCoeffs
().
coeff
(
k
),
&
workspace
.
coeffRef
(
0
));
}
p
(
"Q1t"
)
<<
(
MATLAB
)
Q1t
<<
endl
;
}
{
MatrixXd
Gp
=
MatrixXd
::
Identity
(
r
,
n
);
VectorXd
workspace
(
n
);
/* P2*P1*P0 ... */
for
(
int
k
=
r
-
1
;
k
>=
0
;
--
k
)
{
int
remainingSize
=
n
-
k
;
Gp
.
rightCols
(
Gp
.
cols
()
-
k
)
.
applyHouseholderOnTheRight
(
G_qr
.
matrixQR
().
col
(
k
).
tail
(
remainingSize
-
1
),
G_qr
.
hCoeffs
().
coeff
(
k
),
&
workspace
.
coeffRef
(
0
));
}
G_qr
.
matrixQR
()
.
topLeftCorner
(
r
,
r
).
triangularView
<
Upper
>
()
.
solveInPlace
(
Gp
);
p
(
"EtGp"
)
<<
(
MATLAB
)
Gp
<<
endl
;
Gp
.
applyOnTheLeft
(
G_qr
.
colsPermutation
()
);
p
(
"Gp"
)
<<
(
MATLAB
)
Gp
<<
endl
;
}
}
{
/* Compute the pseudo inverse of a full-row rank matrix: G = [ L; 0 ] V'. */
const
unsigned
int
n
=
3
,
m
=
6
,
r
=
3
;
MatrixXd
G
=
MatrixXd
::
Random
(
n
,
m
);
p
(
"G"
)
<<
(
MATLAB
)
G
<<
endl
;
Eigen
::
ColPivHouseholderQR
<
Eigen
::
MatrixXd
>
Gt_qr
;
Gt_qr
.
compute
(
G
.
transpose
());
p
(
"QR"
)
<<
(
MATLAB
)
Gt_qr
.
matrixQR
()
<<
endl
;
p
(
"Q"
)
<<
(
MATLAB
)(
MatrixXd
)
Gt_qr
.
householderQ
()
<<
endl
;
p
(
"R"
)
<<
(
MATLAB
)(
MatrixXd
)
Gt_qr
.
matrixQR
().
triangularView
<
Upper
>
()
<<
endl
;
p
(
"E"
)
<<
(
MATLAB
)
Gt_qr
.
colsPermutation
().
toDenseMatrix
()
<<
endl
;
{
MatrixXd
Gp
=
MatrixXd
::
Identity
(
m
,
r
);
Gp
.
applyOnTheLeft
(
Gt_qr
.
colsPermutation
().
transpose
()
);
p
(
"Et"
)
<<
(
MATLAB
)
Gp
<<
endl
;
Gt_qr
.
matrixQR
()
.
topLeftCorner
(
r
,
r
).
transpose
().
triangularView
<
Lower
>
()
.
solveInPlace
(
Gp
.
topRows
(
r
));
p
(
"RptEt"
)
<<
(
MATLAB
)
Gp
<<
endl
;
/* Q = P1*P2* ... *Pn */
VectorXd
workspace
(
n
);
for
(
int
k
=
r
-
1
;
k
>=
0
;
--
k
)
{
cout
<<
k
<<
endl
;
int
remainingSize
=
m
-
k
;
Gp
.
bottomRows
(
Gp
.
rows
()
-
k
)
.
applyHouseholderOnTheLeft
(
Gt_qr
.
matrixQR
().
col
(
k
).
tail
(
remainingSize
-
1
),
Gt_qr
.
hCoeffs
().
coeff
(
k
),
&
workspace
.
coeffRef
(
0
));
}
p
(
"Gp"
)
<<
(
MATLAB
)
Gp
<<
endl
;
}
{
FullRowRankColPivQR
G_lq
;
G_lq
.
compute
(
G
);
MatrixXd
Gp
=
MatrixXd
::
Identity
(
m
,
r
);
G_lq
.
solveInPlace
(
Gp
);
p
(
"Gp"
)
<<
(
MATLAB
)
Gp
<<
endl
;
}
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment