Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102665435
matrix.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Feb 23, 00:57
Size
1 KB
Mime Type
text/x-c++
Expires
Tue, Feb 25, 00:57 (2 d)
Engine
blob
Format
Raw Data
Handle
24386513
Attached To
R7571 SP4E-TB-TL-FR
matrix.hh
View Options
#ifndef MATRIX_HH
#define MATRIX_HH
/* ------------------------------------------------------ */
#include "my_types.hh"
#include <Eigen/Dense>
#include <algorithm>
#include <array>
#include <tuple>
#include <vector>
/* ------------------------------------------------------ */
template
<
typename
T
>
class
SquareMatrix
:
public
Eigen
::
Matrix
<
T
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
ColMajor
>
{
using
parent
=
Eigen
::
Matrix
<
T
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
ColMajor
>
;
public
:
SquareMatrix
(
std
::
size_t
size
)
:
parent
(
size
,
size
)
{}
SquareMatrix
(
const
SquareMatrix
&
other
)
:
parent
(
other
)
{}
public
:
std
::
size_t
size
()
{
return
this
->
rows
();
}
};
template
<
typename
T
>
using
Matrix
=
SquareMatrix
<
T
>
;
/* ------------------------------------------------------ */
template
<
typename
T
>
struct
MatrixIndexIterator
:
public
Matrix
<
T
>::
template
CustomIterator
<
T
>
{
MatrixIndexIterator
(
UInt
index
,
UInt
size
,
T
*
ptr
)
:
Matrix
<
T
>::
template
CustomIterator
<
T
>
(
index
,
ptr
),
size
(
size
)
{}
std
::
tuple
<
UInt
,
UInt
,
T
&>
operator
*
()
{
UInt
i
=
this
->
index
%
this
->
size
;
UInt
j
=
this
->
index
/
this
->
size
;
return
std
::
tuple
<
UInt
,
UInt
,
T
&>
(
i
,
j
,
this
->
ptr
[
this
->
index
]);
}
std
::
size_t
size
;
};
/* ------------------------------------------------------ */
template
<
typename
T
>
struct
IndexedMatrix
{
IndexedMatrix
(
Matrix
<
T
>&
mat
)
:
mat
(
mat
){};
MatrixIndexIterator
<
T
>
begin
()
{
return
MatrixIndexIterator
<
T
>
(
0
,
mat
.
size
(),
mat
.
data
());
};
MatrixIndexIterator
<
T
>
end
()
{
return
MatrixIndexIterator
<
T
>
(
mat
.
size
()
*
mat
.
size
(),
mat
.
size
(),
mat
.
data
());
};
private
:
Matrix
<
T
>&
mat
;
};
/* ------------------------------------------------------ */
template
<
typename
T
>
IndexedMatrix
<
T
>
index
(
Matrix
<
T
>&
mat
)
{
return
IndexedMatrix
<
T
>
(
mat
);
}
/* ------------------------------------------------------ */
#endif
// MATRIX
Event Timeline
Log In to Comment