Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yuhao Liu
ogs
Commits
feb6b827
Commit
feb6b827
authored
8 years ago
by
Christoph Lehmann
Browse files
Options
Downloads
Patches
Plain Diff
[MaL] templated EigenMapTools
parent
cf469b54
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
MathLib/LinAlg/Eigen/EigenMapTools.cpp
+0
-67
0 additions, 67 deletions
MathLib/LinAlg/Eigen/EigenMapTools.cpp
MathLib/LinAlg/Eigen/EigenMapTools.h
+161
-14
161 additions, 14 deletions
MathLib/LinAlg/Eigen/EigenMapTools.h
with
161 additions
and
81 deletions
MathLib/LinAlg/Eigen/EigenMapTools.cpp
deleted
100644 → 0
+
0
−
67
View file @
cf469b54
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include
"EigenMapTools.h"
#include
<cassert>
namespace
MathLib
{
Eigen
::
Map
<
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>>
toZeroedMatrix
(
std
::
vector
<
double
>&
data
,
Eigen
::
MatrixXd
::
Index
rows
,
Eigen
::
MatrixXd
::
Index
cols
)
{
assert
(
data
.
empty
());
// in order that resize fills the vector with zeros.
data
.
resize
(
rows
*
cols
);
return
{
data
.
data
(),
rows
,
cols
};
}
Eigen
::
Map
<
const
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>>
toMatrix
(
std
::
vector
<
double
>
const
&
data
,
Eigen
::
MatrixXd
::
Index
rows
,
Eigen
::
MatrixXd
::
Index
cols
)
{
assert
(
static_cast
<
Eigen
::
MatrixXd
::
Index
>
(
data
.
size
())
==
rows
*
cols
);
return
{
data
.
data
(),
rows
,
cols
};
}
Eigen
::
Map
<
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>>
toMatrix
(
std
::
vector
<
double
>&
data
,
Eigen
::
MatrixXd
::
Index
rows
,
Eigen
::
MatrixXd
::
Index
cols
)
{
assert
(
static_cast
<
Eigen
::
MatrixXd
::
Index
>
(
data
.
size
())
==
rows
*
cols
);
return
{
data
.
data
(),
rows
,
cols
};
}
Eigen
::
Map
<
Eigen
::
VectorXd
>
toZeroedVector
(
std
::
vector
<
double
>&
data
,
Eigen
::
VectorXd
::
Index
rows
)
{
assert
(
data
.
empty
());
// in order that resize fills the vector with zeros.
data
.
resize
(
rows
);
return
{
data
.
data
(),
rows
};
}
Eigen
::
Map
<
const
Eigen
::
VectorXd
>
toVector
(
std
::
vector
<
double
>
const
&
data
,
Eigen
::
VectorXd
::
Index
rows
)
{
assert
(
static_cast
<
Eigen
::
VectorXd
::
Index
>
(
data
.
size
())
==
rows
);
return
{
data
.
data
(),
rows
};
}
Eigen
::
Map
<
Eigen
::
VectorXd
>
toVector
(
std
::
vector
<
double
>&
data
,
Eigen
::
VectorXd
::
Index
rows
)
{
assert
(
static_cast
<
Eigen
::
VectorXd
::
Index
>
(
data
.
size
())
==
rows
);
return
{
data
.
data
(),
rows
};
}
}
// MathLib
This diff is collapsed.
Click to expand it.
MathLib/LinAlg/Eigen/EigenMapTools.h
+
161
−
14
View file @
feb6b827
...
...
@@ -7,37 +7,184 @@
*
*/
#pragma once
#ifndef MATHLIB_EIGENMAPTOOLS_H
#define MATHLIB_EIGENMAPTOOLS_H
#include
<cassert>
#include
<vector>
#include
<Eigen/Core>
namespace
MathLib
{
Eigen
::
Map
<
/*! Creates an Eigen mapped matrix from the given data vector.
*
* \return An Eigen mapped matrix of the given size. All values of the matrix
* are set to zero.
*
* \pre The passed \c data vector must have zero size.
* \post The \c data has size \c rows * \c cols.
*
* \note The data vector will have the same storage order (row or column major)
* as the requested matrix type.
*/
template
<
typename
Matrix
>
Eigen
::
Map
<
Matrix
>
toZeroedMatrix
(
std
::
vector
<
double
>&
data
,
Eigen
::
MatrixXd
::
Index
rows
,
Eigen
::
MatrixXd
::
Index
cols
)
{
static_assert
(
Matrix
::
IsRowMajor
||
Matrix
::
IsVectorAtCompileTime
,
"The default storage order in OGS is row major storage for "
"dense matrices."
);
assert
(
Matrix
::
RowsAtCompileTime
==
Eigen
::
Dynamic
||
Matrix
::
RowsAtCompileTime
==
rows
);
assert
(
Matrix
::
ColsAtCompileTime
==
Eigen
::
Dynamic
||
Matrix
::
ColsAtCompileTime
==
cols
);
assert
(
data
.
empty
());
// in order that resize fills the vector with zeros.
data
.
resize
(
rows
*
cols
);
return
{
data
.
data
(),
rows
,
cols
};
}
/*! Creates an Eigen mapped matrix from the given data vector.
*
* This is a convienence method which makes the specification of dynamically
* allocated Eigen matrices as return type easier.
*/
inline
Eigen
::
Map
<
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>>
toZeroedMatrix
(
std
::
vector
<
double
>&
data
,
Eigen
::
MatrixXd
::
Index
rows
,
Eigen
::
MatrixXd
::
Index
cols
);
Eigen
::
MatrixXd
::
Index
cols
)
{
return
toZeroedMatrix
<
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>>
(
data
,
rows
,
cols
);
}
Eigen
::
Map
<
const
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>>
/*! Creates an Eigen mapped matrix from the given data vector.
*
* \attention The data vector must have the same storage order (row or column
* major) as the requested matrix type.
*/
template
<
typename
Matrix
>
Eigen
::
Map
<
const
Matrix
>
toMatrix
(
std
::
vector
<
double
>
const
&
data
,
Eigen
::
MatrixXd
::
Index
rows
,
Eigen
::
MatrixXd
::
Index
cols
)
{
static_assert
(
Matrix
::
IsRowMajor
||
Matrix
::
IsVectorAtCompileTime
,
"The default storage order in OGS is row major storage for "
"dense matrices."
);
assert
(
Matrix
::
RowsAtCompileTime
==
Eigen
::
Dynamic
||
Matrix
::
RowsAtCompileTime
==
rows
);
assert
(
Matrix
::
ColsAtCompileTime
==
Eigen
::
Dynamic
||
Matrix
::
ColsAtCompileTime
==
cols
);
assert
(
static_cast
<
Eigen
::
MatrixXd
::
Index
>
(
data
.
size
())
==
rows
*
cols
);
return
{
data
.
data
(),
rows
,
cols
};
}
/*! Creates an Eigen mapped matrix from the given data vector.
*
* This is a convienence method which makes the specification of dynamically
* allocated Eigen matrices as return type easier.
*/
inline
Eigen
::
Map
<
const
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>>
toMatrix
(
std
::
vector
<
double
>
const
&
data
,
Eigen
::
MatrixXd
::
Index
rows
,
Eigen
::
MatrixXd
::
Index
cols
);
Eigen
::
MatrixXd
::
Index
cols
)
{
return
toMatrix
<
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>>
(
data
,
rows
,
cols
);
}
Eigen
::
Map
<
/*! Creates an Eigen mapped matrix from the given data vector.
*
* \attention The data vector must have the same storage order (row or column
* major) as the requested matrix type.
*/
template
<
typename
Matrix
>
Eigen
::
Map
<
Matrix
>
toMatrix
(
std
::
vector
<
double
>&
data
,
Eigen
::
MatrixXd
::
Index
rows
,
Eigen
::
MatrixXd
::
Index
cols
)
{
static_assert
(
Matrix
::
IsRowMajor
||
Matrix
::
IsVectorAtCompileTime
,
"The default storage order in OGS is row major storage for "
"dense matrices."
);
assert
(
Matrix
::
RowsAtCompileTime
==
Eigen
::
Dynamic
||
Matrix
::
RowsAtCompileTime
==
rows
);
assert
(
Matrix
::
ColsAtCompileTime
==
Eigen
::
Dynamic
||
Matrix
::
ColsAtCompileTime
==
cols
);
assert
(
static_cast
<
Eigen
::
MatrixXd
::
Index
>
(
data
.
size
())
==
rows
*
cols
);
return
{
data
.
data
(),
rows
,
cols
};
}
/*! Creates an Eigen mapped matrix from the given data vector.
*
* This is a convienence method which makes the specification of dynamically
* allocated Eigen matrices as return type easier.
*/
inline
Eigen
::
Map
<
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>>
toMatrix
(
std
::
vector
<
double
>&
data
,
Eigen
::
MatrixXd
::
Index
rows
,
Eigen
::
MatrixXd
::
Index
cols
);
Eigen
::
MatrixXd
::
Index
cols
)
{
return
toMatrix
<
Eigen
::
Matrix
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
Eigen
::
RowMajor
>>
(
data
,
rows
,
cols
);
}
/*! Creates an Eigen mapped vector from the given data vector.
*
* \return An Eigen mapped vector of the given size. All values of the vector
* are set to zero.
*
* \pre The passed \c data vector must have zero size.
* \post The \c data has size \c size.
*/
template
<
typename
Vector
>
Eigen
::
Map
<
Vector
>
toZeroedVector
(
std
::
vector
<
double
>&
data
,
Eigen
::
VectorXd
::
Index
size
)
{
static_assert
(
Vector
::
IsVectorAtCompileTime
,
"A vector type is required."
);
assert
(
Vector
::
SizeAtCompileTime
==
Eigen
::
Dynamic
||
Vector
::
SizeAtCompileTime
==
size
);
assert
(
data
.
empty
());
// in order that resize fills the vector with zeros.
Eigen
::
Map
<
Eigen
::
VectorXd
>
toZeroedVector
(
std
::
vector
<
double
>&
data
,
Eigen
::
VectorXd
::
Index
rows
);
data
.
resize
(
size
);
return
{
data
.
data
(),
size
};
}
//! Creates an Eigen mapped vector from the given data vector.
template
<
typename
Vector
>
Eigen
::
Map
<
const
Vector
>
toVector
(
std
::
vector
<
double
>
const
&
data
,
Eigen
::
VectorXd
::
Index
size
)
{
static_assert
(
Vector
::
IsVectorAtCompileTime
,
"A vector type is required."
);
assert
(
Vector
::
SizeAtCompileTime
==
Eigen
::
Dynamic
||
Vector
::
SizeAtCompileTime
==
size
);
assert
(
static_cast
<
Eigen
::
VectorXd
::
Index
>
(
data
.
size
())
==
size
);
Eigen
::
Map
<
const
Eigen
::
VectorXd
>
toVector
(
std
::
vector
<
double
>
const
&
data
,
Eigen
::
VectorXd
::
Index
rows
);
return
{
data
.
data
(),
size
};
}
//! Creates an Eigen mapped vector from the given data vector.
template
<
typename
Vector
>
Eigen
::
Map
<
Vector
>
toVector
(
std
::
vector
<
double
>&
data
,
Eigen
::
VectorXd
::
Index
size
)
{
static_assert
(
Vector
::
IsVectorAtCompileTime
,
"A vector type is required."
);
assert
(
Vector
::
SizeAtCompileTime
==
Eigen
::
Dynamic
||
Vector
::
SizeAtCompileTime
==
size
);
assert
(
static_cast
<
Eigen
::
VectorXd
::
Index
>
(
data
.
size
())
==
size
);
return
{
data
.
data
(),
size
};
}
Eigen
::
Map
<
Eigen
::
VectorXd
>
toVector
(
std
::
vector
<
double
>&
data
,
Eigen
::
VectorXd
::
Index
rows
);
}
// MathLib
#endif // MATHLIB_EIGENMAPTOOLS_H
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