Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
libcifpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
libcifpp
Commits
d25cbeb1
Commit
d25cbeb1
authored
Apr 14, 2023
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
matrix eigen value work
parent
9b60a07f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
include/cif++/matrix.hpp
+25
-1
test/unit-3d-test.cpp
+1
-1
No files found.
include/cif++/matrix.hpp
View file @
d25cbeb1
...
@@ -57,6 +57,16 @@ class matrix_expression
...
@@ -57,6 +57,16 @@ class matrix_expression
return
static_cast
<
const
M
&>
(
*
this
).
operator
()(
i
,
j
);
return
static_cast
<
const
M
&>
(
*
this
).
operator
()(
i
,
j
);
}
}
void
swap_row
(
uint32_t
r1
,
uint32_t
r2
)
{
for
(
uint32_t
c
=
0
;
c
<
dim_m
();
++
c
)
{
auto
v
=
operator
()(
r1
,
c
);
operator
()(
r1
,
c
)
=
operator
()(
r2
,
c
);
operator
()(
r2
,
c
)
=
v
;
}
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
matrix_expression
&
m
)
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
matrix_expression
&
m
)
{
{
os
<<
'['
;
os
<<
'['
;
...
@@ -454,7 +464,7 @@ matrix3x3<F> inverse(const matrix3x3<F> &m)
...
@@ -454,7 +464,7 @@ matrix3x3<F> inverse(const matrix3x3<F> &m)
}
}
template
<
typename
M
>
template
<
typename
M
>
auto
eigen
(
const
matrix_expression
<
M
>
&
mat
)
auto
eigen
(
const
matrix_expression
<
M
>
&
mat
,
bool
sort
)
{
{
using
value_type
=
decltype
(
mat
(
0
,
0
));
using
value_type
=
decltype
(
mat
(
0
,
0
));
...
@@ -565,6 +575,20 @@ auto eigen(const matrix_expression<M> &mat)
...
@@ -565,6 +575,20 @@ auto eigen(const matrix_expression<M> &mat)
}
}
}
}
if
(
sort
)
{
for
(
size_t
p
=
0
;
p
<
N
;
++
p
)
{
size_t
j
=
p
;
// set j to index of largest remaining eval
for
(
size_t
q
=
p
+
1
;
q
<
N
;
++
q
)
if
(
ev
[
q
]
<
ev
[
j
])
j
=
q
;
std
::
swap
(
ev
[
j
],
ev
[
p
]);
em
.
swap_row
(
j
,
p
);
}
}
return
std
::
make_tuple
(
ev
,
em
);
return
std
::
make_tuple
(
ev
,
em
);
}
}
...
...
test/unit-3d-test.cpp
View file @
d25cbeb1
...
@@ -381,7 +381,7 @@ BOOST_AUTO_TEST_CASE(eigen_1, *utf::tolerance(0.1f))
...
@@ -381,7 +381,7 @@ BOOST_AUTO_TEST_CASE(eigen_1, *utf::tolerance(0.1f))
cif
::
matrix4x4
<
float
>
m2
;
cif
::
matrix4x4
<
float
>
m2
;
m2
=
m
;
m2
=
m
;
const
auto
&
[
ev
,
em
]
=
cif
::
eigen
(
m2
);
const
auto
&
[
ev
,
em
]
=
cif
::
eigen
(
m2
,
true
);
BOOST_TEST
(
ev
[
0
]
==
0.1666428611718905
f
);
BOOST_TEST
(
ev
[
0
]
==
0.1666428611718905
f
);
BOOST_TEST
(
ev
[
1
]
==
1.4780548447781369
f
);
BOOST_TEST
(
ev
[
1
]
==
1.4780548447781369
f
);
...
...
Write
Preview
Markdown
is supported
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