NVIDIA DeepStream SDK API Reference

9.2 Release
sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2018-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef DW_CORE_EIGENDEFS_HPP__
19 #define DW_CORE_EIGENDEFS_HPP__
20 
21 #ifdef Success
22  #undef Success
23 #endif
24 
25 #include <cstdint>
26 
27 #include <Eigen/Core>
28 
29 
30 
32 // Alignment issues:
33 // There is an outstanding bug with Eigen's alignment requirement. The classes of the sfm
34 // module contain Eigen matrices as members. They seem to be aligned but the compiler sometimes
35 // returns the wrong address for the member. The ReconstructorTests unit tests fail when alignment
36 // is enabled in linux and PX. The main problem was observed with Matrix34f but it probably
37 // affects all Eigen types. The bug was observed in .cu files suggesting it is a problem
38 // between Eigen and nvcc.
39 //
40 // All alignment is now disabled pending further investigation.
42 template<typename T, int Rows, int Cols>
43 using Matrix = Eigen::Matrix<T, Rows, Cols, Eigen::DontAlign>;
44 
45 template<typename T, int Rows>
46 using Vector = Eigen::Matrix<T, Rows, 1, Eigen::DontAlign>;
47 
48 template<typename T, int Cols>
49 using RowVector = Eigen::Matrix<T, 1, Cols, Eigen::RowMajor | Eigen::DontAlign>;
50 
51 template<typename T, int Rows, int Cols>
52 using UnalignedMatrix = Eigen::Matrix<T, Rows, Cols, Eigen::DontAlign>;
53 
54 template<typename T, int Rows>
55 using UnalignedVector = Eigen::Matrix<T, Rows, 1, Eigen::DontAlign>;
56 
57 template<typename T, int Cols>
58 using UnalignedRowVector = Eigen::Matrix<T, 1, Cols, Eigen::RowMajor | Eigen::DontAlign>;
59 
60 // clang-format off
61 #define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
62  \
63  \
64  typedef UnalignedMatrix<Type, Size, Size> UnalignedMatrix##SizeSuffix##TypeSuffix; \
65  \
66  \
67  typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
68  \
69  \
70  typedef UnalignedVector<Type, Size> UnalignedVector##SizeSuffix##TypeSuffix; \
71  \
72  \
73  typedef Vector<Type, Size> Vector##SizeSuffix##TypeSuffix; \
74  \
75  \
76  typedef UnalignedRowVector<Type, Size> UnalignedRowVector##SizeSuffix##TypeSuffix; \
77  \
78  \
79  typedef RowVector<Type, Size> RowVector##SizeSuffix##TypeSuffix;
80 
81 #define EIGEN_MAKE_DYNAMIC_TYPEDEFS(Type, TypeSuffix, Size) \
82  \
83  \
84  typedef Eigen::Matrix<Type, Size, Eigen::Dynamic> Matrix##Size##X##TypeSuffix; \
85  \
86  \
87  typedef Eigen::Matrix<Type, Eigen::Dynamic, Size> Matrix##X##Size##TypeSuffix;
88 
89 #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
90  \
91  EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2, 2) \
92  \
93  EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3, 3) \
94  \
95  EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4, 4) \
96  \
97  EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 5, 5) \
98  \
99  EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 6, 6) \
100  \
101  EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Eigen::Dynamic, X) \
102  \
103  EIGEN_MAKE_DYNAMIC_TYPEDEFS(Type, TypeSuffix, 2) \
104  \
105  EIGEN_MAKE_DYNAMIC_TYPEDEFS(Type, TypeSuffix, 3) \
106  \
107  EIGEN_MAKE_DYNAMIC_TYPEDEFS(Type, TypeSuffix, 4)
108 // clang-format on
109 
112 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(uint16_t, us)
114 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(uint32_t, ui)
118 
119 #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
120 #undef EIGEN_MAKE_FIXED_TYPEDEFS
121 #undef EIGEN_MAKE_DYNAMIC_TYPEDEFS
122 
123 #undef ALIGN
124 
126 // Array used for images
127 
128 template<typename T>
130 {
131  typedef Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic> ArrayX;
132  typedef Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> ArrayXr;
133 };
134 
135 template<>
136 struct EigenImage<float>
137 {
138  typedef Eigen::Array<uint16_t, Eigen::Dynamic, Eigen::Dynamic> ArrayX;
139  typedef Eigen::Array<uint16_t, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> ArrayXr;
140 };
141 
142 
145 
146 
148 // saturated_cast
149 
150 template <typename Tout, typename Tin>
151 Tout saturated_cast(Tin value)
152 {
153  if (value < Tin(std::numeric_limits<Tout>::min()))
155  else if (value >= Tin(std::numeric_limits<Tout>::max()))
157  else
158  return static_cast<Tout>(value);
159 }
160 
162 // Quaternion
163 typedef Eigen::Quaternion<float, Eigen::DontAlign> Quaternionf;
164 
166 // Geometry
167 template<typename T, uint32_t SpaceDim>
168 using Hyperplane = Eigen::Hyperplane<T, SpaceDim>;
169 
172 
173 template<typename T, uint32_t SpaceDim>
174 using ParametrizedLine = Eigen::ParametrizedLine<T, SpaceDim>;
175 
178 
179 #endif // DW_CORE_EIGENDEFS_HPP__
RowVector
Eigen::Matrix< T, 1, Cols, Eigen::RowMajor|Eigen::DontAlign > RowVector
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:49
ArrayXb
EigenImage< uint8_t >::ArrayX ArrayXb
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:143
Quaternionf
Eigen::Quaternion< float, Eigen::DontAlign > Quaternionf
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:163
ParametrizedLine2f
ParametrizedLine< float, 2 > ParametrizedLine2f
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:176
ParametrizedLine3f
ParametrizedLine< float, 3 > ParametrizedLine3f
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:177
EigenImage
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:129
Hyperplane2f
Hyperplane< float, 2 > Hyperplane2f
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:170
EigenImage::ArrayX
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > ArrayX
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:131
EigenImage< float >::ArrayXr
Eigen::Array< uint16_t, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ArrayXr
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:139
EigenImage::ArrayXr
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ArrayXr
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:132
saturated_cast
Tout saturated_cast(Tin value)
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:151
EigenImage< float >::ArrayX
Eigen::Array< uint16_t, Eigen::Dynamic, Eigen::Dynamic > ArrayX
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:138
ArrayXbr
EigenImage< uint8_t >::ArrayXr ArrayXbr
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:144
max
int max(int a, int b)
Compute the component-wise maximum.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:60
EIGEN_MAKE_TYPEDEFS_ALL_SIZES
#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix)
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:89
Vector
Eigen::Matrix< T, Rows, 1, Eigen::DontAlign > Vector
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:46
Matrix
Eigen::Matrix< T, Rows, Cols, Eigen::DontAlign > Matrix
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:43
min
int min(int a, int b)
Compute the component-wise minimum.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:70
Hyperplane
Eigen::Hyperplane< T, SpaceDim > Hyperplane
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:168
UnalignedMatrix
Eigen::Matrix< T, Rows, Cols, Eigen::DontAlign > UnalignedMatrix
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:52
UnalignedVector
Eigen::Matrix< T, Rows, 1, Eigen::DontAlign > UnalignedVector
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:55
Hyperplane3f
Hyperplane< float, 3 > Hyperplane3f
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:171
UnalignedRowVector
Eigen::Matrix< T, 1, Cols, Eigen::RowMajor|Eigen::DontAlign > UnalignedRowVector
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:58
ParametrizedLine
Eigen::ParametrizedLine< T, SpaceDim > ParametrizedLine
Definition: sources/libs/nvdsinferutils/dbscan/EigenDefs.hpp:174