Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
include
Utilities
CompareVectorsByComponent.h
Go to the documentation of this file.
1
/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2
*
3
*
4
* MoDELib is distributed without any warranty under the
5
* GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6
*/
7
8
#ifndef model_COMPAREVECTORSBYCOMPONENT_H_
9
#define model_COMPAREVECTORSBYCOMPONENT_H_
10
11
#include <math.h>
/* fabs */
12
#include <Eigen/Dense>
13
#include <type_traits>
14
#include <
NumericPrecision.h
>
15
16
namespace
model
17
{
18
19
template
<
typename
T,
unsigned
int
N,
typename
PrecisionType=T>
20
struct
CompareVectorsByComponent
21
{
22
bool
operator()
(
const
Eigen::Matrix<T,N,1>& lhs,
const
Eigen::Matrix<T,N,1>& rhs)
const
23
{
24
// std::cout<<PrecisionType(lhs(0)-rhs(0))<<" "<<NumericPrecision<PrecisionType>::epsilon<<std::endl;
25
return
( fabs(PrecisionType(lhs(0)-rhs(0)))<=
NumericPrecision<PrecisionType>::epsilon
)?
CompareVectorsByComponent
<T,
N
-1,PrecisionType>()(lhs.template segment<N-1>(1),rhs.template segment<N-1>(1)) : (lhs(0)<rhs(0));
26
}
27
};
28
29
template
<
typename
T,
typename
PrecisionType>
30
struct
CompareVectorsByComponent
<T,1,PrecisionType>
31
{
32
bool
operator()
(
const
Eigen::Matrix<T,1,1>& lhs,
const
Eigen::Matrix<T,1,1>& rhs)
const
33
{
34
// std::cout<<PrecisionType(lhs(0)-rhs(0))<<" "<<NumericPrecision<PrecisionType>::epsilon<<std::endl;
35
return
( fabs(PrecisionType(lhs(0)-rhs(0)))<=
NumericPrecision<PrecisionType>::epsilon
)? false : (lhs(0)<rhs(0));
36
}
37
};
38
39
40
// template<typename T, unsigned int N, typename CastType=T>
41
// struct CompareVectorsByComponent
42
// {
43
// bool operator() (const Eigen::Matrix<T,N,1>& lhs, const Eigen::Matrix<T,N,1>& rhs) const
44
// {
45
// return ( ((CastType) lhs(0))==((CastType) rhs(0)) )? CompareVectorsByComponent<T,N-1,CastType>()(lhs.template segment<N-1>(1),rhs.template segment<N-1>(1)) : (lhs(0)<rhs(0));
46
// }
47
// };
48
//
49
// template<typename T,typename CastType>
50
// struct CompareVectorsByComponent<T,1,CastType>
51
// {
52
// bool operator() (const Eigen::Matrix<T,1,1>& lhs, const Eigen::Matrix<T,1,1>& rhs) const
53
// {
54
// return ((CastType) lhs(0))<((CastType) rhs(0));
55
// }
56
// };
57
58
}
// namespace model
59
#endif
NumericPrecision.h
model
Definition
DD_converter.dox:2
model::CompareVectorsByComponent
Definition
CompareVectorsByComponent.h:21
model::CompareVectorsByComponent::operator()
bool operator()(const Eigen::Matrix< T, N, 1 > &lhs, const Eigen::Matrix< T, N, 1 > &rhs) const
Definition
CompareVectorsByComponent.h:22
model::NumericPrecision::epsilon
static constexpr T epsilon
Definition
NumericPrecision.h:19
N
N
Definition
testStraightExp.m:9
Generated by
1.15.0