gtsam
3rdparty
Eigen
Eigen
src
Core
arch
Default
Default/TypeCasting.h
Go to the documentation of this file.
1
// This file is part of Eigen, a lightweight C++ template library
2
// for linear algebra.
3
//
4
// Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com>
5
// Copyright (C) 2019 Rasmus Munk Larsen <rmlarsen@google.com>
6
//
7
// This Source Code Form is subject to the terms of the Mozilla
8
// Public License v. 2.0. If a copy of the MPL was not distributed
9
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11
#ifndef EIGEN_GENERIC_TYPE_CASTING_H
12
#define EIGEN_GENERIC_TYPE_CASTING_H
13
14
namespace
Eigen
{
15
16
namespace
internal
{
17
18
template
<>
19
struct
scalar_cast_op
<
float
,
Eigen
::
half
> {
20
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cast_op
)
21
typedef
Eigen
::
half
result_type
;
22
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
Eigen
::
half
operator() (const
float
&
a
)
const
{
23
#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
24
(defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
25
return
__float2half(
a
);
26
#else
27
return
Eigen::half
(
a
);
28
#endif
29
}
30
};
31
32
template
<>
33
struct
functor_traits
<
scalar_cast_op
<
float
,
Eigen
::
half
> >
34
{
enum
{
Cost
=
NumTraits<float>::AddCost
,
PacketAccess
=
false
}; };
35
36
37
template
<>
38
struct
scalar_cast_op
<
int
,
Eigen
::
half
> {
39
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cast_op
)
40
typedef
Eigen
::
half
result_type
;
41
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
Eigen
::
half
operator() (const
int
&
a
)
const
{
42
#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
43
(defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
44
return
__float2half(
static_cast<
float
>
(
a
));
45
#else
46
return
Eigen::half
(
static_cast<
float
>
(
a
));
47
#endif
48
}
49
};
50
51
template
<>
52
struct
functor_traits
<
scalar_cast_op
<
int
,
Eigen
::
half
> >
53
{
enum
{
Cost
=
NumTraits<float>::AddCost
,
PacketAccess
=
false
}; };
54
55
56
template
<>
57
struct
scalar_cast_op
<
Eigen
::
half
,
float
> {
58
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cast_op
)
59
typedef
float
result_type
;
60
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
float
operator() (const
Eigen
::
half
&
a
)
const
{
61
#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
62
(defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
63
return
__half2float(
a
);
64
#else
65
return
static_cast<
float
>
(
a
);
66
#endif
67
}
68
};
69
70
template
<>
71
struct
functor_traits
<
scalar_cast_op
<
Eigen
::
half
,
float
> >
72
{
enum
{
Cost
=
NumTraits<float>::AddCost
,
PacketAccess
=
false
}; };
73
74
75
template
<>
76
struct
scalar_cast_op
<
float
,
Eigen
::
bfloat16
> {
77
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cast_op
)
78
typedef
Eigen
::
bfloat16
result_type
;
79
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
Eigen
::
bfloat16
operator() (const
float
&
a
)
const
{
80
return
Eigen::bfloat16
(
a
);
81
}
82
};
83
84
template
<>
85
struct
functor_traits
<
scalar_cast_op
<
float
,
Eigen
::
bfloat16
> >
86
{
enum
{
Cost
=
NumTraits<float>::AddCost
,
PacketAccess
=
false
}; };
87
88
89
template
<>
90
struct
scalar_cast_op
<
int
,
Eigen
::
bfloat16
> {
91
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cast_op
)
92
typedef
Eigen
::
bfloat16
result_type
;
93
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
Eigen
::
bfloat16
operator() (const
int
&
a
)
const
{
94
return
Eigen::bfloat16
(
static_cast<
float
>
(
a
));
95
}
96
};
97
98
template
<>
99
struct
functor_traits
<
scalar_cast_op
<
int
,
Eigen
::
bfloat16
> >
100
{
enum
{
Cost
=
NumTraits<float>::AddCost
,
PacketAccess
=
false
}; };
101
102
103
template
<>
104
struct
scalar_cast_op
<
Eigen
::
bfloat16
,
float
> {
105
EIGEN_EMPTY_STRUCT_CTOR
(
scalar_cast_op
)
106
typedef
float
result_type
;
107
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE
float
operator() (const
Eigen
::
bfloat16
&
a
)
const
{
108
return
static_cast<
float
>
(
a
);
109
}
110
};
111
112
template
<>
113
struct
functor_traits
<
scalar_cast_op
<
Eigen
::
bfloat16
,
float
> >
114
{
enum
{
Cost
=
NumTraits<float>::AddCost
,
PacketAccess
=
false
}; };
115
116
117
}
118
}
119
120
#endif // EIGEN_GENERIC_TYPE_CASTING_H
EIGEN_EMPTY_STRUCT_CTOR
#define EIGEN_EMPTY_STRUCT_CTOR(X)
Definition:
XprHelper.h:22
gtsam.examples.DogLegOptimizerExample.int
int
Definition:
DogLegOptimizerExample.py:111
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition:
Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition:
jet.h:637
Eigen::internal::scalar_cast_op< Eigen::bfloat16, float >::result_type
float result_type
Definition:
Default/TypeCasting.h:106
Eigen::internal::scalar_cast_op
Definition:
UnaryFunctors.h:160
Eigen::bfloat16
Definition:
BFloat16.h:58
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition:
Macros.h:917
Eigen::internal::functor_traits::PacketAccess
@ PacketAccess
Definition:
XprHelper.h:180
a
ArrayXXi a
Definition:
Array_initializer_list_23_cxx11.cpp:1
Eigen::internal::functor_traits::Cost
@ Cost
Definition:
XprHelper.h:179
Eigen::internal::scalar_cast_op< Eigen::half, float >::result_type
float result_type
Definition:
Default/TypeCasting.h:59
gtsam.examples.DogLegOptimizerExample.float
float
Definition:
DogLegOptimizerExample.py:113
Eigen::internal::functor_traits
Definition:
XprHelper.h:175
internal
Definition:
BandTriangularSolver.h:13
Eigen::half
Definition:
Half.h:142
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition:
NumTraits.h:232
gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:09:37