Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
846ce406
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
846ce406
编写于
1月 25, 2021
作者:
Q
Qi Li
提交者:
GitHub
1月 25, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCM] update eigen cmake and patch, test=develop (#30602)
上级
173660be
变更
3
展开全部
显示空白变更内容
内联
并排
Showing
3 changed file
with
1258 addition
and
39 deletion
+1258
-39
cmake/external/eigen.cmake
cmake/external/eigen.cmake
+27
-39
patches/eigen/BinaryFunctors.h
patches/eigen/BinaryFunctors.h
+509
-0
patches/eigen/Meta.h
patches/eigen/Meta.h
+722
-0
未找到文件。
cmake/external/eigen.cmake
浏览文件 @
846ce406
...
...
@@ -26,13 +26,6 @@ if(WIN32)
set
(
EIGEN_TAG 917060c364181f33a735dc023818d5a54f60e54c
)
endif
()
# eigen on cuda9.1 missing header of math_funtions.hpp
# https://stackoverflow.com/questions/43113508/math-functions-hpp-not-found-when-using-cuda-with-eigen
if
(
WITH_ROCM_PLATFORM
)
set
(
EIGEN_REPOSITORY
${
GIT_URL
}
/sabreshao/hipeigen.git
)
set
(
EIGEN_TAG 7cb2b6e5a4b4a1efe658abb215cd866c6fb2275e
)
endif
()
cache_third_party
(
extern_eigen3
REPOSITORY
${
EIGEN_REPOSITORY
}
TAG
${
EIGEN_TAG
}
...
...
@@ -56,14 +49,25 @@ elseif(LINUX)
# add patch to avoid compilation error in c++11
file
(
TO_NATIVE_PATH
${
PADDLE_SOURCE_DIR
}
/patches/eigen/MathFunctions.h native_src2
)
file
(
TO_NATIVE_PATH
${
EIGEN_SOURCE_DIR
}
/Eigen/src/Core/MathFunctions.h native_dst2
)
if
(
WITH_ROCM
)
# For HIPCC Eigen::internal::device::numeric_limits is not EIGEN_DEVICE_FUNC
# which will cause compiler error of using __host__ funciont in __host__ __device__
file
(
TO_NATIVE_PATH
${
PADDLE_SOURCE_DIR
}
/patches/eigen/Meta.h native_src3
)
file
(
TO_NATIVE_PATH
${
EIGEN_SOURCE_DIR
}
/Eigen/src/Core/util/Meta.h native_dst3
)
# For HIPCC Eigen::internal::scalar_sum_op<bool,bool> is not EIGEN_DEVICE_FUNC
# which will cause compiler error of using __host__ funciont in __host__ __device__
file
(
TO_NATIVE_PATH
${
PADDLE_SOURCE_DIR
}
/patches/eigen/BinaryFunctors.h native_src4
)
file
(
TO_NATIVE_PATH
${
EIGEN_SOURCE_DIR
}
/Eigen/src/Core/functors/BinaryFunctors.h native_dst4
)
set
(
EIGEN_PATCH_COMMAND cp
${
native_src1
}
${
native_dst1
}
&& cp
${
native_src2
}
${
native_dst2
}
&& cp
${
native_src3
}
${
native_dst3
}
&& cp
${
native_src4
}
${
native_dst4
}
)
else
()
set
(
EIGEN_PATCH_COMMAND cp
${
native_src1
}
${
native_dst1
}
&& cp
${
native_src2
}
${
native_dst2
}
)
endif
()
endif
()
set
(
EIGEN_INCLUDE_DIR
${
EIGEN_SOURCE_DIR
}
)
INCLUDE_DIRECTORIES
(
${
EIGEN_INCLUDE_DIR
}
)
if
(
WITH_AMD_GPU
)
ExternalProject_Add
(
ExternalProject_Add
(
extern_eigen3
${
EXTERNAL_PROJECT_LOG_ARGS
}
${
SHALLOW_CLONE
}
...
...
@@ -76,23 +80,7 @@ if(WITH_AMD_GPU)
BUILD_COMMAND
""
INSTALL_COMMAND
""
TEST_COMMAND
""
)
else
()
ExternalProject_Add
(
extern_eigen3
${
EXTERNAL_PROJECT_LOG_ARGS
}
${
SHALLOW_CLONE
}
"
${
EIGEN_DOWNLOAD_CMD
}
"
PREFIX
${
EIGEN_PREFIX_DIR
}
SOURCE_DIR
${
EIGEN_SOURCE_DIR
}
UPDATE_COMMAND
""
PATCH_COMMAND
${
EIGEN_PATCH_COMMAND
}
CONFIGURE_COMMAND
""
BUILD_COMMAND
""
INSTALL_COMMAND
""
TEST_COMMAND
""
)
endif
()
)
add_library
(
eigen3 INTERFACE
)
...
...
patches/eigen/BinaryFunctors.h
0 → 100644
浏览文件 @
846ce406
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// clang-format off
#ifndef EIGEN_BINARY_FUNCTORS_H
#define EIGEN_BINARY_FUNCTORS_H
namespace
Eigen
{
namespace
internal
{
//---------- associative binary functors ----------
template
<
typename
Arg1
,
typename
Arg2
>
struct
binary_op_base
{
typedef
Arg1
first_argument_type
;
typedef
Arg2
second_argument_type
;
};
/** \internal
* \brief Template functor to compute the sum of two scalars
*
* \sa class CwiseBinaryOp, MatrixBase::operator+, class VectorwiseOp, DenseBase::sum()
*/
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_sum_op
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
typename
ScalarBinaryOpTraits
<
LhsScalar
,
RhsScalar
,
scalar_sum_op
>::
ReturnType
result_type
;
#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_sum_op
)
#else
scalar_sum_op
()
{
EIGEN_SCALAR_BINARY_OP_PLUGIN
}
#endif
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
operator
()
(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
a
+
b
;
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
Packet
packetOp
(
const
Packet
&
a
,
const
Packet
&
b
)
const
{
return
internal
::
padd
(
a
,
b
);
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
predux
(
const
Packet
&
a
)
const
{
return
internal
::
predux
(
a
);
}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
functor_traits
<
scalar_sum_op
<
LhsScalar
,
RhsScalar
>
>
{
enum
{
Cost
=
(
NumTraits
<
LhsScalar
>::
AddCost
+
NumTraits
<
RhsScalar
>::
AddCost
)
/
2
,
// rough estimate!
PacketAccess
=
is_same
<
LhsScalar
,
RhsScalar
>::
value
&&
packet_traits
<
LhsScalar
>::
HasAdd
&&
packet_traits
<
RhsScalar
>::
HasAdd
// TODO vectorize mixed sum
};
};
/** \internal
* \brief Template specialization to deprecate the summation of boolean expressions.
* This is required to solve Bug 426.
* \sa DenseBase::count(), DenseBase::any(), ArrayBase::cast(), MatrixBase::cast()
*/
template
<
>
struct
scalar_sum_op
<
bool
,
bool
>
:
scalar_sum_op
<
int
,
int
>
{
EIGEN_DEPRECATED
EIGEN_DEVICE_FUNC
scalar_sum_op
()
{}
};
/** \internal
* \brief Template functor to compute the product of two scalars
*
* \sa class CwiseBinaryOp, Cwise::operator*(), class VectorwiseOp, MatrixBase::redux()
*/
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_product_op
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
typename
ScalarBinaryOpTraits
<
LhsScalar
,
RhsScalar
,
scalar_product_op
>::
ReturnType
result_type
;
#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_product_op
)
#else
scalar_product_op
()
{
EIGEN_SCALAR_BINARY_OP_PLUGIN
}
#endif
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
operator
()
(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
a
*
b
;
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
Packet
packetOp
(
const
Packet
&
a
,
const
Packet
&
b
)
const
{
return
internal
::
pmul
(
a
,
b
);
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
predux
(
const
Packet
&
a
)
const
{
return
internal
::
predux_mul
(
a
);
}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
functor_traits
<
scalar_product_op
<
LhsScalar
,
RhsScalar
>
>
{
enum
{
Cost
=
(
NumTraits
<
LhsScalar
>::
MulCost
+
NumTraits
<
RhsScalar
>::
MulCost
)
/
2
,
// rough estimate!
PacketAccess
=
is_same
<
LhsScalar
,
RhsScalar
>::
value
&&
packet_traits
<
LhsScalar
>::
HasMul
&&
packet_traits
<
RhsScalar
>::
HasMul
// TODO vectorize mixed product
};
};
/** \internal
* \brief Template functor to compute the conjugate product of two scalars
*
* This is a short cut for conj(x) * y which is needed for optimization purpose; in Eigen2 support mode, this becomes x * conj(y)
*/
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_conj_product_op
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
enum
{
Conj
=
NumTraits
<
LhsScalar
>::
IsComplex
};
typedef
typename
ScalarBinaryOpTraits
<
LhsScalar
,
RhsScalar
,
scalar_conj_product_op
>::
ReturnType
result_type
;
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_conj_product_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
operator
()
(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
conj_helper
<
LhsScalar
,
RhsScalar
,
Conj
,
false
>
().
pmul
(
a
,
b
);
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
Packet
packetOp
(
const
Packet
&
a
,
const
Packet
&
b
)
const
{
return
conj_helper
<
Packet
,
Packet
,
Conj
,
false
>
().
pmul
(
a
,
b
);
}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
functor_traits
<
scalar_conj_product_op
<
LhsScalar
,
RhsScalar
>
>
{
enum
{
Cost
=
NumTraits
<
LhsScalar
>::
MulCost
,
PacketAccess
=
internal
::
is_same
<
LhsScalar
,
RhsScalar
>::
value
&&
packet_traits
<
LhsScalar
>::
HasMul
};
};
/** \internal
* \brief Template functor to compute the min of two scalars
*
* \sa class CwiseBinaryOp, MatrixBase::cwiseMin, class VectorwiseOp, MatrixBase::minCoeff()
*/
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_min_op
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
typename
ScalarBinaryOpTraits
<
LhsScalar
,
RhsScalar
,
scalar_min_op
>::
ReturnType
result_type
;
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_min_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
operator
()
(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
numext
::
mini
(
a
,
b
);
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
Packet
packetOp
(
const
Packet
&
a
,
const
Packet
&
b
)
const
{
return
internal
::
pmin
(
a
,
b
);
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
predux
(
const
Packet
&
a
)
const
{
return
internal
::
predux_min
(
a
);
}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
functor_traits
<
scalar_min_op
<
LhsScalar
,
RhsScalar
>
>
{
enum
{
Cost
=
(
NumTraits
<
LhsScalar
>::
AddCost
+
NumTraits
<
RhsScalar
>::
AddCost
)
/
2
,
PacketAccess
=
internal
::
is_same
<
LhsScalar
,
RhsScalar
>::
value
&&
packet_traits
<
LhsScalar
>::
HasMin
};
};
/** \internal
* \brief Template functor to compute the max of two scalars
*
* \sa class CwiseBinaryOp, MatrixBase::cwiseMax, class VectorwiseOp, MatrixBase::maxCoeff()
*/
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_max_op
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
typename
ScalarBinaryOpTraits
<
LhsScalar
,
RhsScalar
,
scalar_max_op
>::
ReturnType
result_type
;
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_max_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
operator
()
(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
numext
::
maxi
(
a
,
b
);
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
Packet
packetOp
(
const
Packet
&
a
,
const
Packet
&
b
)
const
{
return
internal
::
pmax
(
a
,
b
);
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
predux
(
const
Packet
&
a
)
const
{
return
internal
::
predux_max
(
a
);
}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
functor_traits
<
scalar_max_op
<
LhsScalar
,
RhsScalar
>
>
{
enum
{
Cost
=
(
NumTraits
<
LhsScalar
>::
AddCost
+
NumTraits
<
RhsScalar
>::
AddCost
)
/
2
,
PacketAccess
=
internal
::
is_same
<
LhsScalar
,
RhsScalar
>::
value
&&
packet_traits
<
LhsScalar
>::
HasMax
};
};
/** \internal
* \brief Template functors for comparison of two scalars
* \todo Implement packet-comparisons
*/
template
<
typename
LhsScalar
,
typename
RhsScalar
,
ComparisonName
cmp
>
struct
scalar_cmp_op
;
template
<
typename
LhsScalar
,
typename
RhsScalar
,
ComparisonName
cmp
>
struct
functor_traits
<
scalar_cmp_op
<
LhsScalar
,
RhsScalar
,
cmp
>
>
{
enum
{
Cost
=
(
NumTraits
<
LhsScalar
>::
AddCost
+
NumTraits
<
RhsScalar
>::
AddCost
)
/
2
,
PacketAccess
=
false
};
};
template
<
ComparisonName
Cmp
,
typename
LhsScalar
,
typename
RhsScalar
>
struct
result_of
<
scalar_cmp_op
<
LhsScalar
,
RhsScalar
,
Cmp
>
(
LhsScalar
,
RhsScalar
)
>
{
typedef
bool
type
;
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_cmp_op
<
LhsScalar
,
RhsScalar
,
cmp_EQ
>
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
bool
result_type
;
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cmp_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
bool
operator
()(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
a
==
b
;}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_cmp_op
<
LhsScalar
,
RhsScalar
,
cmp_LT
>
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
bool
result_type
;
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cmp_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
bool
operator
()(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
a
<
b
;}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_cmp_op
<
LhsScalar
,
RhsScalar
,
cmp_LE
>
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
bool
result_type
;
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cmp_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
bool
operator
()(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
a
<=
b
;}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_cmp_op
<
LhsScalar
,
RhsScalar
,
cmp_GT
>
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
bool
result_type
;
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cmp_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
bool
operator
()(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
a
>
b
;}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_cmp_op
<
LhsScalar
,
RhsScalar
,
cmp_GE
>
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
bool
result_type
;
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cmp_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
bool
operator
()(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
a
>=
b
;}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_cmp_op
<
LhsScalar
,
RhsScalar
,
cmp_UNORD
>
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
bool
result_type
;
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cmp_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
bool
operator
()(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
!
(
a
<=
b
||
b
<=
a
);}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_cmp_op
<
LhsScalar
,
RhsScalar
,
cmp_NEQ
>
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
bool
result_type
;
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cmp_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
bool
operator
()(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
a
!=
b
;}
};
/** \internal
* \brief Template functor to compute the hypot of two \b positive \b and \b real scalars
*
* \sa MatrixBase::stableNorm(), class Redux
*/
template
<
typename
Scalar
>
struct
scalar_hypot_op
<
Scalar
,
Scalar
>
:
binary_op_base
<
Scalar
,
Scalar
>
{
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_hypot_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
Scalar
operator
()
(
const
Scalar
&
x
,
const
Scalar
&
y
)
const
{
// This functor is used by hypotNorm only for which it is faster to first apply abs
// on all coefficients prior to reduction through hypot.
// This way we avoid calling abs on positive and real entries, and this also permits
// to seamlessly handle complexes. Otherwise we would have to handle both real and complexes
// through the same functor...
return
internal
::
positive_real_hypot
(
x
,
y
);
}
};
template
<
typename
Scalar
>
struct
functor_traits
<
scalar_hypot_op
<
Scalar
,
Scalar
>
>
{
enum
{
Cost
=
3
*
NumTraits
<
Scalar
>::
AddCost
+
2
*
NumTraits
<
Scalar
>::
MulCost
+
2
*
scalar_div_cost
<
Scalar
,
false
>::
value
,
PacketAccess
=
false
};
};
/** \internal
* \brief Template functor to compute the pow of two scalars
*/
template
<
typename
Scalar
,
typename
Exponent
>
struct
scalar_pow_op
:
binary_op_base
<
Scalar
,
Exponent
>
{
typedef
typename
ScalarBinaryOpTraits
<
Scalar
,
Exponent
,
scalar_pow_op
>::
ReturnType
result_type
;
#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_pow_op
)
#else
scalar_pow_op
()
{
typedef
Scalar
LhsScalar
;
typedef
Exponent
RhsScalar
;
EIGEN_SCALAR_BINARY_OP_PLUGIN
}
#endif
EIGEN_DEVICE_FUNC
inline
result_type
operator
()
(
const
Scalar
&
a
,
const
Exponent
&
b
)
const
{
return
numext
::
pow
(
a
,
b
);
}
};
template
<
typename
Scalar
,
typename
Exponent
>
struct
functor_traits
<
scalar_pow_op
<
Scalar
,
Exponent
>
>
{
enum
{
Cost
=
5
*
NumTraits
<
Scalar
>::
MulCost
,
PacketAccess
=
false
};
};
//---------- non associative binary functors ----------
/** \internal
* \brief Template functor to compute the difference of two scalars
*
* \sa class CwiseBinaryOp, MatrixBase::operator-
*/
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_difference_op
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
typename
ScalarBinaryOpTraits
<
LhsScalar
,
RhsScalar
,
scalar_difference_op
>::
ReturnType
result_type
;
#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_difference_op
)
#else
scalar_difference_op
()
{
EIGEN_SCALAR_BINARY_OP_PLUGIN
}
#endif
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
operator
()
(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
a
-
b
;
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
Packet
packetOp
(
const
Packet
&
a
,
const
Packet
&
b
)
const
{
return
internal
::
psub
(
a
,
b
);
}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
functor_traits
<
scalar_difference_op
<
LhsScalar
,
RhsScalar
>
>
{
enum
{
Cost
=
(
NumTraits
<
LhsScalar
>::
AddCost
+
NumTraits
<
RhsScalar
>::
AddCost
)
/
2
,
PacketAccess
=
is_same
<
LhsScalar
,
RhsScalar
>::
value
&&
packet_traits
<
LhsScalar
>::
HasSub
&&
packet_traits
<
RhsScalar
>::
HasSub
};
};
/** \internal
* \brief Template functor to compute the quotient of two scalars
*
* \sa class CwiseBinaryOp, Cwise::operator/()
*/
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_quotient_op
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
typename
ScalarBinaryOpTraits
<
LhsScalar
,
RhsScalar
,
scalar_quotient_op
>::
ReturnType
result_type
;
#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_quotient_op
)
#else
scalar_quotient_op
()
{
EIGEN_SCALAR_BINARY_OP_PLUGIN
}
#endif
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
operator
()
(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
a
/
b
;
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
Packet
packetOp
(
const
Packet
&
a
,
const
Packet
&
b
)
const
{
return
internal
::
pdiv
(
a
,
b
);
}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
functor_traits
<
scalar_quotient_op
<
LhsScalar
,
RhsScalar
>
>
{
typedef
typename
scalar_quotient_op
<
LhsScalar
,
RhsScalar
>::
result_type
result_type
;
enum
{
PacketAccess
=
is_same
<
LhsScalar
,
RhsScalar
>::
value
&&
packet_traits
<
LhsScalar
>::
HasDiv
&&
packet_traits
<
RhsScalar
>::
HasDiv
,
Cost
=
scalar_div_cost
<
result_type
,
PacketAccess
>::
value
};
};
/** \internal
* \brief Template functor to compute the and of two booleans
*
* \sa class CwiseBinaryOp, ArrayBase::operator&&
*/
struct
scalar_boolean_and_op
{
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_boolean_and_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
bool
operator
()
(
const
bool
&
a
,
const
bool
&
b
)
const
{
return
a
&&
b
;
}
};
template
<
>
struct
functor_traits
<
scalar_boolean_and_op
>
{
enum
{
Cost
=
NumTraits
<
bool
>::
AddCost
,
PacketAccess
=
false
};
};
/** \internal
* \brief Template functor to compute the or of two booleans
*
* \sa class CwiseBinaryOp, ArrayBase::operator||
*/
struct
scalar_boolean_or_op
{
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_boolean_or_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
bool
operator
()
(
const
bool
&
a
,
const
bool
&
b
)
const
{
return
a
||
b
;
}
};
template
<
>
struct
functor_traits
<
scalar_boolean_or_op
>
{
enum
{
Cost
=
NumTraits
<
bool
>::
AddCost
,
PacketAccess
=
false
};
};
/** \internal
* \brief Template functor to compute the xor of two booleans
*
* \sa class CwiseBinaryOp, ArrayBase::operator^
*/
struct
scalar_boolean_xor_op
{
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_boolean_xor_op
)
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
bool
operator
()
(
const
bool
&
a
,
const
bool
&
b
)
const
{
return
a
^
b
;
}
};
template
<
>
struct
functor_traits
<
scalar_boolean_xor_op
>
{
enum
{
Cost
=
NumTraits
<
bool
>::
AddCost
,
PacketAccess
=
false
};
};
/** \internal
* \brief Template functor to compute the absolute difference of two scalars
*
* \sa class CwiseBinaryOp, MatrixBase::absolute_difference
*/
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
scalar_absolute_difference_op
:
binary_op_base
<
LhsScalar
,
RhsScalar
>
{
typedef
typename
ScalarBinaryOpTraits
<
LhsScalar
,
RhsScalar
,
scalar_absolute_difference_op
>::
ReturnType
result_type
;
#ifndef EIGEN_SCALAR_BINARY_OP_PLUGIN
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_absolute_difference_op
)
#else
scalar_absolute_difference_op
()
{
EIGEN_SCALAR_BINARY_OP_PLUGIN
}
#endif
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
operator
()
(
const
LhsScalar
&
a
,
const
RhsScalar
&
b
)
const
{
return
numext
::
absdiff
(
a
,
b
);
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
Packet
packetOp
(
const
Packet
&
a
,
const
Packet
&
b
)
const
{
return
internal
::
pabsdiff
(
a
,
b
);
}
};
template
<
typename
LhsScalar
,
typename
RhsScalar
>
struct
functor_traits
<
scalar_absolute_difference_op
<
LhsScalar
,
RhsScalar
>
>
{
enum
{
Cost
=
(
NumTraits
<
LhsScalar
>::
AddCost
+
NumTraits
<
RhsScalar
>::
AddCost
)
/
2
,
PacketAccess
=
is_same
<
LhsScalar
,
RhsScalar
>::
value
&&
packet_traits
<
LhsScalar
>::
HasAbsDiff
};
};
//---------- binary functors bound to a constant, thus appearing as a unary functor ----------
// The following two classes permits to turn any binary functor into a unary one with one argument bound to a constant value.
// They are analogues to std::binder1st/binder2nd but with the following differences:
// - they are compatible with packetOp
// - they are portable across C++ versions (the std::binder* are deprecated in C++11)
template
<
typename
BinaryOp
>
struct
bind1st_op
:
BinaryOp
{
typedef
typename
BinaryOp
::
first_argument_type
first_argument_type
;
typedef
typename
BinaryOp
::
second_argument_type
second_argument_type
;
typedef
typename
BinaryOp
::
result_type
result_type
;
EIGEN_DEVICE_FUNC
explicit
bind1st_op
(
const
first_argument_type
&
val
)
:
m_value
(
val
)
{}
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
operator
()
(
const
second_argument_type
&
b
)
const
{
return
BinaryOp
::
operator
()(
m_value
,
b
);
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
Packet
packetOp
(
const
Packet
&
b
)
const
{
return
BinaryOp
::
packetOp
(
internal
::
pset1
<
Packet
>
(
m_value
),
b
);
}
first_argument_type
m_value
;
};
template
<
typename
BinaryOp
>
struct
functor_traits
<
bind1st_op
<
BinaryOp
>
>
:
functor_traits
<
BinaryOp
>
{};
template
<
typename
BinaryOp
>
struct
bind2nd_op
:
BinaryOp
{
typedef
typename
BinaryOp
::
first_argument_type
first_argument_type
;
typedef
typename
BinaryOp
::
second_argument_type
second_argument_type
;
typedef
typename
BinaryOp
::
result_type
result_type
;
EIGEN_DEVICE_FUNC
explicit
bind2nd_op
(
const
second_argument_type
&
val
)
:
m_value
(
val
)
{}
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
result_type
operator
()
(
const
first_argument_type
&
a
)
const
{
return
BinaryOp
::
operator
()(
a
,
m_value
);
}
template
<
typename
Packet
>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
const
Packet
packetOp
(
const
Packet
&
a
)
const
{
return
BinaryOp
::
packetOp
(
a
,
internal
::
pset1
<
Packet
>
(
m_value
));
}
second_argument_type
m_value
;
};
template
<
typename
BinaryOp
>
struct
functor_traits
<
bind2nd_op
<
BinaryOp
>
>
:
functor_traits
<
BinaryOp
>
{};
}
// end namespace internal
}
// end namespace Eigen
#endif // EIGEN_BINARY_FUNCTORS_H
// clang-format on
patches/eigen/Meta.h
0 → 100755
浏览文件 @
846ce406
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录