OrthoMethods.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) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.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_ORTHOMETHODS_H
12 #define EIGEN_ORTHOMETHODS_H
13 
14 namespace Eigen {
15 
27 template<typename Derived>
28 template<typename OtherDerived>
29 #ifndef EIGEN_PARSED_BY_DOXYGEN
31 typename MatrixBase<Derived>::template cross_product_return_type<OtherDerived>::type
32 #else
34 #endif
36 {
39 
40  // Note that there is no need for an expression here since the compiler
41  // optimize such a small temporary very well (even within a complex expression)
42  typename internal::nested_eval<Derived,2>::type lhs(derived());
43  typename internal::nested_eval<OtherDerived,2>::type rhs(other.derived());
45  numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
46  numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
47  numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0))
48  );
49 }
50 
51 namespace internal {
52 
53 template< int Arch,typename VectorLhs,typename VectorRhs,
54  typename Scalar = typename VectorLhs::Scalar,
55  bool Vectorizable = bool((VectorLhs::Flags&VectorRhs::Flags)&PacketAccessBit)>
56 struct cross3_impl {
58  run(const VectorLhs& lhs, const VectorRhs& rhs)
59  {
61  numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)),
62  numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)),
63  numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)),
64  0
65  );
66  }
67 };
68 
69 }
70 
80 template<typename Derived>
81 template<typename OtherDerived>
84 {
87 
88  typedef typename internal::nested_eval<Derived,2>::type DerivedNested;
89  typedef typename internal::nested_eval<OtherDerived,2>::type OtherDerivedNested;
90  DerivedNested lhs(derived());
91  OtherDerivedNested rhs(other.derived());
92 
96 }
97 
107 template<typename ExpressionType, int Direction>
108 template<typename OtherDerived>
112 {
115  YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
116 
117  typename internal::nested_eval<ExpressionType,2>::type mat(_expression());
118  typename internal::nested_eval<OtherDerived,2>::type vec(other.derived());
119 
120  CrossReturnType res(_expression().rows(),_expression().cols());
121  if(Direction==Vertical)
122  {
123  eigen_assert(CrossReturnType::RowsAtCompileTime==3 && "the matrix must have exactly 3 rows");
124  res.row(0) = (mat.row(1) * vec.coeff(2) - mat.row(2) * vec.coeff(1)).conjugate();
125  res.row(1) = (mat.row(2) * vec.coeff(0) - mat.row(0) * vec.coeff(2)).conjugate();
126  res.row(2) = (mat.row(0) * vec.coeff(1) - mat.row(1) * vec.coeff(0)).conjugate();
127  }
128  else
129  {
130  eigen_assert(CrossReturnType::ColsAtCompileTime==3 && "the matrix must have exactly 3 columns");
131  res.col(0) = (mat.col(1) * vec.coeff(2) - mat.col(2) * vec.coeff(1)).conjugate();
132  res.col(1) = (mat.col(2) * vec.coeff(0) - mat.col(0) * vec.coeff(2)).conjugate();
133  res.col(2) = (mat.col(0) * vec.coeff(1) - mat.col(1) * vec.coeff(0)).conjugate();
134  }
135  return res;
136 }
137 
138 namespace internal {
139 
140 template<typename Derived, int Size = Derived::SizeAtCompileTime>
142 {
144  typedef typename traits<Derived>::Scalar Scalar;
148  static inline VectorType run(const Derived& src)
149  {
150  VectorType perp = VectorType::Zero(src.size());
151  Index maxi = 0;
152  Index sndi = 0;
153  src.cwiseAbs().maxCoeff(&maxi);
154  if (maxi==0)
155  sndi = 1;
156  RealScalar invnm = RealScalar(1)/(Vector2() << src.coeff(sndi),src.coeff(maxi)).finished().norm();
157  perp.coeffRef(maxi) = -numext::conj(src.coeff(sndi)) * invnm;
158  perp.coeffRef(sndi) = numext::conj(src.coeff(maxi)) * invnm;
159 
160  return perp;
161  }
162 };
163 
164 template<typename Derived>
165 struct unitOrthogonal_selector<Derived,3>
166 {
168  typedef typename traits<Derived>::Scalar Scalar;
171  static inline VectorType run(const Derived& src)
172  {
173  VectorType perp;
174  /* Let us compute the crossed product of *this with a vector
175  * that is not too close to being colinear to *this.
176  */
177 
178  /* unless the x and y coords are both close to zero, we can
179  * simply take ( -y, x, 0 ) and normalize it.
180  */
181  if((!isMuchSmallerThan(src.x(), src.z()))
182  || (!isMuchSmallerThan(src.y(), src.z())))
183  {
184  RealScalar invnm = RealScalar(1)/src.template head<2>().norm();
185  perp.coeffRef(0) = -numext::conj(src.y())*invnm;
186  perp.coeffRef(1) = numext::conj(src.x())*invnm;
187  perp.coeffRef(2) = 0;
188  }
189  /* if both x and y are close to zero, then the vector is close
190  * to the z-axis, so it's far from colinear to the x-axis for instance.
191  * So we take the crossed product with (1,0,0) and normalize it.
192  */
193  else
194  {
195  RealScalar invnm = RealScalar(1)/src.template tail<2>().norm();
196  perp.coeffRef(0) = 0;
197  perp.coeffRef(1) = -numext::conj(src.z())*invnm;
198  perp.coeffRef(2) = numext::conj(src.y())*invnm;
199  }
200 
201  return perp;
202  }
203 };
204 
205 template<typename Derived>
206 struct unitOrthogonal_selector<Derived,2>
207 {
210  static inline VectorType run(const Derived& src)
211  { return VectorType(-numext::conj(src.y()), numext::conj(src.x())).normalized(); }
212 };
213 
214 } // end namespace internal
215 
225 template<typename Derived>
228 {
231 }
232 
233 } // end namespace Eigen
234 
235 #endif // EIGEN_ORTHOMETHODS_H
Eigen::VectorwiseOp::cross
const EIGEN_DEVICE_FUNC CrossReturnType cross(const MatrixBase< OtherDerived > &other) const
Definition: OrthoMethods.h: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::unitOrthogonal_selector< Derived, 2 >::VectorType
plain_matrix_type< Derived >::type VectorType
Definition: OrthoMethods.h:208
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
Eigen::internal::cross3_impl::run
static EIGEN_DEVICE_FUNC internal::plain_matrix_type< VectorLhs >::type run(const VectorLhs &lhs, const VectorRhs &rhs)
Definition: OrthoMethods.h:58
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
EIGEN_STATIC_ASSERT_VECTOR_ONLY
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:142
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
res
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
Eigen::internal::isMuchSmallerThan
EIGEN_DEVICE_FUNC bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: Eigen/src/Core/MathFunctions.h:1940
Eigen::internal::plain_matrix_type
Definition: XprHelper.h:295
Eigen::internal::unitOrthogonal_selector< Derived, 2 >::run
static EIGEN_DEVICE_FUNC VectorType run(const Derived &src)
Definition: OrthoMethods.h:210
Eigen::MatrixBase::cross
EIGEN_DEVICE_FUNC cross_product_return_type< OtherDerived >::type cross(const MatrixBase< OtherDerived > &other) const
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
Eigen::PacketAccessBit
const unsigned int PacketAccessBit
Definition: Constants.h:94
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::internal::unitOrthogonal_selector::Scalar
traits< Derived >::Scalar Scalar
Definition: OrthoMethods.h:144
Eigen::MatrixBase::cross3
EIGEN_DEVICE_FUNC PlainObject cross3(const MatrixBase< OtherDerived > &other) const
Definition: OrthoMethods.h:83
Eigen::internal::unitOrthogonal_selector::VectorType
plain_matrix_type< Derived >::type VectorType
Definition: OrthoMethods.h:143
Eigen::Architecture::Target
@ Target
Definition: Constants.h:492
Eigen::internal::unitOrthogonal_selector::RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: OrthoMethods.h:145
head< 2 >
v head< 2 >().setZero()
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
gtsam.examples.DogLegOptimizerExample.run
def run(args)
Definition: DogLegOptimizerExample.py:21
Eigen::Triplet< double >
conj
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:104
Eigen::internal::unitOrthogonal_selector::run
static EIGEN_DEVICE_FUNC VectorType run(const Derived &src)
Definition: OrthoMethods.h:148
Eigen::Vertical
@ Vertical
Definition: Constants.h:264
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE)
Definition: StaticAssert.h:157
Eigen::internal::unitOrthogonal_selector
Definition: OrthoMethods.h:141
Eigen::MatrixBase::PlainObject
Base::PlainObject PlainObject
Definition: MatrixBase.h:104
conjugate
EIGEN_DEVICE_FUNC ConjugateReturnType conjugate() const
Definition: CommonCwiseUnaryOps.h:74
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
EIGEN_STATIC_ASSERT
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:127
Eigen::internal::unitOrthogonal_selector::Vector2
Matrix< Scalar, 2, 1 > Vector2
Definition: OrthoMethods.h:146
Eigen::internal::cross3_impl
Definition: OrthoMethods.h:56
Eigen::internal::unitOrthogonal_selector< Derived, 3 >::Scalar
traits< Derived >::Scalar Scalar
Definition: OrthoMethods.h:168
Eigen::internal::unitOrthogonal_selector< Derived, 3 >::VectorType
plain_matrix_type< Derived >::type VectorType
Definition: OrthoMethods.h:167
Eigen::internal::is_same
Definition: Meta.h:148
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
Eigen::internal::unitOrthogonal_selector< Derived, 3 >::RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: OrthoMethods.h:169
internal
Definition: BandTriangularSolver.h:13
Eigen::numext::maxi
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition: Eigen/src/Core/MathFunctions.h:1093
VectorType
Definition: FFTW.cpp:65
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Eigen::VectorwiseOp::CrossReturnType
ExpressionType::PlainObject CrossReturnType
Definition: VectorwiseOp.h:712
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:232
Eigen::internal::unitOrthogonal_selector< Derived, 3 >::run
static EIGEN_DEVICE_FUNC VectorType run(const Derived &src)
Definition: OrthoMethods.h:171
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
tail< 2 >
v tail< 2 >().setZero()
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::MatrixBase::unitOrthogonal
EIGEN_DEVICE_FUNC PlainObject unitOrthogonal(void) const
Definition: OrthoMethods.h:227


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:12:25