Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
eigenpy
Commits
8dd520b5
Unverified
Commit
8dd520b5
authored
Aug 05, 2021
by
Justin Carpentier
Committed by
GitHub
Aug 05, 2021
Browse files
Merge pull request #245 from jcarpent/devel
Enhance support of Cholesky decomposition
parents
51b79afe
1f2ae251
Pipeline
#15522
passed with stage
in 15 minutes and 5 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
include/eigenpy/decompositions/LDLT.hpp
View file @
8dd520b5
/*
* Copyright 2020 INRIA
* Copyright 2020
-2021
INRIA
*/
#ifndef __eigenpy_decomposition_ldlt_hpp__
...
...
@@ -23,7 +23,8 @@ namespace eigenpy
typedef
_MatrixType
MatrixType
;
typedef
typename
MatrixType
::
Scalar
Scalar
;
typedef
typename
MatrixType
::
RealScalar
RealScalar
;
typedef
Eigen
::
Matrix
<
Scalar
,
Eigen
::
Dynamic
,
1
,
MatrixType
::
Options
>
VectorType
;
typedef
Eigen
::
Matrix
<
Scalar
,
Eigen
::
Dynamic
,
1
,
MatrixType
::
Options
>
VectorXs
;
typedef
Eigen
::
Matrix
<
Scalar
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
MatrixType
::
Options
>
MatrixXs
;
typedef
Eigen
::
LDLT
<
MatrixType
>
Solver
;
template
<
class
PyClass
>
...
...
@@ -55,7 +56,7 @@ namespace eigenpy
"Returns the LDLT decomposition matrix."
,
bp
::
return_internal_reference
<>
())
.
def
(
"rankUpdate"
,(
Solver
&
(
Solver
::*
)(
const
Eigen
::
MatrixBase
<
Vector
Type
>
&
,
const
RealScalar
&
))
&
Solver
::
template
rankUpdate
<
Vector
Type
>,
.
def
(
"rankUpdate"
,(
Solver
&
(
Solver
::*
)(
const
Eigen
::
MatrixBase
<
Vector
Xs
>
&
,
const
RealScalar
&
))
&
Solver
::
template
rankUpdate
<
Vector
Xs
>,
bp
::
args
(
"self"
,
"vector"
,
"sigma"
),
bp
::
return_self
<>
())
...
...
@@ -78,8 +79,10 @@ namespace eigenpy
#endif
.
def
(
"reconstructedMatrix"
,
&
Solver
::
reconstructedMatrix
,
bp
::
arg
(
"self"
),
"Returns the matrix represented by the decomposition, i.e., it returns the product: L L^*. This function is provided for debug purpose."
)
.
def
(
"solve"
,
&
solve
<
Vector
Type
>
,
bp
::
args
(
"self"
,
"b"
),
.
def
(
"solve"
,
&
solve
<
Vector
Xs
>
,
bp
::
args
(
"self"
,
"b"
),
"Returns the solution x of A x = b using the current decomposition of A."
)
.
def
(
"solve"
,
&
solve
<
MatrixXs
>
,
bp
::
args
(
"self"
,
"B"
),
"Returns the solution X of A X = B using the current decomposition of A where B is a right hand side matrix."
)
.
def
(
"setZero"
,
&
Solver
::
setZero
,
bp
::
arg
(
"self"
),
"Clear any existing decomposition."
)
...
...
@@ -107,7 +110,7 @@ namespace eigenpy
static
MatrixType
matrixL
(
const
Solver
&
self
)
{
return
self
.
matrixL
();
}
static
MatrixType
matrixU
(
const
Solver
&
self
)
{
return
self
.
matrixU
();
}
static
Vector
Type
vectorD
(
const
Solver
&
self
)
{
return
self
.
vectorD
();
}
static
Vector
Xs
vectorD
(
const
Solver
&
self
)
{
return
self
.
vectorD
();
}
static
MatrixType
transpositionsP
(
const
Solver
&
self
)
{
...
...
@@ -115,8 +118,8 @@ namespace eigenpy
self
.
matrixL
().
rows
());
}
template
<
typename
Vector
Type
>
static
Vector
Type
solve
(
const
Solver
&
self
,
const
Vector
Type
&
vec
)
template
<
typename
MatrixOr
Vector
>
static
MatrixOr
Vector
solve
(
const
Solver
&
self
,
const
MatrixOr
Vector
&
vec
)
{
return
self
.
solve
(
vec
);
}
...
...
include/eigenpy/decompositions/LLT.hpp
View file @
8dd520b5
/*
* Copyright 2020 INRIA
* Copyright 2020
-2021
INRIA
*/
#ifndef __eigenpy_decomposition_llt_hpp__
...
...
@@ -23,7 +23,8 @@ namespace eigenpy
typedef
_MatrixType
MatrixType
;
typedef
typename
MatrixType
::
Scalar
Scalar
;
typedef
typename
MatrixType
::
RealScalar
RealScalar
;
typedef
Eigen
::
Matrix
<
Scalar
,
Eigen
::
Dynamic
,
1
,
MatrixType
::
Options
>
VectorType
;
typedef
Eigen
::
Matrix
<
Scalar
,
Eigen
::
Dynamic
,
1
,
MatrixType
::
Options
>
VectorXs
;
typedef
Eigen
::
Matrix
<
Scalar
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
MatrixType
::
Options
>
MatrixXs
;
typedef
Eigen
::
LLT
<
MatrixType
>
Solver
;
template
<
class
PyClass
>
...
...
@@ -46,10 +47,10 @@ namespace eigenpy
bp
::
return_internal_reference
<>
())
#if EIGEN_VERSION_AT_LEAST(3,3,90)
.
def
(
"rankUpdate"
,(
Solver
&
(
Solver
::*
)(
const
Vector
Type
&
,
const
RealScalar
&
))
&
Solver
::
template
rankUpdate
<
Vector
Type
>,
.
def
(
"rankUpdate"
,(
Solver
&
(
Solver
::*
)(
const
Vector
Xs
&
,
const
RealScalar
&
))
&
Solver
::
template
rankUpdate
<
Vector
Xs
>,
bp
::
args
(
"self"
,
"vector"
,
"sigma"
),
bp
::
return_self
<>
())
#else
.
def
(
"rankUpdate"
,(
Solver
(
Solver
::*
)(
const
Vector
Type
&
,
const
RealScalar
&
))
&
Solver
::
template
rankUpdate
<
Vector
Type
>,
.
def
(
"rankUpdate"
,(
Solver
(
Solver
::*
)(
const
Vector
Xs
&
,
const
RealScalar
&
))
&
Solver
::
template
rankUpdate
<
Vector
Xs
>,
bp
::
args
(
"self"
,
"vector"
,
"sigma"
))
#endif
...
...
@@ -72,8 +73,10 @@ namespace eigenpy
#endif
.
def
(
"reconstructedMatrix"
,
&
Solver
::
reconstructedMatrix
,
bp
::
arg
(
"self"
),
"Returns the matrix represented by the decomposition, i.e., it returns the product: L L^*. This function is provided for debug purpose."
)
.
def
(
"solve"
,
&
solve
<
Vector
Type
>
,
bp
::
args
(
"self"
,
"b"
),
.
def
(
"solve"
,
&
solve
<
Vector
Xs
>
,
bp
::
args
(
"self"
,
"b"
),
"Returns the solution x of A x = b using the current decomposition of A."
)
.
def
(
"solve"
,
&
solve
<
MatrixXs
>
,
bp
::
args
(
"self"
,
"B"
),
"Returns the solution X of A X = B using the current decomposition of A where B is a right hand side matrix."
)
;
}
...
...
@@ -99,8 +102,8 @@ namespace eigenpy
static
MatrixType
matrixL
(
const
Solver
&
self
)
{
return
self
.
matrixL
();
}
static
MatrixType
matrixU
(
const
Solver
&
self
)
{
return
self
.
matrixU
();
}
template
<
typename
Vector
Type
>
static
Vector
Type
solve
(
const
Solver
&
self
,
const
Vector
Type
&
vec
)
template
<
typename
MatrixOr
Vector
>
static
MatrixOr
Vector
solve
(
const
Solver
&
self
,
const
MatrixOr
Vector
&
vec
)
{
return
self
.
solve
(
vec
);
}
...
...
unittest/python/test_LDLT.py
View file @
8dd520b5
import
eigenpy
eigenpy
.
switchToNumpyArray
()
import
numpy
as
np
import
numpy.linalg
as
la
...
...
@@ -16,3 +15,9 @@ D = ldlt.vectorD()
P
=
ldlt
.
transpositionsP
()
assert
eigenpy
.
is_approx
(
np
.
transpose
(
P
).
dot
(
L
.
dot
(
np
.
diag
(
D
).
dot
(
np
.
transpose
(
L
).
dot
(
P
)))),
A
)
X
=
np
.
random
.
rand
(
dim
,
20
)
B
=
A
.
dot
(
X
)
X_est
=
ldlt
.
solve
(
B
)
assert
eigenpy
.
is_approx
(
X
,
X_est
)
assert
eigenpy
.
is_approx
(
A
.
dot
(
X_est
),
B
)
unittest/python/test_LLT.py
View file @
8dd520b5
import
eigenpy
eigenpy
.
switchToNumpyArray
()
import
numpy
as
np
import
numpy.linalg
as
la
...
...
@@ -12,5 +11,10 @@ A = (A + A.T)*0.5 + np.diag(10. + np.random.rand(dim))
llt
=
eigenpy
.
LLT
(
A
)
L
=
llt
.
matrixL
()
assert
eigenpy
.
is_approx
(
L
.
dot
(
np
.
transpose
(
L
)),
A
)
X
=
np
.
random
.
rand
(
dim
,
20
)
B
=
A
.
dot
(
X
)
X_est
=
llt
.
solve
(
B
)
assert
eigenpy
.
is_approx
(
X
,
X_est
)
assert
eigenpy
.
is_approx
(
A
.
dot
(
X_est
),
B
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment