├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── JoanSolaESKFNotes.pdf ├── LICENCE.md ├── README.md ├── eigen ├── .hg_archival.txt ├── Array.h ├── Cholesky.h ├── Core.h ├── Dense.h ├── Eigenvalues.h ├── Geometry.h ├── Householder.h ├── Jacobi.h ├── LU.h ├── QR.h ├── SVD.h └── src │ ├── Cholesky │ ├── LDLT.h │ ├── LLT.h │ └── LLT_MKL.h │ ├── Core │ ├── Array.h │ ├── ArrayBase.h │ ├── ArrayWrapper.h │ ├── Assign.h │ ├── Assign_MKL.h │ ├── BandMatrix.h │ ├── Block.h │ ├── BooleanRedux.h │ ├── CommaInitializer.h │ ├── CoreIterators.h │ ├── CwiseBinaryOp.h │ ├── CwiseNullaryOp.h │ ├── CwiseUnaryOp.h │ ├── CwiseUnaryView.h │ ├── DenseBase.h │ ├── DenseCoeffsBase.h │ ├── DenseStorage.h │ ├── Diagonal.h │ ├── DiagonalMatrix.h │ ├── DiagonalProduct.h │ ├── Dot.h │ ├── EigenBase.h │ ├── Flagged.h │ ├── ForceAlignedAccess.h │ ├── Functors.h │ ├── Fuzzy.h │ ├── GeneralProduct.h │ ├── GenericPacketMath.h │ ├── GlobalFunctions.h │ ├── IO.h │ ├── Map.h │ ├── MapBase.h │ ├── MathFunctions.h │ ├── Matrix.h │ ├── MatrixBase.h │ ├── NestByValue.h │ ├── NoAlias.h │ ├── NumTraits.h │ ├── PermutationMatrix.h │ ├── PlainObjectBase.h │ ├── ProductBase.h │ ├── Random.h │ ├── Redux.h │ ├── Ref.h │ ├── Replicate.h │ ├── ReturnByValue.h │ ├── Reverse.h │ ├── Select.h │ ├── SelfAdjointView.h │ ├── SelfCwiseBinaryOp.h │ ├── SolveTriangular.h │ ├── StableNorm.h │ ├── Stride.h │ ├── Swap.h │ ├── Transpose.h │ ├── Transpositions.h │ ├── TriangularMatrix.h │ ├── VectorBlock.h │ ├── VectorwiseOp.h │ ├── Visitor.h │ ├── arch │ │ └── Default │ │ │ └── Settings.h │ ├── products │ │ ├── CoeffBasedProduct.h │ │ ├── GeneralBlockPanelKernel.h │ │ ├── GeneralMatrixMatrix.h │ │ ├── GeneralMatrixMatrixTriangular.h │ │ ├── GeneralMatrixMatrixTriangular_MKL.h │ │ ├── GeneralMatrixMatrix_MKL.h │ │ ├── GeneralMatrixVector.h │ │ ├── GeneralMatrixVector_MKL.h │ │ ├── Parallelizer.h │ │ ├── SelfadjointMatrixMatrix.h │ │ ├── SelfadjointMatrixMatrix_MKL.h │ │ ├── SelfadjointMatrixVector.h │ │ ├── SelfadjointMatrixVector_MKL.h │ │ ├── SelfadjointProduct.h │ │ ├── SelfadjointRank2Update.h │ │ ├── TriangularMatrixMatrix.h │ │ ├── TriangularMatrixMatrix_MKL.h │ │ ├── TriangularMatrixVector.h │ │ ├── TriangularMatrixVector_MKL.h │ │ ├── TriangularSolverMatrix.h │ │ ├── TriangularSolverMatrix_MKL.h │ │ └── TriangularSolverVector.h │ └── util │ │ ├── BlasUtil.h │ │ ├── Constants.h │ │ ├── DisableStupidWarnings.h │ │ ├── ForwardDeclarations.h │ │ ├── MKL_support.h │ │ ├── Macros.h │ │ ├── Memory.h │ │ ├── Meta.h │ │ ├── NonMPL2.h │ │ ├── ReenableStupidWarnings.h │ │ ├── StaticAssert.h │ │ └── XprHelper.h │ ├── Eigenvalues │ ├── ComplexEigenSolver.h │ ├── ComplexSchur.h │ ├── ComplexSchur_MKL.h │ ├── EigenSolver.h │ ├── GeneralizedEigenSolver.h │ ├── GeneralizedSelfAdjointEigenSolver.h │ ├── HessenbergDecomposition.h │ ├── MatrixBaseEigenvalues.h │ ├── RealQZ.h │ ├── RealSchur.h │ ├── RealSchur_MKL.h │ ├── SelfAdjointEigenSolver.h │ ├── SelfAdjointEigenSolver_MKL.h │ └── Tridiagonalization.h │ ├── Geometry │ ├── AlignedBox.h │ ├── AngleAxis.h │ ├── EulerAngles.h │ ├── Homogeneous.h │ ├── Hyperplane.h │ ├── OrthoMethods.h │ ├── ParametrizedLine.h │ ├── Quaternion.h │ ├── Rotation2D.h │ ├── RotationBase.h │ ├── Scaling.h │ ├── Transform.h │ ├── Translation.h │ └── Umeyama.h │ ├── Householder │ ├── BlockHouseholder.h │ ├── Householder.h │ └── HouseholderSequence.h │ ├── Jacobi │ └── Jacobi.h │ ├── LU │ ├── Determinant.h │ ├── FullPivLU.h │ ├── Inverse.h │ ├── PartialPivLU.h │ └── PartialPivLU_MKL.h │ ├── QR │ ├── ColPivHouseholderQR.h │ ├── ColPivHouseholderQR_MKL.h │ ├── FullPivHouseholderQR.h │ ├── HouseholderQR.h │ └── HouseholderQR_MKL.h │ ├── SVD │ ├── JacobiSVD.h │ ├── JacobiSVD_MKL.h │ └── UpperBidiagonalization.h │ ├── misc │ ├── Image.h │ ├── Kernel.h │ ├── Solve.h │ ├── SparseSolve.h │ └── blas.h │ └── plugins │ ├── ArrayCwiseBinaryOps.h │ ├── ArrayCwiseUnaryOps.h │ ├── BlockMethods.h │ ├── CommonCwiseBinaryOps.h │ ├── CommonCwiseUnaryOps.h │ ├── MatrixCwiseBinaryOps.h │ └── MatrixCwiseUnaryOps.h ├── include ├── ESKF.h └── unrolledFPFt.h ├── src ├── ESKF.cpp └── main.cpp └── tools ├── analyze.py └── codegen.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.autosave 2 | /build/* 3 | CMakeLists.txt.user 4 | CMakeCache.txt 5 | CMakeFiles 6 | CMakeScripts 7 | Testing 8 | Makefile 9 | cmake_install.cmake 10 | install_manifest.txt 11 | compile_commands.json 12 | CTestTestfile.cmake 13 | # Prerequisites 14 | *.d 15 | 16 | # Compiled Object files 17 | *.slo 18 | *.lo 19 | *.o 20 | *.obj 21 | 22 | # Precompiled Headers 23 | *.gch 24 | *.pch 25 | 26 | # Compiled Dynamic libraries 27 | *.so 28 | *.dylib 29 | *.dll 30 | 31 | # Fortran module files 32 | *.mod 33 | *.smod 34 | 35 | # Compiled Static libraries 36 | *.lai 37 | *.la 38 | *.a 39 | *.lib 40 | 41 | # Executables 42 | *.exe 43 | *.out 44 | *.app 45 | 46 | 47 | #Visual studio 48 | .vs/ 49 | *.json -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Matrix"] 2 | path = Matrix 3 | url = https://github.com/PX4/Matrix.git 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.9) 2 | project(ESKF) 3 | 4 | IF (WIN32) 5 | set(CMAKE_CXX_FLAGS "-O2 -Wall") 6 | ELSE() 7 | set(CMAKE_CXX_FLAGS "-Og -W -Wall -std=c++11") 8 | ENDIF() 9 | 10 | file(GLOB INCLUDES "include/*.h" "eigen/*.h" "eigen/src/*/*.h") 11 | include_directories(./include eigen eigen/src/*/*) 12 | file(GLOB SOURCES "src/*.cpp" "include/*.h" "eigen/*.h" "eigen/src/*/*.h") 13 | 14 | add_executable(ESKF ${SOURCES}) 15 | -------------------------------------------------------------------------------- /JoanSolaESKFNotes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madcowswe/ESKF/228e511e758f262c9782da43fb04ef5727a253c0/JoanSolaESKFNotes.pdf -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Oskar Weigl 4 | Copyright (c) 2018 Joshua Elsdon 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESKF 2 | An implementation of an Error State Kalman Filter (ESKF) 3 | 4 | The ambition of this repository is to make an estimator that can take accelerometer/gyro readings and integrate them into a 6DOF pose. 5 | This will also be corrected by a motion capture system (or any absolute position input.). 6 | 7 | Where possible notation and concepts will be taken from the notes provided by Joan Sola. Found at http://www.iri.upc.edu/people/jsola/JoanSola/objectes/notes/kinematics.pdf 8 | 9 | This implementation is intended to run on an embedded device. In my case an STM32 development board. 10 | 11 | 12 | # Building 13 | 14 | mkdir build 15 | 16 | cd build 17 | 18 | cmake .. 19 | 20 | make -j8 21 | -------------------------------------------------------------------------------- /eigen/.hg_archival.txt: -------------------------------------------------------------------------------- 1 | repo: 13a5d365ba1633179aee1a15b7d17e414dbce394 2 | node: 13a5d365ba1633179aee1a15b7d17e414dbce394 3 | branch: default 4 | latesttag: null 5 | latesttagdistance: 1 6 | -------------------------------------------------------------------------------- /eigen/Array.h: -------------------------------------------------------------------------------- 1 | #ifndef EIGEN_ARRAY_MODULE_H 2 | #define EIGEN_ARRAY_MODULE_H 3 | 4 | // include Core first to handle Eigen2 support macros 5 | #include "Core" 6 | 7 | #ifndef EIGEN2_SUPPORT 8 | #error The Eigen/Array header does no longer exist in Eigen3. All that functionality has moved to Eigen/Core. 9 | #endif 10 | 11 | #endif // EIGEN_ARRAY_MODULE_H -------------------------------------------------------------------------------- /eigen/Cholesky.h: -------------------------------------------------------------------------------- 1 | #ifndef EIGEN_CHOLESKY_MODULE_H 2 | #define EIGEN_CHOLESKY_MODULE_H 3 | 4 | #include "Core.h" 5 | 6 | #include "src/Core/util/DisableStupidWarnings.h" 7 | 8 | /** \defgroup Cholesky_Module Cholesky module 9 | * 10 | * 11 | * 12 | * This module provides two variants of the Cholesky decomposition for selfadjoint (hermitian) matrices. 13 | * Those decompositions are accessible via the following MatrixBase methods: 14 | * - MatrixBase::llt(), 15 | * - MatrixBase::ldlt() 16 | * 17 | * \code 18 | * #include 19 | * \endcode 20 | */ 21 | 22 | #include "src/misc/Solve.h" 23 | #include "src/Cholesky/LLT.h" 24 | #include "src/Cholesky/LDLT.h" 25 | #ifdef EIGEN_USE_LAPACKE 26 | #include "src/Cholesky/LLT_MKL.h" 27 | #endif 28 | 29 | #include "src/Core/util/ReenableStupidWarnings.h" 30 | 31 | #endif // EIGEN_CHOLESKY_MODULE_H 32 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ -------------------------------------------------------------------------------- /eigen/Dense.h: -------------------------------------------------------------------------------- 1 | #include "Core.h" 2 | #include "LU.h" 3 | #include "Cholesky.h" 4 | #include "QR.h" 5 | #include "SVD.h" 6 | #include "Geometry.h" 7 | #include "Eigenvalues.h" -------------------------------------------------------------------------------- /eigen/Eigenvalues.h: -------------------------------------------------------------------------------- 1 | #ifndef EIGEN_EIGENVALUES_MODULE_H 2 | #define EIGEN_EIGENVALUES_MODULE_H 3 | 4 | #include "Core.h" 5 | 6 | #include "src/Core/util/DisableStupidWarnings.h" 7 | 8 | #include "Cholesky.h" 9 | #include "Jacobi.h" 10 | #include "Householder.h" 11 | #include "LU.h" 12 | #include "Geometry.h" 13 | 14 | /** \defgroup Eigenvalues_Module Eigenvalues module 15 | * 16 | * 17 | * 18 | * This module mainly provides various eigenvalue solvers. 19 | * This module also provides some MatrixBase methods, including: 20 | * - MatrixBase::eigenvalues(), 21 | * - MatrixBase::operatorNorm() 22 | * 23 | * \code 24 | * #include 25 | * \endcode 26 | */ 27 | 28 | #include "src/Eigenvalues/Tridiagonalization.h" 29 | #include "src/Eigenvalues/RealSchur.h" 30 | #include "src/Eigenvalues/EigenSolver.h" 31 | #include "src/Eigenvalues/SelfAdjointEigenSolver.h" 32 | #include "src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h" 33 | #include "src/Eigenvalues/HessenbergDecomposition.h" 34 | #include "src/Eigenvalues/ComplexSchur.h" 35 | #include "src/Eigenvalues/ComplexEigenSolver.h" 36 | #include "src/Eigenvalues/RealQZ.h" 37 | #include "src/Eigenvalues/GeneralizedEigenSolver.h" 38 | #include "src/Eigenvalues/MatrixBaseEigenvalues.h" 39 | #ifdef EIGEN_USE_LAPACKE 40 | #include "src/Eigenvalues/RealSchur_MKL.h" 41 | #include "src/Eigenvalues/ComplexSchur_MKL.h" 42 | #include "src/Eigenvalues/SelfAdjointEigenSolver_MKL.h" 43 | #endif 44 | 45 | #include "src/Core/util/ReenableStupidWarnings.h" 46 | 47 | #endif // EIGEN_EIGENVALUES_MODULE_H 48 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ -------------------------------------------------------------------------------- /eigen/Geometry.h: -------------------------------------------------------------------------------- 1 | #ifndef EIGEN_GEOMETRY_MODULE_H 2 | #define EIGEN_GEOMETRY_MODULE_H 3 | 4 | #include "Core.h" 5 | 6 | #include "src/Core/util/DisableStupidWarnings.h" 7 | 8 | #include "SVD.h" 9 | #include "LU.h" 10 | #include 11 | 12 | #ifndef M_PI 13 | #define M_PI 3.14159265358979323846 14 | #endif 15 | 16 | /** \defgroup Geometry_Module Geometry module 17 | * 18 | * 19 | * 20 | * This module provides support for: 21 | * - fixed-size homogeneous transformations 22 | * - translation, scaling, 2D and 3D rotations 23 | * - quaternions 24 | * - \ref MatrixBase::cross() "cross product" 25 | * - \ref MatrixBase::unitOrthogonal() "orthognal vector generation" 26 | * - some linear components: parametrized-lines and hyperplanes 27 | * 28 | * \code 29 | * #include 30 | * \endcode 31 | */ 32 | 33 | #include "src/Geometry/OrthoMethods.h" 34 | #include "src/Geometry/EulerAngles.h" 35 | 36 | #if EIGEN2_SUPPORT_STAGE > STAGE20_RESOLVE_API_CONFLICTS 37 | #include "src/Geometry/Homogeneous.h" 38 | #include "src/Geometry/RotationBase.h" 39 | #include "src/Geometry/Rotation2D.h" 40 | #include "src/Geometry/Quaternion.h" 41 | #include "src/Geometry/AngleAxis.h" 42 | #include "src/Geometry/Transform.h" 43 | #include "src/Geometry/Translation.h" 44 | #include "src/Geometry/Scaling.h" 45 | #include "src/Geometry/Hyperplane.h" 46 | #include "src/Geometry/ParametrizedLine.h" 47 | #include "src/Geometry/AlignedBox.h" 48 | #include "src/Geometry/Umeyama.h" 49 | 50 | #if defined EIGEN_VECTORIZE_SSE 51 | #include "src/Geometry/arch/Geometry_SSE.h" 52 | #endif 53 | #endif 54 | 55 | #ifdef EIGEN2_SUPPORT 56 | #include "src/Eigen2Support/Geometry/All.h" 57 | #endif 58 | 59 | #include "src/Core/util/ReenableStupidWarnings.h" 60 | 61 | #endif // EIGEN_GEOMETRY_MODULE_H 62 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ 63 | -------------------------------------------------------------------------------- /eigen/Householder.h: -------------------------------------------------------------------------------- 1 | #ifndef EIGEN_HOUSEHOLDER_MODULE_H 2 | #define EIGEN_HOUSEHOLDER_MODULE_H 3 | 4 | #include "Core.h" 5 | 6 | #include "src/Core/util/DisableStupidWarnings.h" 7 | 8 | /** \defgroup Householder_Module Householder module 9 | * This module provides Householder transformations. 10 | * 11 | * \code 12 | * #include 13 | * \endcode 14 | */ 15 | 16 | #include "src/Householder/Householder.h" 17 | #include "src/Householder/HouseholderSequence.h" 18 | #include "src/Householder/BlockHouseholder.h" 19 | 20 | #include "src/Core/util/ReenableStupidWarnings.h" 21 | 22 | #endif // EIGEN_HOUSEHOLDER_MODULE_H 23 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ -------------------------------------------------------------------------------- /eigen/Jacobi.h: -------------------------------------------------------------------------------- 1 | #ifndef EIGEN_JACOBI_MODULE_H 2 | #define EIGEN_JACOBI_MODULE_H 3 | 4 | #include "Core.h" 5 | 6 | #include "src/Core/util/DisableStupidWarnings.h" 7 | 8 | /** \defgroup Jacobi_Module Jacobi module 9 | * This module provides Jacobi and Givens rotations. 10 | * 11 | * \code 12 | * #include 13 | * \endcode 14 | * 15 | * In addition to listed classes, it defines the two following MatrixBase methods to apply a Jacobi or Givens rotation: 16 | * - MatrixBase::applyOnTheLeft() 17 | * - MatrixBase::applyOnTheRight(). 18 | */ 19 | 20 | #include "src/Jacobi/Jacobi.h" 21 | 22 | #include "src/Core/util/ReenableStupidWarnings.h" 23 | 24 | #endif // EIGEN_JACOBI_MODULE_H 25 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ 26 | -------------------------------------------------------------------------------- /eigen/LU.h: -------------------------------------------------------------------------------- 1 | #ifndef EIGEN_LU_MODULE_H 2 | #define EIGEN_LU_MODULE_H 3 | 4 | #include "Core.h" 5 | 6 | #include "src/Core/util/DisableStupidWarnings.h" 7 | 8 | /** \defgroup LU_Module LU module 9 | * This module includes %LU decomposition and related notions such as matrix inversion and determinant. 10 | * This module defines the following MatrixBase methods: 11 | * - MatrixBase::inverse() 12 | * - MatrixBase::determinant() 13 | * 14 | * \code 15 | * #include 16 | * \endcode 17 | */ 18 | 19 | #include "src/misc/Solve.h" 20 | #include "src/misc/Kernel.h" 21 | #include "src/misc/Image.h" 22 | #include "src/LU/FullPivLU.h" 23 | #include "src/LU/PartialPivLU.h" 24 | #ifdef EIGEN_USE_LAPACKE 25 | #include "src/LU/PartialPivLU_MKL.h" 26 | #endif 27 | #include "src/LU/Determinant.h" 28 | #include "src/LU/Inverse.h" 29 | 30 | #if defined EIGEN_VECTORIZE_SSE 31 | #include "src/LU/arch/Inverse_SSE.h" 32 | #endif 33 | 34 | #ifdef EIGEN2_SUPPORT 35 | #include "src/Eigen2Support/LU.h" 36 | #endif 37 | 38 | #include "src/Core/util/ReenableStupidWarnings.h" 39 | 40 | #endif // EIGEN_LU_MODULE_H 41 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ -------------------------------------------------------------------------------- /eigen/QR.h: -------------------------------------------------------------------------------- 1 | #ifndef EIGEN_QR_MODULE_H 2 | #define EIGEN_QR_MODULE_H 3 | 4 | #include "Core.h" 5 | 6 | #include "src/Core/util/DisableStupidWarnings.h" 7 | 8 | #include "Cholesky.h" 9 | #include "Jacobi.h" 10 | #include "Householder.h" 11 | 12 | /** \defgroup QR_Module QR module 13 | * 14 | * 15 | * 16 | * This module provides various QR decompositions 17 | * This module also provides some MatrixBase methods, including: 18 | * - MatrixBase::qr(), 19 | * 20 | * \code 21 | * #include 22 | * \endcode 23 | */ 24 | 25 | #include "src/misc/Solve.h" 26 | #include "src/QR/HouseholderQR.h" 27 | #include "src/QR/FullPivHouseholderQR.h" 28 | #include "src/QR/ColPivHouseholderQR.h" 29 | #ifdef EIGEN_USE_LAPACKE 30 | #include "src/QR/HouseholderQR_MKL.h" 31 | #include "src/QR/ColPivHouseholderQR_MKL.h" 32 | #endif 33 | 34 | #ifdef EIGEN2_SUPPORT 35 | #include "src/Eigen2Support/QR.h" 36 | #endif 37 | 38 | #include "src/Core/util/ReenableStupidWarnings.h" 39 | 40 | #ifdef EIGEN2_SUPPORT 41 | #include "Eigenvalues" 42 | #endif 43 | 44 | #endif // EIGEN_QR_MODULE_H 45 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ -------------------------------------------------------------------------------- /eigen/SVD.h: -------------------------------------------------------------------------------- 1 | #ifndef EIGEN_SVD_MODULE_H 2 | #define EIGEN_SVD_MODULE_H 3 | 4 | #include "QR.h" 5 | #include "Householder.h" 6 | #include "Jacobi.h" 7 | 8 | #include "src/Core/util/DisableStupidWarnings.h" 9 | 10 | /** \defgroup SVD_Module SVD module 11 | * 12 | * 13 | * 14 | * This module provides SVD decomposition for matrices (both real and complex). 15 | * This decomposition is accessible via the following MatrixBase method: 16 | * - MatrixBase::jacobiSvd() 17 | * 18 | * \code 19 | * #include 20 | * \endcode 21 | */ 22 | 23 | #include "src/misc/Solve.h" 24 | #include "src/SVD/JacobiSVD.h" 25 | #if defined(EIGEN_USE_LAPACKE) && !defined(EIGEN_USE_LAPACKE_STRICT) 26 | #include "src/SVD/JacobiSVD_MKL.h" 27 | #endif 28 | #include "src/SVD/UpperBidiagonalization.h" 29 | 30 | #ifdef EIGEN2_SUPPORT 31 | #include "src/Eigen2Support/SVD.h" 32 | #endif 33 | 34 | #include "src/Core/util/ReenableStupidWarnings.h" 35 | 36 | #endif // EIGEN_SVD_MODULE_H 37 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ -------------------------------------------------------------------------------- /eigen/src/Cholesky/LLT_MKL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to Intel(R) MKL 29 | * LLt decomposition based on LAPACKE_?potrf function. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_LLT_MKL_H 34 | #define EIGEN_LLT_MKL_H 35 | 36 | #include "Eigen/src/Core/util/MKL_support.h" 37 | #include 38 | 39 | namespace Eigen { 40 | 41 | namespace internal { 42 | 43 | template struct mkl_llt; 44 | 45 | #define EIGEN_MKL_LLT(EIGTYPE, MKLTYPE, MKLPREFIX) \ 46 | template<> struct mkl_llt \ 47 | { \ 48 | template \ 49 | static inline typename MatrixType::Index potrf(MatrixType& m, char uplo) \ 50 | { \ 51 | lapack_int matrix_order; \ 52 | lapack_int size, lda, info, StorageOrder; \ 53 | EIGTYPE* a; \ 54 | eigen_assert(m.rows()==m.cols()); \ 55 | /* Set up parameters for ?potrf */ \ 56 | size = m.rows(); \ 57 | StorageOrder = MatrixType::Flags&RowMajorBit?RowMajor:ColMajor; \ 58 | matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \ 59 | a = &(m.coeffRef(0,0)); \ 60 | lda = m.outerStride(); \ 61 | \ 62 | info = LAPACKE_##MKLPREFIX##potrf( matrix_order, uplo, size, (MKLTYPE*)a, lda ); \ 63 | info = (info==0) ? -1 : info>0 ? info-1 : size; \ 64 | return info; \ 65 | } \ 66 | }; \ 67 | template<> struct llt_inplace \ 68 | { \ 69 | template \ 70 | static typename MatrixType::Index blocked(MatrixType& m) \ 71 | { \ 72 | return mkl_llt::potrf(m, 'L'); \ 73 | } \ 74 | template \ 75 | static typename MatrixType::Index rankUpdate(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) \ 76 | { return Eigen::internal::llt_rank_update_lower(mat, vec, sigma); } \ 77 | }; \ 78 | template<> struct llt_inplace \ 79 | { \ 80 | template \ 81 | static typename MatrixType::Index blocked(MatrixType& m) \ 82 | { \ 83 | return mkl_llt::potrf(m, 'U'); \ 84 | } \ 85 | template \ 86 | static typename MatrixType::Index rankUpdate(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) \ 87 | { \ 88 | Transpose matt(mat); \ 89 | return llt_inplace::rankUpdate(matt, vec.conjugate(), sigma); \ 90 | } \ 91 | }; 92 | 93 | EIGEN_MKL_LLT(double, double, d) 94 | EIGEN_MKL_LLT(float, float, s) 95 | EIGEN_MKL_LLT(dcomplex, MKL_Complex16, z) 96 | EIGEN_MKL_LLT(scomplex, MKL_Complex8, c) 97 | 98 | } // end namespace internal 99 | 100 | } // end namespace Eigen 101 | 102 | #endif // EIGEN_LLT_MKL_H -------------------------------------------------------------------------------- /eigen/src/Core/BooleanRedux.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_ALLANDANY_H 11 | #define EIGEN_ALLANDANY_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | template 18 | struct all_unroller 19 | { 20 | enum { 21 | col = (UnrollCount-1) / Derived::RowsAtCompileTime, 22 | row = (UnrollCount-1) % Derived::RowsAtCompileTime 23 | }; 24 | 25 | static inline bool run(const Derived &mat) 26 | { 27 | return all_unroller::run(mat) && mat.coeff(row, col); 28 | } 29 | }; 30 | 31 | template 32 | struct all_unroller 33 | { 34 | static inline bool run(const Derived &/*mat*/) { return true; } 35 | }; 36 | 37 | template 38 | struct all_unroller 39 | { 40 | static inline bool run(const Derived &) { return false; } 41 | }; 42 | 43 | template 44 | struct any_unroller 45 | { 46 | enum { 47 | col = (UnrollCount-1) / Derived::RowsAtCompileTime, 48 | row = (UnrollCount-1) % Derived::RowsAtCompileTime 49 | }; 50 | 51 | static inline bool run(const Derived &mat) 52 | { 53 | return any_unroller::run(mat) || mat.coeff(row, col); 54 | } 55 | }; 56 | 57 | template 58 | struct any_unroller 59 | { 60 | static inline bool run(const Derived & /*mat*/) { return false; } 61 | }; 62 | 63 | template 64 | struct any_unroller 65 | { 66 | static inline bool run(const Derived &) { return false; } 67 | }; 68 | 69 | } // end namespace internal 70 | 71 | /** \returns true if all coefficients are true 72 | * 73 | * Example: \include MatrixBase_all.cpp 74 | * Output: \verbinclude MatrixBase_all.out 75 | * 76 | * \sa any(), Cwise::operator<() 77 | */ 78 | template 79 | inline bool DenseBase::all() const 80 | { 81 | enum { 82 | unroll = SizeAtCompileTime != Dynamic 83 | && CoeffReadCost != Dynamic 84 | && NumTraits::AddCost != Dynamic 85 | && SizeAtCompileTime * (CoeffReadCost + NumTraits::AddCost) <= EIGEN_UNROLLING_LIMIT 86 | }; 87 | if(unroll) 88 | return internal::all_unroller::run(derived()); 89 | else 90 | { 91 | for(Index j = 0; j < cols(); ++j) 92 | for(Index i = 0; i < rows(); ++i) 93 | if (!coeff(i, j)) return false; 94 | return true; 95 | } 96 | } 97 | 98 | /** \returns true if at least one coefficient is true 99 | * 100 | * \sa all() 101 | */ 102 | template 103 | inline bool DenseBase::any() const 104 | { 105 | enum { 106 | unroll = SizeAtCompileTime != Dynamic 107 | && CoeffReadCost != Dynamic 108 | && NumTraits::AddCost != Dynamic 109 | && SizeAtCompileTime * (CoeffReadCost + NumTraits::AddCost) <= EIGEN_UNROLLING_LIMIT 110 | }; 111 | if(unroll) 112 | return internal::any_unroller::run(derived()); 113 | else 114 | { 115 | for(Index j = 0; j < cols(); ++j) 116 | for(Index i = 0; i < rows(); ++i) 117 | if (coeff(i, j)) return true; 118 | return false; 119 | } 120 | } 121 | 122 | /** \returns the number of coefficients which evaluate to true 123 | * 124 | * \sa all(), any() 125 | */ 126 | template 127 | inline typename DenseBase::Index DenseBase::count() const 128 | { 129 | return derived().template cast().template cast().sum(); 130 | } 131 | 132 | /** \returns true is \c *this contains at least one Not A Number (NaN). 133 | * 134 | * \sa allFinite() 135 | */ 136 | template 137 | inline bool DenseBase::hasNaN() const 138 | { 139 | return !((derived().array()==derived().array()).all()); 140 | } 141 | 142 | /** \returns true if \c *this contains only finite numbers, i.e., no NaN and no +/-INF values. 143 | * 144 | * \sa hasNaN() 145 | */ 146 | template 147 | inline bool DenseBase::allFinite() const 148 | { 149 | return !((derived()-derived()).hasNaN()); 150 | } 151 | 152 | } // end namespace Eigen 153 | 154 | #endif // EIGEN_ALLANDANY_H -------------------------------------------------------------------------------- /eigen/src/Core/CoreIterators.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2010 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_COREITERATORS_H 11 | #define EIGEN_COREITERATORS_H 12 | 13 | namespace Eigen { 14 | 15 | /* This file contains the respective InnerIterator definition of the expressions defined in Eigen/Core 16 | */ 17 | 18 | /** \ingroup SparseCore_Module 19 | * \class InnerIterator 20 | * \brief An InnerIterator allows to loop over the element of a sparse (or dense) matrix or expression 21 | * 22 | * todo 23 | */ 24 | 25 | // generic version for dense matrix and expressions 26 | template class DenseBase::InnerIterator 27 | { 28 | protected: 29 | typedef typename Derived::Scalar Scalar; 30 | typedef typename Derived::Index Index; 31 | 32 | enum { IsRowMajor = (Derived::Flags&RowMajorBit)==RowMajorBit }; 33 | public: 34 | EIGEN_STRONG_INLINE InnerIterator(const Derived& expr, Index outer) 35 | : m_expression(expr), m_inner(0), m_outer(outer), m_end(expr.innerSize()) 36 | {} 37 | 38 | EIGEN_STRONG_INLINE Scalar value() const 39 | { 40 | return (IsRowMajor) ? m_expression.coeff(m_outer, m_inner) 41 | : m_expression.coeff(m_inner, m_outer); 42 | } 43 | 44 | EIGEN_STRONG_INLINE InnerIterator& operator++() { m_inner++; return *this; } 45 | 46 | EIGEN_STRONG_INLINE Index index() const { return m_inner; } 47 | inline Index row() const { return IsRowMajor ? m_outer : index(); } 48 | inline Index col() const { return IsRowMajor ? index() : m_outer; } 49 | 50 | EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; } 51 | 52 | protected: 53 | const Derived& m_expression; 54 | Index m_inner; 55 | const Index m_outer; 56 | const Index m_end; 57 | }; 58 | 59 | } // end namespace Eigen 60 | 61 | #endif // EIGEN_COREITERATORS_H -------------------------------------------------------------------------------- /eigen/src/Core/CwiseUnaryOp.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2010 Gael Guennebaud 5 | // Copyright (C) 2006-2008 Benoit Jacob 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_CWISE_UNARY_OP_H 12 | #define EIGEN_CWISE_UNARY_OP_H 13 | 14 | namespace Eigen { 15 | 16 | /** \class CwiseUnaryOp 17 | * \ingroup Core_Module 18 | * 19 | * \brief Generic expression where a coefficient-wise unary operator is applied to an expression 20 | * 21 | * \param UnaryOp template functor implementing the operator 22 | * \param XprType the type of the expression to which we are applying the unary operator 23 | * 24 | * This class represents an expression where a unary operator is applied to an expression. 25 | * It is the return type of all operations taking exactly 1 input expression, regardless of the 26 | * presence of other inputs such as scalars. For example, the operator* in the expression 3*matrix 27 | * is considered unary, because only the right-hand side is an expression, and its 28 | * return type is a specialization of CwiseUnaryOp. 29 | * 30 | * Most of the time, this is the only way that it is used, so you typically don't have to name 31 | * CwiseUnaryOp types explicitly. 32 | * 33 | * \sa MatrixBase::unaryExpr(const CustomUnaryOp &) const, class CwiseBinaryOp, class CwiseNullaryOp 34 | */ 35 | 36 | namespace internal { 37 | template 38 | struct traits > 39 | : traits 40 | { 41 | typedef typename result_of< 42 | UnaryOp(typename XprType::Scalar) 43 | >::type Scalar; 44 | typedef typename XprType::Nested XprTypeNested; 45 | typedef typename remove_reference::type _XprTypeNested; 46 | enum { 47 | Flags = _XprTypeNested::Flags & ( 48 | HereditaryBits | LinearAccessBit | AlignedBit 49 | | (functor_traits::PacketAccess ? PacketAccessBit : 0)), 50 | CoeffReadCost = EIGEN_ADD_COST(_XprTypeNested::CoeffReadCost, functor_traits::Cost) 51 | }; 52 | }; 53 | } 54 | 55 | template 56 | class CwiseUnaryOpImpl; 57 | 58 | template 59 | class CwiseUnaryOp : internal::no_assignment_operator, 60 | public CwiseUnaryOpImpl::StorageKind> 61 | { 62 | public: 63 | 64 | typedef typename CwiseUnaryOpImpl::StorageKind>::Base Base; 65 | EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp) 66 | 67 | inline CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp()) 68 | : m_xpr(xpr), m_functor(func) {} 69 | 70 | EIGEN_STRONG_INLINE Index rows() const { return m_xpr.rows(); } 71 | EIGEN_STRONG_INLINE Index cols() const { return m_xpr.cols(); } 72 | 73 | /** \returns the functor representing the unary operation */ 74 | const UnaryOp& functor() const { return m_functor; } 75 | 76 | /** \returns the nested expression */ 77 | const typename internal::remove_all::type& 78 | nestedExpression() const { return m_xpr; } 79 | 80 | /** \returns the nested expression */ 81 | typename internal::remove_all::type& 82 | nestedExpression() { return m_xpr.const_cast_derived(); } 83 | 84 | protected: 85 | typename XprType::Nested m_xpr; 86 | const UnaryOp m_functor; 87 | }; 88 | 89 | // This is the generic implementation for dense storage. 90 | // It can be used for any expression types implementing the dense concept. 91 | template 92 | class CwiseUnaryOpImpl 93 | : public internal::dense_xpr_base >::type 94 | { 95 | public: 96 | 97 | typedef CwiseUnaryOp Derived; 98 | typedef typename internal::dense_xpr_base >::type Base; 99 | EIGEN_DENSE_PUBLIC_INTERFACE(Derived) 100 | 101 | EIGEN_STRONG_INLINE const Scalar coeff(Index rowId, Index colId) const 102 | { 103 | return derived().functor()(derived().nestedExpression().coeff(rowId, colId)); 104 | } 105 | 106 | template 107 | EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId) const 108 | { 109 | return derived().functor().packetOp(derived().nestedExpression().template packet(rowId, colId)); 110 | } 111 | 112 | EIGEN_STRONG_INLINE const Scalar coeff(Index index) const 113 | { 114 | return derived().functor()(derived().nestedExpression().coeff(index)); 115 | } 116 | 117 | template 118 | EIGEN_STRONG_INLINE PacketScalar packet(Index index) const 119 | { 120 | return derived().functor().packetOp(derived().nestedExpression().template packet(index)); 121 | } 122 | }; 123 | 124 | } // end namespace Eigen 125 | 126 | #endif // EIGEN_CWISE_UNARY_OP_H -------------------------------------------------------------------------------- /eigen/src/Core/CwiseUnaryView.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009-2010 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_CWISE_UNARY_VIEW_H 11 | #define EIGEN_CWISE_UNARY_VIEW_H 12 | 13 | namespace Eigen { 14 | 15 | /** \class CwiseUnaryView 16 | * \ingroup Core_Module 17 | * 18 | * \brief Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector 19 | * 20 | * \param ViewOp template functor implementing the view 21 | * \param MatrixType the type of the matrix we are applying the unary operator 22 | * 23 | * This class represents a lvalue expression of a generic unary view operator of a matrix or a vector. 24 | * It is the return type of real() and imag(), and most of the time this is the only way it is used. 25 | * 26 | * \sa MatrixBase::unaryViewExpr(const CustomUnaryOp &) const, class CwiseUnaryOp 27 | */ 28 | 29 | namespace internal { 30 | template 31 | struct traits > 32 | : traits 33 | { 34 | typedef typename result_of< 35 | ViewOp(typename traits::Scalar) 36 | >::type Scalar; 37 | typedef typename MatrixType::Nested MatrixTypeNested; 38 | typedef typename remove_all::type _MatrixTypeNested; 39 | enum { 40 | Flags = (traits<_MatrixTypeNested>::Flags & (HereditaryBits | LvalueBit | LinearAccessBit | DirectAccessBit)), 41 | CoeffReadCost = EIGEN_ADD_COST(traits<_MatrixTypeNested>::CoeffReadCost, functor_traits::Cost), 42 | MatrixTypeInnerStride = inner_stride_at_compile_time::ret, 43 | // need to cast the sizeof's from size_t to int explicitly, otherwise: 44 | // "error: no integral type can represent all of the enumerator values 45 | InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic 46 | ? int(Dynamic) 47 | : int(MatrixTypeInnerStride) * int(sizeof(typename traits::Scalar) / sizeof(Scalar)), 48 | OuterStrideAtCompileTime = outer_stride_at_compile_time::ret == Dynamic 49 | ? int(Dynamic) 50 | : outer_stride_at_compile_time::ret * int(sizeof(typename traits::Scalar) / sizeof(Scalar)) 51 | }; 52 | }; 53 | } 54 | 55 | template 56 | class CwiseUnaryViewImpl; 57 | 58 | template 59 | class CwiseUnaryView : public CwiseUnaryViewImpl::StorageKind> 60 | { 61 | public: 62 | 63 | typedef typename CwiseUnaryViewImpl::StorageKind>::Base Base; 64 | EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView) 65 | 66 | inline CwiseUnaryView(const MatrixType& mat, const ViewOp& func = ViewOp()) 67 | : m_matrix(mat), m_functor(func) {} 68 | 69 | EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView) 70 | 71 | EIGEN_STRONG_INLINE Index rows() const { return m_matrix.rows(); } 72 | EIGEN_STRONG_INLINE Index cols() const { return m_matrix.cols(); } 73 | 74 | /** \returns the functor representing unary operation */ 75 | const ViewOp& functor() const { return m_functor; } 76 | 77 | /** \returns the nested expression */ 78 | const typename internal::remove_all::type& 79 | nestedExpression() const { return m_matrix; } 80 | 81 | /** \returns the nested expression */ 82 | typename internal::remove_all::type& 83 | nestedExpression() { return m_matrix.const_cast_derived(); } 84 | 85 | protected: 86 | // FIXME changed from MatrixType::Nested because of a weird compilation error with sun CC 87 | typename internal::nested::type m_matrix; 88 | ViewOp m_functor; 89 | }; 90 | 91 | template 92 | class CwiseUnaryViewImpl 93 | : public internal::dense_xpr_base< CwiseUnaryView >::type 94 | { 95 | public: 96 | 97 | typedef CwiseUnaryView Derived; 98 | typedef typename internal::dense_xpr_base< CwiseUnaryView >::type Base; 99 | 100 | EIGEN_DENSE_PUBLIC_INTERFACE(Derived) 101 | EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl) 102 | 103 | inline Scalar* data() { return &coeffRef(0); } 104 | inline const Scalar* data() const { return &coeff(0); } 105 | 106 | inline Index innerStride() const 107 | { 108 | return derived().nestedExpression().innerStride() * sizeof(typename internal::traits::Scalar) / sizeof(Scalar); 109 | } 110 | 111 | inline Index outerStride() const 112 | { 113 | return derived().nestedExpression().outerStride() * sizeof(typename internal::traits::Scalar) / sizeof(Scalar); 114 | } 115 | 116 | EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const 117 | { 118 | return derived().functor()(derived().nestedExpression().coeff(row, col)); 119 | } 120 | 121 | EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const 122 | { 123 | return derived().functor()(derived().nestedExpression().coeff(index)); 124 | } 125 | 126 | EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) 127 | { 128 | return derived().functor()(const_cast_derived().nestedExpression().coeffRef(row, col)); 129 | } 130 | 131 | EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) 132 | { 133 | return derived().functor()(const_cast_derived().nestedExpression().coeffRef(index)); 134 | } 135 | }; 136 | 137 | } // end namespace Eigen 138 | 139 | #endif // EIGEN_CWISE_UNARY_VIEW_H -------------------------------------------------------------------------------- /eigen/src/Core/EigenBase.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009 Benoit Jacob 5 | // Copyright (C) 2009 Gael Guennebaud 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_EIGENBASE_H 12 | #define EIGEN_EIGENBASE_H 13 | 14 | namespace Eigen { 15 | 16 | /** Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T). 17 | * 18 | * In other words, an EigenBase object is an object that can be copied into a MatrixBase. 19 | * 20 | * Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc. 21 | * 22 | * Notice that this class is trivial, it is only used to disambiguate overloaded functions. 23 | * 24 | * \sa \ref TopicClassHierarchy 25 | */ 26 | template struct EigenBase 27 | { 28 | // typedef typename internal::plain_matrix_type::type PlainObject; 29 | 30 | typedef typename internal::traits::StorageKind StorageKind; 31 | typedef typename internal::traits::Index Index; 32 | 33 | /** \returns a reference to the derived object */ 34 | Derived& derived() { return *static_cast(this); } 35 | /** \returns a const reference to the derived object */ 36 | const Derived& derived() const { return *static_cast(this); } 37 | 38 | inline Derived& const_cast_derived() const 39 | { return *static_cast(const_cast(this)); } 40 | inline const Derived& const_derived() const 41 | { return *static_cast(this); } 42 | 43 | /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ 44 | inline Index rows() const { return derived().rows(); } 45 | /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ 46 | inline Index cols() const { return derived().cols(); } 47 | /** \returns the number of coefficients, which is rows()*cols(). 48 | * \sa rows(), cols(), SizeAtCompileTime. */ 49 | inline Index size() const { return rows() * cols(); } 50 | 51 | /** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */ 52 | template inline void evalTo(Dest& dst) const 53 | { derived().evalTo(dst); } 54 | 55 | /** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */ 56 | template inline void addTo(Dest& dst) const 57 | { 58 | // This is the default implementation, 59 | // derived class can reimplement it in a more optimized way. 60 | typename Dest::PlainObject res(rows(),cols()); 61 | evalTo(res); 62 | dst += res; 63 | } 64 | 65 | /** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */ 66 | template inline void subTo(Dest& dst) const 67 | { 68 | // This is the default implementation, 69 | // derived class can reimplement it in a more optimized way. 70 | typename Dest::PlainObject res(rows(),cols()); 71 | evalTo(res); 72 | dst -= res; 73 | } 74 | 75 | /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */ 76 | template inline void applyThisOnTheRight(Dest& dst) const 77 | { 78 | // This is the default implementation, 79 | // derived class can reimplement it in a more optimized way. 80 | dst = dst * this->derived(); 81 | } 82 | 83 | /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */ 84 | template inline void applyThisOnTheLeft(Dest& dst) const 85 | { 86 | // This is the default implementation, 87 | // derived class can reimplement it in a more optimized way. 88 | dst = this->derived() * dst; 89 | } 90 | 91 | }; 92 | 93 | /*************************************************************************** 94 | * Implementation of matrix base methods 95 | ***************************************************************************/ 96 | 97 | /** \brief Copies the generic expression \a other into *this. 98 | * 99 | * \details The expression must provide a (templated) evalTo(Derived& dst) const 100 | * function which does the actual job. In practice, this allows any user to write 101 | * its own special matrix without having to modify MatrixBase 102 | * 103 | * \returns a reference to *this. 104 | */ 105 | template 106 | template 107 | Derived& DenseBase::operator=(const EigenBase &other) 108 | { 109 | other.derived().evalTo(derived()); 110 | return derived(); 111 | } 112 | 113 | template 114 | template 115 | Derived& DenseBase::operator+=(const EigenBase &other) 116 | { 117 | other.derived().addTo(derived()); 118 | return derived(); 119 | } 120 | 121 | template 122 | template 123 | Derived& DenseBase::operator-=(const EigenBase &other) 124 | { 125 | other.derived().subTo(derived()); 126 | return derived(); 127 | } 128 | 129 | } // end namespace Eigen 130 | 131 | #endif // EIGEN_EIGENBASE_H -------------------------------------------------------------------------------- /eigen/src/Core/Flagged.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008 Benoit Jacob 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_FLAGGED_H 11 | #define EIGEN_FLAGGED_H 12 | 13 | namespace Eigen { 14 | 15 | /** \class Flagged 16 | * \ingroup Core_Module 17 | * 18 | * \brief Expression with modified flags 19 | * 20 | * \param ExpressionType the type of the object of which we are modifying the flags 21 | * \param Added the flags added to the expression 22 | * \param Removed the flags removed from the expression (has priority over Added). 23 | * 24 | * This class represents an expression whose flags have been modified. 25 | * It is the return type of MatrixBase::flagged() 26 | * and most of the time this is the only way it is used. 27 | * 28 | * \sa MatrixBase::flagged() 29 | */ 30 | 31 | namespace internal { 32 | template 33 | struct traits > : traits 34 | { 35 | enum { Flags = (ExpressionType::Flags | Added) & ~Removed }; 36 | }; 37 | } 38 | 39 | template class Flagged 40 | : public MatrixBase > 41 | { 42 | public: 43 | 44 | typedef MatrixBase Base; 45 | 46 | EIGEN_DENSE_PUBLIC_INTERFACE(Flagged) 47 | typedef typename internal::conditional::ret, 48 | ExpressionType, const ExpressionType&>::type ExpressionTypeNested; 49 | typedef typename ExpressionType::InnerIterator InnerIterator; 50 | 51 | inline Flagged(const ExpressionType& matrix) : m_matrix(matrix) {} 52 | 53 | inline Index rows() const { return m_matrix.rows(); } 54 | inline Index cols() const { return m_matrix.cols(); } 55 | inline Index outerStride() const { return m_matrix.outerStride(); } 56 | inline Index innerStride() const { return m_matrix.innerStride(); } 57 | 58 | inline CoeffReturnType coeff(Index row, Index col) const 59 | { 60 | return m_matrix.coeff(row, col); 61 | } 62 | 63 | inline CoeffReturnType coeff(Index index) const 64 | { 65 | return m_matrix.coeff(index); 66 | } 67 | 68 | inline const Scalar& coeffRef(Index row, Index col) const 69 | { 70 | return m_matrix.const_cast_derived().coeffRef(row, col); 71 | } 72 | 73 | inline const Scalar& coeffRef(Index index) const 74 | { 75 | return m_matrix.const_cast_derived().coeffRef(index); 76 | } 77 | 78 | inline Scalar& coeffRef(Index row, Index col) 79 | { 80 | return m_matrix.const_cast_derived().coeffRef(row, col); 81 | } 82 | 83 | inline Scalar& coeffRef(Index index) 84 | { 85 | return m_matrix.const_cast_derived().coeffRef(index); 86 | } 87 | 88 | template 89 | inline const PacketScalar packet(Index row, Index col) const 90 | { 91 | return m_matrix.template packet(row, col); 92 | } 93 | 94 | template 95 | inline void writePacket(Index row, Index col, const PacketScalar& x) 96 | { 97 | m_matrix.const_cast_derived().template writePacket(row, col, x); 98 | } 99 | 100 | template 101 | inline const PacketScalar packet(Index index) const 102 | { 103 | return m_matrix.template packet(index); 104 | } 105 | 106 | template 107 | inline void writePacket(Index index, const PacketScalar& x) 108 | { 109 | m_matrix.const_cast_derived().template writePacket(index, x); 110 | } 111 | 112 | const ExpressionType& _expression() const { return m_matrix; } 113 | 114 | template 115 | typename ExpressionType::PlainObject solveTriangular(const MatrixBase& other) const; 116 | 117 | template 118 | void solveTriangularInPlace(const MatrixBase& other) const; 119 | 120 | protected: 121 | ExpressionTypeNested m_matrix; 122 | }; 123 | 124 | /** \returns an expression of *this with added and removed flags 125 | * 126 | * This is mostly for internal use. 127 | * 128 | * \sa class Flagged 129 | */ 130 | template 131 | template 132 | inline const Flagged 133 | DenseBase::flagged() const 134 | { 135 | return derived(); 136 | } 137 | 138 | } // end namespace Eigen 139 | 140 | #endif // EIGEN_FLAGGED_H -------------------------------------------------------------------------------- /eigen/src/Core/ForceAlignedAccess.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009-2010 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_FORCEALIGNEDACCESS_H 11 | #define EIGEN_FORCEALIGNEDACCESS_H 12 | 13 | namespace Eigen { 14 | 15 | /** \class ForceAlignedAccess 16 | * \ingroup Core_Module 17 | * 18 | * \brief Enforce aligned packet loads and stores regardless of what is requested 19 | * 20 | * \param ExpressionType the type of the object of which we are forcing aligned packet access 21 | * 22 | * This class is the return type of MatrixBase::forceAlignedAccess() 23 | * and most of the time this is the only way it is used. 24 | * 25 | * \sa MatrixBase::forceAlignedAccess() 26 | */ 27 | 28 | namespace internal { 29 | template 30 | struct traits > : public traits 31 | {}; 32 | } 33 | 34 | template class ForceAlignedAccess 35 | : public internal::dense_xpr_base< ForceAlignedAccess >::type 36 | { 37 | public: 38 | 39 | typedef typename internal::dense_xpr_base::type Base; 40 | EIGEN_DENSE_PUBLIC_INTERFACE(ForceAlignedAccess) 41 | 42 | inline ForceAlignedAccess(const ExpressionType& matrix) : m_expression(matrix) {} 43 | 44 | inline Index rows() const { return m_expression.rows(); } 45 | inline Index cols() const { return m_expression.cols(); } 46 | inline Index outerStride() const { return m_expression.outerStride(); } 47 | inline Index innerStride() const { return m_expression.innerStride(); } 48 | 49 | inline const CoeffReturnType coeff(Index row, Index col) const 50 | { 51 | return m_expression.coeff(row, col); 52 | } 53 | 54 | inline Scalar& coeffRef(Index row, Index col) 55 | { 56 | return m_expression.const_cast_derived().coeffRef(row, col); 57 | } 58 | 59 | inline const CoeffReturnType coeff(Index index) const 60 | { 61 | return m_expression.coeff(index); 62 | } 63 | 64 | inline Scalar& coeffRef(Index index) 65 | { 66 | return m_expression.const_cast_derived().coeffRef(index); 67 | } 68 | 69 | template 70 | inline const PacketScalar packet(Index row, Index col) const 71 | { 72 | return m_expression.template packet(row, col); 73 | } 74 | 75 | template 76 | inline void writePacket(Index row, Index col, const PacketScalar& x) 77 | { 78 | m_expression.const_cast_derived().template writePacket(row, col, x); 79 | } 80 | 81 | template 82 | inline const PacketScalar packet(Index index) const 83 | { 84 | return m_expression.template packet(index); 85 | } 86 | 87 | template 88 | inline void writePacket(Index index, const PacketScalar& x) 89 | { 90 | m_expression.const_cast_derived().template writePacket(index, x); 91 | } 92 | 93 | operator const ExpressionType&() const { return m_expression; } 94 | 95 | protected: 96 | const ExpressionType& m_expression; 97 | 98 | private: 99 | ForceAlignedAccess& operator=(const ForceAlignedAccess&); 100 | }; 101 | 102 | /** \returns an expression of *this with forced aligned access 103 | * \sa forceAlignedAccessIf(),class ForceAlignedAccess 104 | */ 105 | template 106 | inline const ForceAlignedAccess 107 | MatrixBase::forceAlignedAccess() const 108 | { 109 | return ForceAlignedAccess(derived()); 110 | } 111 | 112 | /** \returns an expression of *this with forced aligned access 113 | * \sa forceAlignedAccessIf(), class ForceAlignedAccess 114 | */ 115 | template 116 | inline ForceAlignedAccess 117 | MatrixBase::forceAlignedAccess() 118 | { 119 | return ForceAlignedAccess(derived()); 120 | } 121 | 122 | /** \returns an expression of *this with forced aligned access if \a Enable is true. 123 | * \sa forceAlignedAccess(), class ForceAlignedAccess 124 | */ 125 | template 126 | template 127 | inline typename internal::add_const_on_value_type,Derived&>::type>::type 128 | MatrixBase::forceAlignedAccessIf() const 129 | { 130 | return derived(); 131 | } 132 | 133 | /** \returns an expression of *this with forced aligned access if \a Enable is true. 134 | * \sa forceAlignedAccess(), class ForceAlignedAccess 135 | */ 136 | template 137 | template 138 | inline typename internal::conditional,Derived&>::type 139 | MatrixBase::forceAlignedAccessIf() 140 | { 141 | return derived(); 142 | } 143 | 144 | } // end namespace Eigen 145 | 146 | #endif // EIGEN_FORCEALIGNEDACCESS_H -------------------------------------------------------------------------------- /eigen/src/Core/Fuzzy.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2006-2008 Benoit Jacob 5 | // Copyright (C) 2008 Gael Guennebaud 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_FUZZY_H 12 | #define EIGEN_FUZZY_H 13 | 14 | namespace Eigen { 15 | 16 | namespace internal 17 | { 18 | 19 | template::IsInteger> 20 | struct isApprox_selector 21 | { 22 | static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec) 23 | { 24 | using std::min; 25 | typename internal::nested::type nested(x); 26 | typename internal::nested::type otherNested(y); 27 | return (nested - otherNested).cwiseAbs2().sum() <= prec * prec * (min)(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum()); 28 | } 29 | }; 30 | 31 | template 32 | struct isApprox_selector 33 | { 34 | static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar&) 35 | { 36 | return x.matrix() == y.matrix(); 37 | } 38 | }; 39 | 40 | template::IsInteger> 41 | struct isMuchSmallerThan_object_selector 42 | { 43 | static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec) 44 | { 45 | return x.cwiseAbs2().sum() <= numext::abs2(prec) * y.cwiseAbs2().sum(); 46 | } 47 | }; 48 | 49 | template 50 | struct isMuchSmallerThan_object_selector 51 | { 52 | static bool run(const Derived& x, const OtherDerived&, const typename Derived::RealScalar&) 53 | { 54 | return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix(); 55 | } 56 | }; 57 | 58 | template::IsInteger> 59 | struct isMuchSmallerThan_scalar_selector 60 | { 61 | static bool run(const Derived& x, const typename Derived::RealScalar& y, const typename Derived::RealScalar& prec) 62 | { 63 | return x.cwiseAbs2().sum() <= numext::abs2(prec * y); 64 | } 65 | }; 66 | 67 | template 68 | struct isMuchSmallerThan_scalar_selector 69 | { 70 | static bool run(const Derived& x, const typename Derived::RealScalar&, const typename Derived::RealScalar&) 71 | { 72 | return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix(); 73 | } 74 | }; 75 | 76 | } // end namespace internal 77 | 78 | 79 | /** \returns \c true if \c *this is approximately equal to \a other, within the precision 80 | * determined by \a prec. 81 | * 82 | * \note The fuzzy compares are done multiplicatively. Two vectors \f$ v \f$ and \f$ w \f$ 83 | * are considered to be approximately equal within precision \f$ p \f$ if 84 | * \f[ \Vert v - w \Vert \leqslant p\,\min(\Vert v\Vert, \Vert w\Vert). \f] 85 | * For matrices, the comparison is done using the Hilbert-Schmidt norm (aka Frobenius norm 86 | * L2 norm). 87 | * 88 | * \note Because of the multiplicativeness of this comparison, one can't use this function 89 | * to check whether \c *this is approximately equal to the zero matrix or vector. 90 | * Indeed, \c isApprox(zero) returns false unless \c *this itself is exactly the zero matrix 91 | * or vector. If you want to test whether \c *this is zero, use internal::isMuchSmallerThan(const 92 | * RealScalar&, RealScalar) instead. 93 | * 94 | * \sa internal::isMuchSmallerThan(const RealScalar&, RealScalar) const 95 | */ 96 | template 97 | template 98 | bool DenseBase::isApprox( 99 | const DenseBase& other, 100 | const RealScalar& prec 101 | ) const 102 | { 103 | return internal::isApprox_selector::run(derived(), other.derived(), prec); 104 | } 105 | 106 | /** \returns \c true if the norm of \c *this is much smaller than \a other, 107 | * within the precision determined by \a prec. 108 | * 109 | * \note The fuzzy compares are done multiplicatively. A vector \f$ v \f$ is 110 | * considered to be much smaller than \f$ x \f$ within precision \f$ p \f$ if 111 | * \f[ \Vert v \Vert \leqslant p\,\vert x\vert. \f] 112 | * 113 | * For matrices, the comparison is done using the Hilbert-Schmidt norm. For this reason, 114 | * the value of the reference scalar \a other should come from the Hilbert-Schmidt norm 115 | * of a reference matrix of same dimensions. 116 | * 117 | * \sa isApprox(), isMuchSmallerThan(const DenseBase&, RealScalar) const 118 | */ 119 | template 120 | bool DenseBase::isMuchSmallerThan( 121 | const typename NumTraits::Real& other, 122 | const RealScalar& prec 123 | ) const 124 | { 125 | return internal::isMuchSmallerThan_scalar_selector::run(derived(), other, prec); 126 | } 127 | 128 | /** \returns \c true if the norm of \c *this is much smaller than the norm of \a other, 129 | * within the precision determined by \a prec. 130 | * 131 | * \note The fuzzy compares are done multiplicatively. A vector \f$ v \f$ is 132 | * considered to be much smaller than a vector \f$ w \f$ within precision \f$ p \f$ if 133 | * \f[ \Vert v \Vert \leqslant p\,\Vert w\Vert. \f] 134 | * For matrices, the comparison is done using the Hilbert-Schmidt norm. 135 | * 136 | * \sa isApprox(), isMuchSmallerThan(const RealScalar&, RealScalar) const 137 | */ 138 | template 139 | template 140 | bool DenseBase::isMuchSmallerThan( 141 | const DenseBase& other, 142 | const RealScalar& prec 143 | ) const 144 | { 145 | return internal::isMuchSmallerThan_object_selector::run(derived(), other.derived(), prec); 146 | } 147 | 148 | } // end namespace Eigen 149 | 150 | #endif // EIGEN_FUZZY_H -------------------------------------------------------------------------------- /eigen/src/Core/GlobalFunctions.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2010-2012 Gael Guennebaud 5 | // Copyright (C) 2010 Benoit Jacob 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_GLOBAL_FUNCTIONS_H 12 | #define EIGEN_GLOBAL_FUNCTIONS_H 13 | 14 | #define EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(NAME,FUNCTOR) \ 15 | template \ 16 | inline const Eigen::CwiseUnaryOp, const Derived> \ 17 | NAME(const Eigen::ArrayBase& x) { \ 18 | return x.derived(); \ 19 | } 20 | 21 | #define EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(NAME,FUNCTOR) \ 22 | \ 23 | template \ 24 | struct NAME##_retval > \ 25 | { \ 26 | typedef const Eigen::CwiseUnaryOp, const Derived> type; \ 27 | }; \ 28 | template \ 29 | struct NAME##_impl > \ 30 | { \ 31 | static inline typename NAME##_retval >::type run(const Eigen::ArrayBase& x) \ 32 | { \ 33 | return x.derived(); \ 34 | } \ 35 | }; 36 | 37 | 38 | namespace Eigen 39 | { 40 | EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(real,scalar_real_op) 41 | EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(imag,scalar_imag_op) 42 | EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(conj,scalar_conjugate_op) 43 | EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sin,scalar_sin_op) 44 | EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cos,scalar_cos_op) 45 | EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asin,scalar_asin_op) 46 | EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acos,scalar_acos_op) 47 | EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tan,scalar_tan_op) 48 | EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(exp,scalar_exp_op) 49 | EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log,scalar_log_op) 50 | EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs,scalar_abs_op) 51 | EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sqrt,scalar_sqrt_op) 52 | 53 | template 54 | inline const Eigen::CwiseUnaryOp, const Derived> 55 | pow(const Eigen::ArrayBase& x, const typename Derived::Scalar& exponent) { 56 | return x.derived().pow(exponent); 57 | } 58 | 59 | template 60 | inline const Eigen::CwiseBinaryOp, const Derived, const Derived> 61 | pow(const Eigen::ArrayBase& x, const Eigen::ArrayBase& exponents) 62 | { 63 | return Eigen::CwiseBinaryOp, const Derived, const Derived>( 64 | x.derived(), 65 | exponents.derived() 66 | ); 67 | } 68 | 69 | /** 70 | * \brief Component-wise division of a scalar by array elements. 71 | **/ 72 | template 73 | inline const Eigen::CwiseUnaryOp, const Derived> 74 | operator/(const typename Derived::Scalar& s, const Eigen::ArrayBase& a) 75 | { 76 | return Eigen::CwiseUnaryOp, const Derived>( 77 | a.derived(), 78 | Eigen::internal::scalar_inverse_mult_op(s) 79 | ); 80 | } 81 | 82 | namespace internal 83 | { 84 | EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(real,scalar_real_op) 85 | EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(imag,scalar_imag_op) 86 | EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(abs2,scalar_abs2_op) 87 | } 88 | } 89 | 90 | // TODO: cleanly disable those functions that are not supported on Array (numext::real_ref, internal::random, internal::isApprox...) 91 | 92 | #endif // EIGEN_GLOBAL_FUNCTIONS_H -------------------------------------------------------------------------------- /eigen/src/Core/NestByValue.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008 Gael Guennebaud 5 | // Copyright (C) 2006-2008 Benoit Jacob 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_NESTBYVALUE_H 12 | #define EIGEN_NESTBYVALUE_H 13 | 14 | namespace Eigen { 15 | 16 | /** \class NestByValue 17 | * \ingroup Core_Module 18 | * 19 | * \brief Expression which must be nested by value 20 | * 21 | * \param ExpressionType the type of the object of which we are requiring nesting-by-value 22 | * 23 | * This class is the return type of MatrixBase::nestByValue() 24 | * and most of the time this is the only way it is used. 25 | * 26 | * \sa MatrixBase::nestByValue() 27 | */ 28 | 29 | namespace internal { 30 | template 31 | struct traits > : public traits 32 | {}; 33 | } 34 | 35 | template class NestByValue 36 | : public internal::dense_xpr_base< NestByValue >::type 37 | { 38 | public: 39 | 40 | typedef typename internal::dense_xpr_base::type Base; 41 | EIGEN_DENSE_PUBLIC_INTERFACE(NestByValue) 42 | 43 | inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {} 44 | 45 | inline Index rows() const { return m_expression.rows(); } 46 | inline Index cols() const { return m_expression.cols(); } 47 | inline Index outerStride() const { return m_expression.outerStride(); } 48 | inline Index innerStride() const { return m_expression.innerStride(); } 49 | 50 | inline const CoeffReturnType coeff(Index row, Index col) const 51 | { 52 | return m_expression.coeff(row, col); 53 | } 54 | 55 | inline Scalar& coeffRef(Index row, Index col) 56 | { 57 | return m_expression.const_cast_derived().coeffRef(row, col); 58 | } 59 | 60 | inline const CoeffReturnType coeff(Index index) const 61 | { 62 | return m_expression.coeff(index); 63 | } 64 | 65 | inline Scalar& coeffRef(Index index) 66 | { 67 | return m_expression.const_cast_derived().coeffRef(index); 68 | } 69 | 70 | template 71 | inline const PacketScalar packet(Index row, Index col) const 72 | { 73 | return m_expression.template packet(row, col); 74 | } 75 | 76 | template 77 | inline void writePacket(Index row, Index col, const PacketScalar& x) 78 | { 79 | m_expression.const_cast_derived().template writePacket(row, col, x); 80 | } 81 | 82 | template 83 | inline const PacketScalar packet(Index index) const 84 | { 85 | return m_expression.template packet(index); 86 | } 87 | 88 | template 89 | inline void writePacket(Index index, const PacketScalar& x) 90 | { 91 | m_expression.const_cast_derived().template writePacket(index, x); 92 | } 93 | 94 | operator const ExpressionType&() const { return m_expression; } 95 | 96 | protected: 97 | const ExpressionType m_expression; 98 | }; 99 | 100 | /** \returns an expression of the temporary version of *this. 101 | */ 102 | template 103 | inline const NestByValue 104 | DenseBase::nestByValue() const 105 | { 106 | return NestByValue(derived()); 107 | } 108 | 109 | } // end namespace Eigen 110 | 111 | #endif // EIGEN_NESTBYVALUE_H -------------------------------------------------------------------------------- /eigen/src/Core/NoAlias.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_NOALIAS_H 11 | #define EIGEN_NOALIAS_H 12 | 13 | namespace Eigen { 14 | 15 | /** \class NoAlias 16 | * \ingroup Core_Module 17 | * 18 | * \brief Pseudo expression providing an operator = assuming no aliasing 19 | * 20 | * \param ExpressionType the type of the object on which to do the lazy assignment 21 | * 22 | * This class represents an expression with special assignment operators 23 | * assuming no aliasing between the target expression and the source expression. 24 | * More precisely it alloas to bypass the EvalBeforeAssignBit flag of the source expression. 25 | * It is the return type of MatrixBase::noalias() 26 | * and most of the time this is the only way it is used. 27 | * 28 | * \sa MatrixBase::noalias() 29 | */ 30 | template class StorageBase> 31 | class NoAlias 32 | { 33 | typedef typename ExpressionType::Scalar Scalar; 34 | public: 35 | NoAlias(ExpressionType& expression) : m_expression(expression) {} 36 | 37 | /** Behaves like MatrixBase::lazyAssign(other) 38 | * \sa MatrixBase::lazyAssign() */ 39 | template 40 | EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase& other) 41 | { return internal::assign_selector::run(m_expression,other.derived()); } 42 | 43 | /** \sa MatrixBase::operator+= */ 44 | template 45 | EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase& other) 46 | { 47 | typedef SelfCwiseBinaryOp, ExpressionType, OtherDerived> SelfAdder; 48 | SelfAdder tmp(m_expression); 49 | typedef typename internal::nested::type OtherDerivedNested; 50 | typedef typename internal::remove_all::type _OtherDerivedNested; 51 | internal::assign_selector::run(tmp,OtherDerivedNested(other.derived())); 52 | return m_expression; 53 | } 54 | 55 | /** \sa MatrixBase::operator-= */ 56 | template 57 | EIGEN_STRONG_INLINE ExpressionType& operator-=(const StorageBase& other) 58 | { 59 | typedef SelfCwiseBinaryOp, ExpressionType, OtherDerived> SelfAdder; 60 | SelfAdder tmp(m_expression); 61 | typedef typename internal::nested::type OtherDerivedNested; 62 | typedef typename internal::remove_all::type _OtherDerivedNested; 63 | internal::assign_selector::run(tmp,OtherDerivedNested(other.derived())); 64 | return m_expression; 65 | } 66 | 67 | #ifndef EIGEN_PARSED_BY_DOXYGEN 68 | template 69 | EIGEN_STRONG_INLINE ExpressionType& operator+=(const ProductBase& other) 70 | { other.derived().addTo(m_expression); return m_expression; } 71 | 72 | template 73 | EIGEN_STRONG_INLINE ExpressionType& operator-=(const ProductBase& other) 74 | { other.derived().subTo(m_expression); return m_expression; } 75 | 76 | template 77 | EIGEN_STRONG_INLINE ExpressionType& operator+=(const CoeffBasedProduct& other) 78 | { return m_expression.derived() += CoeffBasedProduct(other.lhs(), other.rhs()); } 79 | 80 | template 81 | EIGEN_STRONG_INLINE ExpressionType& operator-=(const CoeffBasedProduct& other) 82 | { return m_expression.derived() -= CoeffBasedProduct(other.lhs(), other.rhs()); } 83 | 84 | template 85 | ExpressionType& operator=(const ReturnByValue& func) 86 | { return m_expression = func; } 87 | #endif 88 | 89 | ExpressionType& expression() const 90 | { 91 | return m_expression; 92 | } 93 | 94 | protected: 95 | ExpressionType& m_expression; 96 | }; 97 | 98 | /** \returns a pseudo expression of \c *this with an operator= assuming 99 | * no aliasing between \c *this and the source expression. 100 | * 101 | * More precisely, noalias() allows to bypass the EvalBeforeAssignBit flag. 102 | * Currently, even though several expressions may alias, only product 103 | * expressions have this flag. Therefore, noalias() is only usefull when 104 | * the source expression contains a matrix product. 105 | * 106 | * Here are some examples where noalias is usefull: 107 | * \code 108 | * D.noalias() = A * B; 109 | * D.noalias() += A.transpose() * B; 110 | * D.noalias() -= 2 * A * B.adjoint(); 111 | * \endcode 112 | * 113 | * On the other hand the following example will lead to a \b wrong result: 114 | * \code 115 | * A.noalias() = A * B; 116 | * \endcode 117 | * because the result matrix A is also an operand of the matrix product. Therefore, 118 | * there is no alternative than evaluating A * B in a temporary, that is the default 119 | * behavior when you write: 120 | * \code 121 | * A = A * B; 122 | * \endcode 123 | * 124 | * \sa class NoAlias 125 | */ 126 | template 127 | NoAlias MatrixBase::noalias() 128 | { 129 | return derived(); 130 | } 131 | 132 | } // end namespace Eigen 133 | 134 | #endif // EIGEN_NOALIAS_H -------------------------------------------------------------------------------- /eigen/src/Core/Random.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_RANDOM_H 11 | #define EIGEN_RANDOM_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | template struct scalar_random_op { 18 | EIGEN_EMPTY_STRUCT_CTOR(scalar_random_op) 19 | template 20 | inline const Scalar operator() (Index, Index = 0) const { return random(); } 21 | }; 22 | 23 | template 24 | struct functor_traits > 25 | { enum { Cost = 5 * NumTraits::MulCost, PacketAccess = false, IsRepeatable = false }; }; 26 | 27 | } // end namespace internal 28 | 29 | /** \returns a random matrix expression 30 | * 31 | * The parameters \a rows and \a cols are the number of rows and of columns of 32 | * the returned matrix. Must be compatible with this MatrixBase type. 33 | * 34 | * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, 35 | * it is redundant to pass \a rows and \a cols as arguments, so Random() should be used 36 | * instead. 37 | * 38 | * Example: \include MatrixBase_random_int_int.cpp 39 | * Output: \verbinclude MatrixBase_random_int_int.out 40 | * 41 | * This expression has the "evaluate before nesting" flag so that it will be evaluated into 42 | * a temporary matrix whenever it is nested in a larger expression. This prevents unexpected 43 | * behavior with expressions involving random matrices. 44 | * 45 | * \sa MatrixBase::setRandom(), MatrixBase::Random(Index), MatrixBase::Random() 46 | */ 47 | template 48 | inline const CwiseNullaryOp::Scalar>, Derived> 49 | DenseBase::Random(Index rows, Index cols) 50 | { 51 | return NullaryExpr(rows, cols, internal::scalar_random_op()); 52 | } 53 | 54 | /** \returns a random vector expression 55 | * 56 | * The parameter \a size is the size of the returned vector. 57 | * Must be compatible with this MatrixBase type. 58 | * 59 | * \only_for_vectors 60 | * 61 | * This variant is meant to be used for dynamic-size vector types. For fixed-size types, 62 | * it is redundant to pass \a size as argument, so Random() should be used 63 | * instead. 64 | * 65 | * Example: \include MatrixBase_random_int.cpp 66 | * Output: \verbinclude MatrixBase_random_int.out 67 | * 68 | * This expression has the "evaluate before nesting" flag so that it will be evaluated into 69 | * a temporary vector whenever it is nested in a larger expression. This prevents unexpected 70 | * behavior with expressions involving random matrices. 71 | * 72 | * \sa MatrixBase::setRandom(), MatrixBase::Random(Index,Index), MatrixBase::Random() 73 | */ 74 | template 75 | inline const CwiseNullaryOp::Scalar>, Derived> 76 | DenseBase::Random(Index size) 77 | { 78 | return NullaryExpr(size, internal::scalar_random_op()); 79 | } 80 | 81 | /** \returns a fixed-size random matrix or vector expression 82 | * 83 | * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you 84 | * need to use the variants taking size arguments. 85 | * 86 | * Example: \include MatrixBase_random.cpp 87 | * Output: \verbinclude MatrixBase_random.out 88 | * 89 | * This expression has the "evaluate before nesting" flag so that it will be evaluated into 90 | * a temporary matrix whenever it is nested in a larger expression. This prevents unexpected 91 | * behavior with expressions involving random matrices. 92 | * 93 | * \sa MatrixBase::setRandom(), MatrixBase::Random(Index,Index), MatrixBase::Random(Index) 94 | */ 95 | template 96 | inline const CwiseNullaryOp::Scalar>, Derived> 97 | DenseBase::Random() 98 | { 99 | return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op()); 100 | } 101 | 102 | /** Sets all coefficients in this expression to random values. 103 | * 104 | * Example: \include MatrixBase_setRandom.cpp 105 | * Output: \verbinclude MatrixBase_setRandom.out 106 | * 107 | * \sa class CwiseNullaryOp, setRandom(Index), setRandom(Index,Index) 108 | */ 109 | template 110 | inline Derived& DenseBase::setRandom() 111 | { 112 | return *this = Random(rows(), cols()); 113 | } 114 | 115 | /** Resizes to the given \a newSize, and sets all coefficients in this expression to random values. 116 | * 117 | * \only_for_vectors 118 | * 119 | * Example: \include Matrix_setRandom_int.cpp 120 | * Output: \verbinclude Matrix_setRandom_int.out 121 | * 122 | * \sa MatrixBase::setRandom(), setRandom(Index,Index), class CwiseNullaryOp, MatrixBase::Random() 123 | */ 124 | template 125 | EIGEN_STRONG_INLINE Derived& 126 | PlainObjectBase::setRandom(Index newSize) 127 | { 128 | resize(newSize); 129 | return setRandom(); 130 | } 131 | 132 | /** Resizes to the given size, and sets all coefficients in this expression to random values. 133 | * 134 | * \param nbRows the new number of rows 135 | * \param nbCols the new number of columns 136 | * 137 | * Example: \include Matrix_setRandom_int_int.cpp 138 | * Output: \verbinclude Matrix_setRandom_int_int.out 139 | * 140 | * \sa MatrixBase::setRandom(), setRandom(Index), class CwiseNullaryOp, MatrixBase::Random() 141 | */ 142 | template 143 | EIGEN_STRONG_INLINE Derived& 144 | PlainObjectBase::setRandom(Index nbRows, Index nbCols) 145 | { 146 | resize(nbRows, nbCols); 147 | return setRandom(); 148 | } 149 | 150 | } // end namespace Eigen 151 | 152 | #endif // EIGEN_RANDOM_H -------------------------------------------------------------------------------- /eigen/src/Core/ReturnByValue.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009-2010 Gael Guennebaud 5 | // Copyright (C) 2009-2010 Benoit Jacob 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_RETURNBYVALUE_H 12 | #define EIGEN_RETURNBYVALUE_H 13 | 14 | namespace Eigen { 15 | 16 | /** \class ReturnByValue 17 | * \ingroup Core_Module 18 | * 19 | */ 20 | 21 | namespace internal { 22 | 23 | template 24 | struct traits > 25 | : public traits::ReturnType> 26 | { 27 | enum { 28 | // We're disabling the DirectAccess because e.g. the constructor of 29 | // the Block-with-DirectAccess expression requires to have a coeffRef method. 30 | // Also, we don't want to have to implement the stride stuff. 31 | Flags = (traits::ReturnType>::Flags 32 | | EvalBeforeNestingBit) & ~DirectAccessBit 33 | }; 34 | }; 35 | 36 | /* The ReturnByValue object doesn't even have a coeff() method. 37 | * So the only way that nesting it in an expression can work, is by evaluating it into a plain matrix. 38 | * So internal::nested always gives the plain return matrix type. 39 | * 40 | * FIXME: I don't understand why we need this specialization: isn't this taken care of by the EvalBeforeNestingBit ?? 41 | */ 42 | template 43 | struct nested, n, PlainObject> 44 | { 45 | typedef typename traits::ReturnType type; 46 | }; 47 | 48 | } // end namespace internal 49 | 50 | template class ReturnByValue 51 | : internal::no_assignment_operator, public internal::dense_xpr_base< ReturnByValue >::type 52 | { 53 | public: 54 | typedef typename internal::traits::ReturnType ReturnType; 55 | 56 | typedef typename internal::dense_xpr_base::type Base; 57 | EIGEN_DENSE_PUBLIC_INTERFACE(ReturnByValue) 58 | 59 | template 60 | inline void evalTo(Dest& dst) const 61 | { static_cast(this)->evalTo(dst); } 62 | inline Index rows() const { return static_cast(this)->rows(); } 63 | inline Index cols() const { return static_cast(this)->cols(); } 64 | 65 | #ifndef EIGEN_PARSED_BY_DOXYGEN 66 | #define Unusable YOU_ARE_TRYING_TO_ACCESS_A_SINGLE_COEFFICIENT_IN_A_SPECIAL_EXPRESSION_WHERE_THAT_IS_NOT_ALLOWED_BECAUSE_THAT_WOULD_BE_INEFFICIENT 67 | class Unusable{ 68 | Unusable(const Unusable&) {} 69 | Unusable& operator=(const Unusable&) {return *this;} 70 | }; 71 | const Unusable& coeff(Index) const { return *reinterpret_cast(this); } 72 | const Unusable& coeff(Index,Index) const { return *reinterpret_cast(this); } 73 | Unusable& coeffRef(Index) { return *reinterpret_cast(this); } 74 | Unusable& coeffRef(Index,Index) { return *reinterpret_cast(this); } 75 | template Unusable& packet(Index) const; 76 | template Unusable& packet(Index, Index) const; 77 | #endif 78 | }; 79 | 80 | template 81 | template 82 | Derived& DenseBase::operator=(const ReturnByValue& other) 83 | { 84 | other.evalTo(derived()); 85 | return derived(); 86 | } 87 | 88 | template 89 | template 90 | Derived& DenseBase::lazyAssign(const ReturnByValue& other) 91 | { 92 | other.evalTo(derived()); 93 | return derived(); 94 | } 95 | 96 | 97 | } // end namespace Eigen 98 | 99 | #endif // EIGEN_RETURNBYVALUE_H -------------------------------------------------------------------------------- /eigen/src/Core/Stride.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2010 Benoit Jacob 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_STRIDE_H 11 | #define EIGEN_STRIDE_H 12 | 13 | namespace Eigen { 14 | 15 | /** \class Stride 16 | * \ingroup Core_Module 17 | * 18 | * \brief Holds strides information for Map 19 | * 20 | * This class holds the strides information for mapping arrays with strides with class Map. 21 | * 22 | * It holds two values: the inner stride and the outer stride. 23 | * 24 | * The inner stride is the pointer increment between two consecutive entries within a given row of a 25 | * row-major matrix or within a given column of a column-major matrix. 26 | * 27 | * The outer stride is the pointer increment between two consecutive rows of a row-major matrix or 28 | * between two consecutive columns of a column-major matrix. 29 | * 30 | * These two values can be passed either at compile-time as template parameters, or at runtime as 31 | * arguments to the constructor. 32 | * 33 | * Indeed, this class takes two template parameters: 34 | * \param _OuterStrideAtCompileTime the outer stride, or Dynamic if you want to specify it at runtime. 35 | * \param _InnerStrideAtCompileTime the inner stride, or Dynamic if you want to specify it at runtime. 36 | * 37 | * Here is an example: 38 | * \include Map_general_stride.cpp 39 | * Output: \verbinclude Map_general_stride.out 40 | * 41 | * \sa class InnerStride, class OuterStride, \ref TopicStorageOrders 42 | */ 43 | template 44 | class Stride 45 | { 46 | public: 47 | typedef DenseIndex Index; 48 | enum { 49 | InnerStrideAtCompileTime = _InnerStrideAtCompileTime, 50 | OuterStrideAtCompileTime = _OuterStrideAtCompileTime 51 | }; 52 | 53 | /** Default constructor, for use when strides are fixed at compile time */ 54 | Stride() 55 | : m_outer(OuterStrideAtCompileTime), m_inner(InnerStrideAtCompileTime) 56 | { 57 | eigen_assert(InnerStrideAtCompileTime != Dynamic && OuterStrideAtCompileTime != Dynamic); 58 | } 59 | 60 | /** Constructor allowing to pass the strides at runtime */ 61 | Stride(Index outerStride, Index innerStride) 62 | : m_outer(outerStride), m_inner(innerStride) 63 | { 64 | eigen_assert(innerStride>=0 && outerStride>=0); 65 | } 66 | 67 | /** Copy constructor */ 68 | Stride(const Stride& other) 69 | : m_outer(other.outer()), m_inner(other.inner()) 70 | {} 71 | 72 | /** \returns the outer stride */ 73 | inline Index outer() const { return m_outer.value(); } 74 | /** \returns the inner stride */ 75 | inline Index inner() const { return m_inner.value(); } 76 | 77 | protected: 78 | internal::variable_if_dynamic m_outer; 79 | internal::variable_if_dynamic m_inner; 80 | }; 81 | 82 | /** \brief Convenience specialization of Stride to specify only an inner stride 83 | * See class Map for some examples */ 84 | template 85 | class InnerStride : public Stride<0, Value> 86 | { 87 | typedef Stride<0, Value> Base; 88 | public: 89 | typedef DenseIndex Index; 90 | InnerStride() : Base() {} 91 | InnerStride(Index v) : Base(0, v) {} 92 | }; 93 | 94 | /** \brief Convenience specialization of Stride to specify only an outer stride 95 | * See class Map for some examples */ 96 | template 97 | class OuterStride : public Stride 98 | { 99 | typedef Stride Base; 100 | public: 101 | typedef DenseIndex Index; 102 | OuterStride() : Base() {} 103 | OuterStride(Index v) : Base(v,0) {} 104 | }; 105 | 106 | } // end namespace Eigen 107 | 108 | #endif // EIGEN_STRIDE_H -------------------------------------------------------------------------------- /eigen/src/Core/Swap.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2006-2008 Benoit Jacob 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_SWAP_H 11 | #define EIGEN_SWAP_H 12 | 13 | namespace Eigen { 14 | 15 | /** \class SwapWrapper 16 | * \ingroup Core_Module 17 | * 18 | * \internal 19 | * 20 | * \brief Internal helper class for swapping two expressions 21 | */ 22 | namespace internal { 23 | template 24 | struct traits > : traits {}; 25 | } 26 | 27 | template class SwapWrapper 28 | : public internal::dense_xpr_base >::type 29 | { 30 | public: 31 | 32 | typedef typename internal::dense_xpr_base::type Base; 33 | EIGEN_DENSE_PUBLIC_INTERFACE(SwapWrapper) 34 | typedef typename internal::packet_traits::type Packet; 35 | 36 | inline SwapWrapper(ExpressionType& xpr) : m_expression(xpr) {} 37 | 38 | inline Index rows() const { return m_expression.rows(); } 39 | inline Index cols() const { return m_expression.cols(); } 40 | inline Index outerStride() const { return m_expression.outerStride(); } 41 | inline Index innerStride() const { return m_expression.innerStride(); } 42 | 43 | typedef typename internal::conditional< 44 | internal::is_lvalue::value, 45 | Scalar, 46 | const Scalar 47 | >::type ScalarWithConstIfNotLvalue; 48 | 49 | inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } 50 | inline const Scalar* data() const { return m_expression.data(); } 51 | 52 | inline Scalar& coeffRef(Index rowId, Index colId) 53 | { 54 | return m_expression.const_cast_derived().coeffRef(rowId, colId); 55 | } 56 | 57 | inline Scalar& coeffRef(Index index) 58 | { 59 | return m_expression.const_cast_derived().coeffRef(index); 60 | } 61 | 62 | inline Scalar& coeffRef(Index rowId, Index colId) const 63 | { 64 | return m_expression.coeffRef(rowId, colId); 65 | } 66 | 67 | inline Scalar& coeffRef(Index index) const 68 | { 69 | return m_expression.coeffRef(index); 70 | } 71 | 72 | template 73 | void copyCoeff(Index rowId, Index colId, const DenseBase& other) 74 | { 75 | OtherDerived& _other = other.const_cast_derived(); 76 | eigen_internal_assert(rowId >= 0 && rowId < rows() 77 | && colId >= 0 && colId < cols()); 78 | Scalar tmp = m_expression.coeff(rowId, colId); 79 | m_expression.coeffRef(rowId, colId) = _other.coeff(rowId, colId); 80 | _other.coeffRef(rowId, colId) = tmp; 81 | } 82 | 83 | template 84 | void copyCoeff(Index index, const DenseBase& other) 85 | { 86 | OtherDerived& _other = other.const_cast_derived(); 87 | eigen_internal_assert(index >= 0 && index < m_expression.size()); 88 | Scalar tmp = m_expression.coeff(index); 89 | m_expression.coeffRef(index) = _other.coeff(index); 90 | _other.coeffRef(index) = tmp; 91 | } 92 | 93 | template 94 | void copyPacket(Index rowId, Index colId, const DenseBase& other) 95 | { 96 | OtherDerived& _other = other.const_cast_derived(); 97 | eigen_internal_assert(rowId >= 0 && rowId < rows() 98 | && colId >= 0 && colId < cols()); 99 | Packet tmp = m_expression.template packet(rowId, colId); 100 | m_expression.template writePacket(rowId, colId, 101 | _other.template packet(rowId, colId) 102 | ); 103 | _other.template writePacket(rowId, colId, tmp); 104 | } 105 | 106 | template 107 | void copyPacket(Index index, const DenseBase& other) 108 | { 109 | OtherDerived& _other = other.const_cast_derived(); 110 | eigen_internal_assert(index >= 0 && index < m_expression.size()); 111 | Packet tmp = m_expression.template packet(index); 112 | m_expression.template writePacket(index, 113 | _other.template packet(index) 114 | ); 115 | _other.template writePacket(index, tmp); 116 | } 117 | 118 | ExpressionType& expression() const { return m_expression; } 119 | 120 | protected: 121 | ExpressionType& m_expression; 122 | }; 123 | 124 | } // end namespace Eigen 125 | 126 | #endif // EIGEN_SWAP_H -------------------------------------------------------------------------------- /eigen/src/Core/VectorBlock.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2010 Gael Guennebaud 5 | // Copyright (C) 2006-2008 Benoit Jacob 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_VECTORBLOCK_H 12 | #define EIGEN_VECTORBLOCK_H 13 | 14 | namespace Eigen { 15 | 16 | /** \class VectorBlock 17 | * \ingroup Core_Module 18 | * 19 | * \brief Expression of a fixed-size or dynamic-size sub-vector 20 | * 21 | * \param VectorType the type of the object in which we are taking a sub-vector 22 | * \param Size size of the sub-vector we are taking at compile time (optional) 23 | * 24 | * This class represents an expression of either a fixed-size or dynamic-size sub-vector. 25 | * It is the return type of DenseBase::segment(Index,Index) and DenseBase::segment(Index) and 26 | * most of the time this is the only way it is used. 27 | * 28 | * However, if you want to directly maniputate sub-vector expressions, 29 | * for instance if you want to write a function returning such an expression, you 30 | * will need to use this class. 31 | * 32 | * Here is an example illustrating the dynamic case: 33 | * \include class_VectorBlock.cpp 34 | * Output: \verbinclude class_VectorBlock.out 35 | * 36 | * \note Even though this expression has dynamic size, in the case where \a VectorType 37 | * has fixed size, this expression inherits a fixed maximal size which means that evaluating 38 | * it does not cause a dynamic memory allocation. 39 | * 40 | * Here is an example illustrating the fixed-size case: 41 | * \include class_FixedVectorBlock.cpp 42 | * Output: \verbinclude class_FixedVectorBlock.out 43 | * 44 | * \sa class Block, DenseBase::segment(Index,Index,Index,Index), DenseBase::segment(Index,Index) 45 | */ 46 | 47 | namespace internal { 48 | template 49 | struct traits > 50 | : public traits::Flags & RowMajorBit ? 1 : Size, 52 | traits::Flags & RowMajorBit ? Size : 1> > 53 | { 54 | }; 55 | } 56 | 57 | template class VectorBlock 58 | : public Block::Flags & RowMajorBit ? 1 : Size, 60 | internal::traits::Flags & RowMajorBit ? Size : 1> 61 | { 62 | typedef Block::Flags & RowMajorBit ? 1 : Size, 64 | internal::traits::Flags & RowMajorBit ? Size : 1> Base; 65 | enum { 66 | IsColVector = !(internal::traits::Flags & RowMajorBit) 67 | }; 68 | public: 69 | EIGEN_DENSE_PUBLIC_INTERFACE(VectorBlock) 70 | 71 | using Base::operator=; 72 | 73 | /** Dynamic-size constructor 74 | */ 75 | inline VectorBlock(VectorType& vector, Index start, Index size) 76 | : Base(vector, 77 | IsColVector ? start : 0, IsColVector ? 0 : start, 78 | IsColVector ? size : 1, IsColVector ? 1 : size) 79 | { 80 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorBlock); 81 | } 82 | 83 | /** Fixed-size constructor 84 | */ 85 | inline VectorBlock(VectorType& vector, Index start) 86 | : Base(vector, IsColVector ? start : 0, IsColVector ? 0 : start) 87 | { 88 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorBlock); 89 | } 90 | }; 91 | 92 | 93 | } // end namespace Eigen 94 | 95 | #endif // EIGEN_VECTORBLOCK_H -------------------------------------------------------------------------------- /eigen/src/Core/arch/Default/Settings.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2010 Gael Guennebaud 5 | // Copyright (C) 2006-2008 Benoit Jacob 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 | 12 | /* All the parameters defined in this file can be specialized in the 13 | * architecture specific files, and/or by the user. 14 | * More to come... */ 15 | 16 | #ifndef EIGEN_DEFAULT_SETTINGS_H 17 | #define EIGEN_DEFAULT_SETTINGS_H 18 | 19 | /** Defines the maximal loop size to enable meta unrolling of loops. 20 | * Note that the value here is expressed in Eigen's own notion of "number of FLOPS", 21 | * it does not correspond to the number of iterations or the number of instructions 22 | */ 23 | #ifndef EIGEN_UNROLLING_LIMIT 24 | #define EIGEN_UNROLLING_LIMIT 100 25 | #endif 26 | 27 | /** Defines the threshold between a "small" and a "large" matrix. 28 | * This threshold is mainly used to select the proper product implementation. 29 | */ 30 | #ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 31 | #define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8 32 | #endif 33 | 34 | /** Defines the maximal width of the blocks used in the triangular product and solver 35 | * for vectors (level 2 blas xTRMV and xTRSV). The default is 8. 36 | */ 37 | #ifndef EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH 38 | #define EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH 8 39 | #endif 40 | 41 | 42 | /** Defines the default number of registers available for that architecture. 43 | * Currently it must be 8 or 16. Other values will fail. 44 | */ 45 | #ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 46 | #define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 8 47 | #endif 48 | 49 | #endif // EIGEN_DEFAULT_SETTINGS_H -------------------------------------------------------------------------------- /eigen/src/Core/products/GeneralMatrixMatrix_MKL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to Intel(R) MKL 29 | * General matrix-matrix product functionality based on ?GEMM. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_GENERAL_MATRIX_MATRIX_MKL_H 34 | #define EIGEN_GENERAL_MATRIX_MATRIX_MKL_H 35 | 36 | namespace Eigen { 37 | 38 | namespace internal { 39 | 40 | /********************************************************************** 41 | * This file implements general matrix-matrix multiplication using BLAS 42 | * gemm function via partial specialization of 43 | * general_matrix_matrix_product::run(..) method for float, double, 44 | * std::complex and std::complex types 45 | **********************************************************************/ 46 | 47 | // gemm specialization 48 | 49 | #define GEMM_SPECIALIZATION(EIGTYPE, EIGPREFIX, MKLTYPE, MKLPREFIX) \ 50 | template< \ 51 | typename Index, \ 52 | int LhsStorageOrder, bool ConjugateLhs, \ 53 | int RhsStorageOrder, bool ConjugateRhs> \ 54 | struct general_matrix_matrix_product \ 55 | { \ 56 | static void run(Index rows, Index cols, Index depth, \ 57 | const EIGTYPE* _lhs, Index lhsStride, \ 58 | const EIGTYPE* _rhs, Index rhsStride, \ 59 | EIGTYPE* res, Index resStride, \ 60 | EIGTYPE alpha, \ 61 | level3_blocking& /*blocking*/, \ 62 | GemmParallelInfo* /*info = 0*/) \ 63 | { \ 64 | using std::conj; \ 65 | \ 66 | char transa, transb; \ 67 | MKL_INT m, n, k, lda, ldb, ldc; \ 68 | const EIGTYPE *a, *b; \ 69 | MKLTYPE alpha_, beta_; \ 70 | MatrixX##EIGPREFIX a_tmp, b_tmp; \ 71 | EIGTYPE myone(1);\ 72 | \ 73 | /* Set transpose options */ \ 74 | transa = (LhsStorageOrder==RowMajor) ? ((ConjugateLhs) ? 'C' : 'T') : 'N'; \ 75 | transb = (RhsStorageOrder==RowMajor) ? ((ConjugateRhs) ? 'C' : 'T') : 'N'; \ 76 | \ 77 | /* Set m, n, k */ \ 78 | m = (MKL_INT)rows; \ 79 | n = (MKL_INT)cols; \ 80 | k = (MKL_INT)depth; \ 81 | \ 82 | /* Set alpha_ & beta_ */ \ 83 | assign_scalar_eig2mkl(alpha_, alpha); \ 84 | assign_scalar_eig2mkl(beta_, myone); \ 85 | \ 86 | /* Set lda, ldb, ldc */ \ 87 | lda = (MKL_INT)lhsStride; \ 88 | ldb = (MKL_INT)rhsStride; \ 89 | ldc = (MKL_INT)resStride; \ 90 | \ 91 | /* Set a, b, c */ \ 92 | if ((LhsStorageOrder==ColMajor) && (ConjugateLhs)) { \ 93 | Map > lhs(_lhs,m,k,OuterStride<>(lhsStride)); \ 94 | a_tmp = lhs.conjugate(); \ 95 | a = a_tmp.data(); \ 96 | lda = a_tmp.outerStride(); \ 97 | } else a = _lhs; \ 98 | \ 99 | if ((RhsStorageOrder==ColMajor) && (ConjugateRhs)) { \ 100 | Map > rhs(_rhs,k,n,OuterStride<>(rhsStride)); \ 101 | b_tmp = rhs.conjugate(); \ 102 | b = b_tmp.data(); \ 103 | ldb = b_tmp.outerStride(); \ 104 | } else b = _rhs; \ 105 | \ 106 | MKLPREFIX##gemm(&transa, &transb, &m, &n, &k, &alpha_, (const MKLTYPE*)a, &lda, (const MKLTYPE*)b, &ldb, &beta_, (MKLTYPE*)res, &ldc); \ 107 | }}; 108 | 109 | GEMM_SPECIALIZATION(double, d, double, d) 110 | GEMM_SPECIALIZATION(float, f, float, s) 111 | GEMM_SPECIALIZATION(dcomplex, cd, MKL_Complex16, z) 112 | GEMM_SPECIALIZATION(scomplex, cf, MKL_Complex8, c) 113 | 114 | } // end namespase internal 115 | 116 | } // end namespace Eigen 117 | 118 | #endif // EIGEN_GENERAL_MATRIX_MATRIX_MKL_H -------------------------------------------------------------------------------- /eigen/src/Core/products/GeneralMatrixVector_MKL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to Intel(R) MKL 29 | * General matrix-vector product functionality based on ?GEMV. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_GENERAL_MATRIX_VECTOR_MKL_H 34 | #define EIGEN_GENERAL_MATRIX_VECTOR_MKL_H 35 | 36 | namespace Eigen { 37 | 38 | namespace internal { 39 | 40 | /********************************************************************** 41 | * This file implements general matrix-vector multiplication using BLAS 42 | * gemv function via partial specialization of 43 | * general_matrix_vector_product::run(..) method for float, double, 44 | * std::complex and std::complex types 45 | **********************************************************************/ 46 | 47 | // gemv specialization 48 | 49 | template 50 | struct general_matrix_vector_product_gemv : 51 | general_matrix_vector_product {}; 52 | 53 | #define EIGEN_MKL_GEMV_SPECIALIZE(Scalar) \ 54 | template \ 55 | struct general_matrix_vector_product { \ 56 | static void run( \ 57 | Index rows, Index cols, \ 58 | const Scalar* lhs, Index lhsStride, \ 59 | const Scalar* rhs, Index rhsIncr, \ 60 | Scalar* res, Index resIncr, Scalar alpha) \ 61 | { \ 62 | if (ConjugateLhs) { \ 63 | general_matrix_vector_product::run( \ 64 | rows, cols, lhs, lhsStride, rhs, rhsIncr, res, resIncr, alpha); \ 65 | } else { \ 66 | general_matrix_vector_product_gemv::run( \ 67 | rows, cols, lhs, lhsStride, rhs, rhsIncr, res, resIncr, alpha); \ 68 | } \ 69 | } \ 70 | }; \ 71 | template \ 72 | struct general_matrix_vector_product { \ 73 | static void run( \ 74 | Index rows, Index cols, \ 75 | const Scalar* lhs, Index lhsStride, \ 76 | const Scalar* rhs, Index rhsIncr, \ 77 | Scalar* res, Index resIncr, Scalar alpha) \ 78 | { \ 79 | general_matrix_vector_product_gemv::run( \ 80 | rows, cols, lhs, lhsStride, rhs, rhsIncr, res, resIncr, alpha); \ 81 | } \ 82 | }; \ 83 | 84 | EIGEN_MKL_GEMV_SPECIALIZE(double) 85 | EIGEN_MKL_GEMV_SPECIALIZE(float) 86 | EIGEN_MKL_GEMV_SPECIALIZE(dcomplex) 87 | EIGEN_MKL_GEMV_SPECIALIZE(scomplex) 88 | 89 | #define EIGEN_MKL_GEMV_SPECIALIZATION(EIGTYPE,MKLTYPE,MKLPREFIX) \ 90 | template \ 91 | struct general_matrix_vector_product_gemv \ 92 | { \ 93 | typedef Matrix GEMVVector;\ 94 | \ 95 | static void run( \ 96 | Index rows, Index cols, \ 97 | const EIGTYPE* lhs, Index lhsStride, \ 98 | const EIGTYPE* rhs, Index rhsIncr, \ 99 | EIGTYPE* res, Index resIncr, EIGTYPE alpha) \ 100 | { \ 101 | MKL_INT m=rows, n=cols, lda=lhsStride, incx=rhsIncr, incy=resIncr; \ 102 | MKLTYPE alpha_, beta_; \ 103 | const EIGTYPE *x_ptr, myone(1); \ 104 | char trans=(LhsStorageOrder==ColMajor) ? 'N' : (ConjugateLhs) ? 'C' : 'T'; \ 105 | if (LhsStorageOrder==RowMajor) { \ 106 | m=cols; \ 107 | n=rows; \ 108 | }\ 109 | assign_scalar_eig2mkl(alpha_, alpha); \ 110 | assign_scalar_eig2mkl(beta_, myone); \ 111 | GEMVVector x_tmp; \ 112 | if (ConjugateRhs) { \ 113 | Map > map_x(rhs,cols,1,InnerStride<>(incx)); \ 114 | x_tmp=map_x.conjugate(); \ 115 | x_ptr=x_tmp.data(); \ 116 | incx=1; \ 117 | } else x_ptr=rhs; \ 118 | MKLPREFIX##gemv(&trans, &m, &n, &alpha_, (const MKLTYPE*)lhs, &lda, (const MKLTYPE*)x_ptr, &incx, &beta_, (MKLTYPE*)res, &incy); \ 119 | }\ 120 | }; 121 | 122 | EIGEN_MKL_GEMV_SPECIALIZATION(double, double, d) 123 | EIGEN_MKL_GEMV_SPECIALIZATION(float, float, s) 124 | EIGEN_MKL_GEMV_SPECIALIZATION(dcomplex, MKL_Complex16, z) 125 | EIGEN_MKL_GEMV_SPECIALIZATION(scomplex, MKL_Complex8, c) 126 | 127 | } // end namespase internal 128 | 129 | } // end namespace Eigen 130 | 131 | #endif // EIGEN_GENERAL_MATRIX_VECTOR_MKL_H -------------------------------------------------------------------------------- /eigen/src/Core/products/Parallelizer.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2010 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_PARALLELIZER_H 11 | #define EIGEN_PARALLELIZER_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | /** \internal */ 18 | inline void manage_multi_threading(Action action, int* v) 19 | { 20 | static EIGEN_UNUSED int m_maxThreads = -1; 21 | 22 | if(action==SetAction) 23 | { 24 | eigen_internal_assert(v!=0); 25 | m_maxThreads = *v; 26 | } 27 | else if(action==GetAction) 28 | { 29 | eigen_internal_assert(v!=0); 30 | #ifdef EIGEN_HAS_OPENMP 31 | if(m_maxThreads>0) 32 | *v = m_maxThreads; 33 | else 34 | *v = omp_get_max_threads(); 35 | #else 36 | *v = 1; 37 | #endif 38 | } 39 | else 40 | { 41 | eigen_internal_assert(false); 42 | } 43 | } 44 | 45 | } 46 | 47 | /** Must be call first when calling Eigen from multiple threads */ 48 | inline void initParallel() 49 | { 50 | int nbt; 51 | internal::manage_multi_threading(GetAction, &nbt); 52 | std::ptrdiff_t l1, l2; 53 | internal::manage_caching_sizes(GetAction, &l1, &l2); 54 | } 55 | 56 | /** \returns the max number of threads reserved for Eigen 57 | * \sa setNbThreads */ 58 | inline int nbThreads() 59 | { 60 | int ret; 61 | internal::manage_multi_threading(GetAction, &ret); 62 | return ret; 63 | } 64 | 65 | /** Sets the max number of threads reserved for Eigen 66 | * \sa nbThreads */ 67 | inline void setNbThreads(int v) 68 | { 69 | internal::manage_multi_threading(SetAction, &v); 70 | } 71 | 72 | namespace internal { 73 | 74 | template struct GemmParallelInfo 75 | { 76 | GemmParallelInfo() : sync(-1), users(0), rhs_start(0), rhs_length(0) {} 77 | 78 | int volatile sync; 79 | int volatile users; 80 | 81 | Index rhs_start; 82 | Index rhs_length; 83 | }; 84 | 85 | template 86 | void parallelize_gemm(const Functor& func, Index rows, Index cols, bool transpose) 87 | { 88 | // TODO when EIGEN_USE_BLAS is defined, 89 | // we should still enable OMP for other scalar types 90 | #if !(defined (EIGEN_HAS_OPENMP)) || defined (EIGEN_USE_BLAS) 91 | // FIXME the transpose variable is only needed to properly split 92 | // the matrix product when multithreading is enabled. This is a temporary 93 | // fix to support row-major destination matrices. This whole 94 | // parallelizer mechanism has to be redisigned anyway. 95 | EIGEN_UNUSED_VARIABLE(transpose); 96 | func(0,rows, 0,cols); 97 | #else 98 | 99 | // Dynamically check whether we should enable or disable OpenMP. 100 | // The conditions are: 101 | // - the max number of threads we can create is greater than 1 102 | // - we are not already in a parallel code 103 | // - the sizes are large enough 104 | 105 | // 1- are we already in a parallel session? 106 | // FIXME omp_get_num_threads()>1 only works for openmp, what if the user does not use openmp? 107 | if((!Condition) || (omp_get_num_threads()>1)) 108 | return func(0,rows, 0,cols); 109 | 110 | Index size = transpose ? cols : rows; 111 | 112 | // 2- compute the maximal number of threads from the size of the product: 113 | // FIXME this has to be fine tuned 114 | Index max_threads = std::max(1,size / 32); 115 | 116 | // 3 - compute the number of threads we are going to use 117 | Index threads = std::min(nbThreads(), max_threads); 118 | 119 | if(threads==1) 120 | return func(0,rows, 0,cols); 121 | 122 | Eigen::initParallel(); 123 | func.initParallelSession(); 124 | 125 | if(transpose) 126 | std::swap(rows,cols); 127 | 128 | GemmParallelInfo* info = new GemmParallelInfo[threads]; 129 | 130 | #pragma omp parallel num_threads(threads) 131 | { 132 | Index i = omp_get_thread_num(); 133 | // Note that the actual number of threads might be lower than the number of request ones. 134 | Index actual_threads = omp_get_num_threads(); 135 | 136 | Index blockCols = (cols / actual_threads) & ~Index(0x3); 137 | Index blockRows = (rows / actual_threads) & ~Index(0x7); 138 | 139 | Index r0 = i*blockRows; 140 | Index actualBlockRows = (i+1==actual_threads) ? rows-r0 : blockRows; 141 | 142 | Index c0 = i*blockCols; 143 | Index actualBlockCols = (i+1==actual_threads) ? cols-c0 : blockCols; 144 | 145 | info[i].rhs_start = c0; 146 | info[i].rhs_length = actualBlockCols; 147 | 148 | if(transpose) 149 | func(0, cols, r0, actualBlockRows, info); 150 | else 151 | func(r0, actualBlockRows, 0,cols, info); 152 | } 153 | 154 | delete[] info; 155 | #endif 156 | } 157 | 158 | } // end namespace internal 159 | 160 | } // end namespace Eigen 161 | 162 | #endif // EIGEN_PARALLELIZER_H -------------------------------------------------------------------------------- /eigen/src/Core/products/SelfadjointMatrixVector_MKL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to Intel(R) MKL 29 | * Selfadjoint matrix-vector product functionality based on ?SYMV/HEMV. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_SELFADJOINT_MATRIX_VECTOR_MKL_H 34 | #define EIGEN_SELFADJOINT_MATRIX_VECTOR_MKL_H 35 | 36 | namespace Eigen { 37 | 38 | namespace internal { 39 | 40 | /********************************************************************** 41 | * This file implements selfadjoint matrix-vector multiplication using BLAS 42 | **********************************************************************/ 43 | 44 | // symv/hemv specialization 45 | 46 | template 47 | struct selfadjoint_matrix_vector_product_symv : 48 | selfadjoint_matrix_vector_product {}; 49 | 50 | #define EIGEN_MKL_SYMV_SPECIALIZE(Scalar) \ 51 | template \ 52 | struct selfadjoint_matrix_vector_product { \ 53 | static void run( \ 54 | Index size, const Scalar* lhs, Index lhsStride, \ 55 | const Scalar* _rhs, Index rhsIncr, Scalar* res, Scalar alpha) { \ 56 | enum {\ 57 | IsColMajor = StorageOrder==ColMajor \ 58 | }; \ 59 | if (IsColMajor == ConjugateLhs) {\ 60 | selfadjoint_matrix_vector_product::run( \ 61 | size, lhs, lhsStride, _rhs, rhsIncr, res, alpha); \ 62 | } else {\ 63 | selfadjoint_matrix_vector_product_symv::run( \ 64 | size, lhs, lhsStride, _rhs, rhsIncr, res, alpha); \ 65 | }\ 66 | } \ 67 | }; \ 68 | 69 | EIGEN_MKL_SYMV_SPECIALIZE(double) 70 | EIGEN_MKL_SYMV_SPECIALIZE(float) 71 | EIGEN_MKL_SYMV_SPECIALIZE(dcomplex) 72 | EIGEN_MKL_SYMV_SPECIALIZE(scomplex) 73 | 74 | #define EIGEN_MKL_SYMV_SPECIALIZATION(EIGTYPE,MKLTYPE,MKLFUNC) \ 75 | template \ 76 | struct selfadjoint_matrix_vector_product_symv \ 77 | { \ 78 | typedef Matrix SYMVVector;\ 79 | \ 80 | static void run( \ 81 | Index size, const EIGTYPE* lhs, Index lhsStride, \ 82 | const EIGTYPE* _rhs, Index rhsIncr, EIGTYPE* res, EIGTYPE alpha) \ 83 | { \ 84 | enum {\ 85 | IsRowMajor = StorageOrder==RowMajor ? 1 : 0, \ 86 | IsLower = UpLo == Lower ? 1 : 0 \ 87 | }; \ 88 | MKL_INT n=size, lda=lhsStride, incx=rhsIncr, incy=1; \ 89 | MKLTYPE alpha_, beta_; \ 90 | const EIGTYPE *x_ptr, myone(1); \ 91 | char uplo=(IsRowMajor) ? (IsLower ? 'U' : 'L') : (IsLower ? 'L' : 'U'); \ 92 | assign_scalar_eig2mkl(alpha_, alpha); \ 93 | assign_scalar_eig2mkl(beta_, myone); \ 94 | SYMVVector x_tmp; \ 95 | if (ConjugateRhs) { \ 96 | Map > map_x(_rhs,size,1,InnerStride<>(incx)); \ 97 | x_tmp=map_x.conjugate(); \ 98 | x_ptr=x_tmp.data(); \ 99 | incx=1; \ 100 | } else x_ptr=_rhs; \ 101 | MKLFUNC(&uplo, &n, &alpha_, (const MKLTYPE*)lhs, &lda, (const MKLTYPE*)x_ptr, &incx, &beta_, (MKLTYPE*)res, &incy); \ 102 | }\ 103 | }; 104 | 105 | EIGEN_MKL_SYMV_SPECIALIZATION(double, double, dsymv) 106 | EIGEN_MKL_SYMV_SPECIALIZATION(float, float, ssymv) 107 | EIGEN_MKL_SYMV_SPECIALIZATION(dcomplex, MKL_Complex16, zhemv) 108 | EIGEN_MKL_SYMV_SPECIALIZATION(scomplex, MKL_Complex8, chemv) 109 | 110 | } // end namespace internal 111 | 112 | } // end namespace Eigen 113 | 114 | #endif // EIGEN_SELFADJOINT_MATRIX_VECTOR_MKL_H -------------------------------------------------------------------------------- /eigen/src/Core/products/SelfadjointRank2Update.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_SELFADJOINTRANK2UPTADE_H 11 | #define EIGEN_SELFADJOINTRANK2UPTADE_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | /* Optimized selfadjoint matrix += alpha * uv' + conj(alpha)*vu' 18 | * It corresponds to the Level2 syr2 BLAS routine 19 | */ 20 | 21 | template 22 | struct selfadjoint_rank2_update_selector; 23 | 24 | template 25 | struct selfadjoint_rank2_update_selector 26 | { 27 | static void run(Scalar* mat, Index stride, const UType& u, const VType& v, const Scalar& alpha) 28 | { 29 | const Index size = u.size(); 30 | for (Index i=0; i >(mat+stride*i+i, size-i) += 33 | (numext::conj(alpha) * numext::conj(u.coeff(i))) * v.tail(size-i) 34 | + (alpha * numext::conj(v.coeff(i))) * u.tail(size-i); 35 | } 36 | } 37 | }; 38 | 39 | template 40 | struct selfadjoint_rank2_update_selector 41 | { 42 | static void run(Scalar* mat, Index stride, const UType& u, const VType& v, const Scalar& alpha) 43 | { 44 | const Index size = u.size(); 45 | for (Index i=0; i >(mat+stride*i, i+1) += 47 | (numext::conj(alpha) * numext::conj(u.coeff(i))) * v.head(i+1) 48 | + (alpha * numext::conj(v.coeff(i))) * u.head(i+1); 49 | } 50 | }; 51 | 52 | template struct conj_expr_if 53 | : conditional::Scalar>,T> > {}; 55 | 56 | } // end namespace internal 57 | 58 | template 59 | template 60 | SelfAdjointView& SelfAdjointView 61 | ::rankUpdate(const MatrixBase& u, const MatrixBase& v, const Scalar& alpha) 62 | { 63 | typedef internal::blas_traits UBlasTraits; 64 | typedef typename UBlasTraits::DirectLinearAccessType ActualUType; 65 | typedef typename internal::remove_all::type _ActualUType; 66 | typename internal::add_const_on_value_type::type actualU = UBlasTraits::extract(u.derived()); 67 | 68 | typedef internal::blas_traits VBlasTraits; 69 | typedef typename VBlasTraits::DirectLinearAccessType ActualVType; 70 | typedef typename internal::remove_all::type _ActualVType; 71 | typename internal::add_const_on_value_type::type actualV = VBlasTraits::extract(v.derived()); 72 | 73 | // If MatrixType is row major, then we use the routine for lower triangular in the upper triangular case and 74 | // vice versa, and take the complex conjugate of all coefficients and vector entries. 75 | 76 | enum { IsRowMajor = (internal::traits::Flags&RowMajorBit) ? 1 : 0 }; 77 | Scalar actualAlpha = alpha * UBlasTraits::extractScalarFactor(u.derived()) 78 | * numext::conj(VBlasTraits::extractScalarFactor(v.derived())); 79 | if (IsRowMajor) 80 | actualAlpha = numext::conj(actualAlpha); 81 | 82 | internal::selfadjoint_rank2_update_selector::type>::type, 84 | typename internal::remove_all::type>::type, 85 | (IsRowMajor ? int(UpLo==Upper ? Lower : Upper) : UpLo)> 86 | ::run(_expression().const_cast_derived().data(),_expression().outerStride(),actualU,actualV,actualAlpha); 87 | 88 | return *this; 89 | } 90 | 91 | } // end namespace Eigen 92 | 93 | #endif // EIGEN_SELFADJOINTRANK2UPTADE_H -------------------------------------------------------------------------------- /eigen/src/Core/products/TriangularSolverVector.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2010 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_TRIANGULAR_SOLVER_VECTOR_H 11 | #define EIGEN_TRIANGULAR_SOLVER_VECTOR_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | template 18 | struct triangular_solve_vector 19 | { 20 | static void run(Index size, const LhsScalar* _lhs, Index lhsStride, RhsScalar* rhs) 21 | { 22 | triangular_solve_vector::run(size, _lhs, lhsStride, rhs); 26 | } 27 | }; 28 | 29 | // forward and backward substitution, row-major, rhs is a vector 30 | template 31 | struct triangular_solve_vector 32 | { 33 | enum { 34 | IsLower = ((Mode&Lower)==Lower) 35 | }; 36 | static void run(Index size, const LhsScalar* _lhs, Index lhsStride, RhsScalar* rhs) 37 | { 38 | typedef Map, 0, OuterStride<> > LhsMap; 39 | const LhsMap lhs(_lhs,size,size,OuterStride<>(lhsStride)); 40 | typename internal::conditional< 41 | Conjugate, 42 | const CwiseUnaryOp,LhsMap>, 43 | const LhsMap&> 44 | ::type cjLhs(lhs); 45 | static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH; 46 | for(Index pi=IsLower ? 0 : size; 47 | IsLower ? pi0; 48 | IsLower ? pi+=PanelWidth : pi-=PanelWidth) 49 | { 50 | Index actualPanelWidth = (std::min)(IsLower ? size - pi : pi, PanelWidth); 51 | 52 | Index r = IsLower ? pi : size - pi; // remaining size 53 | if (r > 0) 54 | { 55 | // let's directly call the low level product function because: 56 | // 1 - it is faster to compile 57 | // 2 - it is slighlty faster at runtime 58 | Index startRow = IsLower ? pi : pi-actualPanelWidth; 59 | Index startCol = IsLower ? 0 : pi; 60 | 61 | general_matrix_vector_product::run( 62 | actualPanelWidth, r, 63 | &lhs.coeffRef(startRow,startCol), lhsStride, 64 | rhs + startCol, 1, 65 | rhs + startRow, 1, 66 | RhsScalar(-1)); 67 | } 68 | 69 | for(Index k=0; k0) 74 | rhs[i] -= (cjLhs.row(i).segment(s,k).transpose().cwiseProduct(Map >(rhs+s,k))).sum(); 75 | 76 | if(!(Mode & UnitDiag)) 77 | rhs[i] /= cjLhs(i,i); 78 | } 79 | } 80 | } 81 | }; 82 | 83 | // forward and backward substitution, column-major, rhs is a vector 84 | template 85 | struct triangular_solve_vector 86 | { 87 | enum { 88 | IsLower = ((Mode&Lower)==Lower) 89 | }; 90 | static void run(Index size, const LhsScalar* _lhs, Index lhsStride, RhsScalar* rhs) 91 | { 92 | typedef Map, 0, OuterStride<> > LhsMap; 93 | const LhsMap lhs(_lhs,size,size,OuterStride<>(lhsStride)); 94 | typename internal::conditional,LhsMap>, 96 | const LhsMap& 97 | >::type cjLhs(lhs); 98 | static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH; 99 | 100 | for(Index pi=IsLower ? 0 : size; 101 | IsLower ? pi0; 102 | IsLower ? pi+=PanelWidth : pi-=PanelWidth) 103 | { 104 | Index actualPanelWidth = (std::min)(IsLower ? size - pi : pi, PanelWidth); 105 | Index startBlock = IsLower ? pi : pi-actualPanelWidth; 106 | Index endBlock = IsLower ? pi + actualPanelWidth : 0; 107 | 108 | for(Index k=0; k0) 117 | Map >(rhs+s,r) -= rhs[i] * cjLhs.col(i).segment(s,r); 118 | } 119 | Index r = IsLower ? size - endBlock : startBlock; // remaining size 120 | if (r > 0) 121 | { 122 | // let's directly call the low level product function because: 123 | // 1 - it is faster to compile 124 | // 2 - it is slighlty faster at runtime 125 | general_matrix_vector_product::run( 126 | r, actualPanelWidth, 127 | &lhs.coeffRef(endBlock,startBlock), lhsStride, 128 | rhs+startBlock, 1, 129 | rhs+endBlock, 1, RhsScalar(-1)); 130 | } 131 | } 132 | } 133 | }; 134 | 135 | } // end namespace internal 136 | 137 | } // end namespace Eigen 138 | 139 | #endif // EIGEN_TRIANGULAR_SOLVER_VECTOR_H -------------------------------------------------------------------------------- /eigen/src/Core/util/DisableStupidWarnings.h: -------------------------------------------------------------------------------- 1 | #ifndef EIGEN_WARNINGS_DISABLED 2 | #define EIGEN_WARNINGS_DISABLED 3 | 4 | #ifdef _MSC_VER 5 | // 4100 - unreferenced formal parameter (occurred e.g. in aligned_allocator::destroy(pointer p)) 6 | // 4101 - unreferenced local variable 7 | // 4127 - conditional expression is constant 8 | // 4181 - qualifier applied to reference type ignored 9 | // 4211 - nonstandard extension used : redefined extern to static 10 | // 4244 - 'argument' : conversion from 'type1' to 'type2', possible loss of data 11 | // 4273 - QtAlignedMalloc, inconsistent DLL linkage 12 | // 4324 - structure was padded due to declspec(align()) 13 | // 4512 - assignment operator could not be generated 14 | // 4522 - 'class' : multiple assignment operators specified 15 | // 4700 - uninitialized local variable 'xyz' used 16 | // 4717 - 'function' : recursive on all control paths, function will cause runtime stack overflow 17 | #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS 18 | #pragma warning( push ) 19 | #endif 20 | #pragma warning( disable : 4100 4101 4127 4181 4211 4244 4273 4324 4512 4522 4700 4717 ) 21 | #elif defined __INTEL_COMPILER 22 | // 2196 - routine is both "inline" and "noinline" ("noinline" assumed) 23 | // ICC 12 generates this warning even without any inline keyword, when defining class methods 'inline' i.e. inside of class body 24 | // typedef that may be a reference type. 25 | // 279 - controlling expression is constant 26 | // ICC 12 generates this warning on assert(constant_expression_depending_on_template_params) and frankly this is a legitimate use case. 27 | #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS 28 | #pragma warning push 29 | #endif 30 | #pragma warning disable 2196 279 31 | #elif defined __clang__ 32 | // -Wconstant-logical-operand - warning: use of logical && with constant operand; switch to bitwise & or remove constant 33 | // this is really a stupid warning as it warns on compile-time expressions involving enums 34 | #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS 35 | #pragma clang diagnostic push 36 | #endif 37 | #pragma clang diagnostic ignored "-Wconstant-logical-operand" 38 | #endif 39 | 40 | #endif // not EIGEN_WARNINGS_DISABLED -------------------------------------------------------------------------------- /eigen/src/Core/util/MKL_support.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to Intel(R) MKL 29 | * Include file with common MKL declarations 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_MKL_SUPPORT_H 34 | #define EIGEN_MKL_SUPPORT_H 35 | 36 | #ifdef EIGEN_USE_MKL_ALL 37 | #ifndef EIGEN_USE_BLAS 38 | #define EIGEN_USE_BLAS 39 | #endif 40 | #ifndef EIGEN_USE_LAPACKE 41 | #define EIGEN_USE_LAPACKE 42 | #endif 43 | #ifndef EIGEN_USE_MKL_VML 44 | #define EIGEN_USE_MKL_VML 45 | #endif 46 | #endif 47 | 48 | #ifdef EIGEN_USE_LAPACKE_STRICT 49 | #define EIGEN_USE_LAPACKE 50 | #endif 51 | 52 | #if defined(EIGEN_USE_BLAS) || defined(EIGEN_USE_LAPACKE) || defined(EIGEN_USE_MKL_VML) 53 | #define EIGEN_USE_MKL 54 | #endif 55 | 56 | #if defined EIGEN_USE_MKL 57 | # include 58 | /*Check IMKL version for compatibility: < 10.3 is not usable with Eigen*/ 59 | # ifndef INTEL_MKL_VERSION 60 | # undef EIGEN_USE_MKL /* INTEL_MKL_VERSION is not even defined on older versions */ 61 | # elif INTEL_MKL_VERSION < 100305 /* the intel-mkl-103-release-notes say this was when the lapacke.h interface was added*/ 62 | # undef EIGEN_USE_MKL 63 | # endif 64 | # ifndef EIGEN_USE_MKL 65 | /*If the MKL version is too old, undef everything*/ 66 | # undef EIGEN_USE_MKL_ALL 67 | # undef EIGEN_USE_BLAS 68 | # undef EIGEN_USE_LAPACKE 69 | # undef EIGEN_USE_MKL_VML 70 | # undef EIGEN_USE_LAPACKE_STRICT 71 | # undef EIGEN_USE_LAPACKE 72 | # endif 73 | #endif 74 | 75 | #if defined EIGEN_USE_MKL 76 | #include 77 | #define EIGEN_MKL_VML_THRESHOLD 128 78 | 79 | /* MKL_DOMAIN_BLAS, etc are defined only in 10.3 update 7 */ 80 | /* MKL_BLAS, etc are not defined in 11.2 */ 81 | #ifdef MKL_DOMAIN_ALL 82 | #define EIGEN_MKL_DOMAIN_ALL MKL_DOMAIN_ALL 83 | #else 84 | #define EIGEN_MKL_DOMAIN_ALL MKL_ALL 85 | #endif 86 | 87 | #ifdef MKL_DOMAIN_BLAS 88 | #define EIGEN_MKL_DOMAIN_BLAS MKL_DOMAIN_BLAS 89 | #else 90 | #define EIGEN_MKL_DOMAIN_BLAS MKL_BLAS 91 | #endif 92 | 93 | #ifdef MKL_DOMAIN_FFT 94 | #define EIGEN_MKL_DOMAIN_FFT MKL_DOMAIN_FFT 95 | #else 96 | #define EIGEN_MKL_DOMAIN_FFT MKL_FFT 97 | #endif 98 | 99 | #ifdef MKL_DOMAIN_VML 100 | #define EIGEN_MKL_DOMAIN_VML MKL_DOMAIN_VML 101 | #else 102 | #define EIGEN_MKL_DOMAIN_VML MKL_VML 103 | #endif 104 | 105 | #ifdef MKL_DOMAIN_PARDISO 106 | #define EIGEN_MKL_DOMAIN_PARDISO MKL_DOMAIN_PARDISO 107 | #else 108 | #define EIGEN_MKL_DOMAIN_PARDISO MKL_PARDISO 109 | #endif 110 | 111 | namespace Eigen { 112 | 113 | typedef std::complex dcomplex; 114 | typedef std::complex scomplex; 115 | 116 | namespace internal { 117 | 118 | template 119 | static inline void assign_scalar_eig2mkl(MKLType& mklScalar, const EigenType& eigenScalar) { 120 | mklScalar=eigenScalar; 121 | } 122 | 123 | template 124 | static inline void assign_conj_scalar_eig2mkl(MKLType& mklScalar, const EigenType& eigenScalar) { 125 | mklScalar=eigenScalar; 126 | } 127 | 128 | template <> 129 | inline void assign_scalar_eig2mkl(MKL_Complex16& mklScalar, const dcomplex& eigenScalar) { 130 | mklScalar.real=eigenScalar.real(); 131 | mklScalar.imag=eigenScalar.imag(); 132 | } 133 | 134 | template <> 135 | inline void assign_scalar_eig2mkl(MKL_Complex8& mklScalar, const scomplex& eigenScalar) { 136 | mklScalar.real=eigenScalar.real(); 137 | mklScalar.imag=eigenScalar.imag(); 138 | } 139 | 140 | template <> 141 | inline void assign_conj_scalar_eig2mkl(MKL_Complex16& mklScalar, const dcomplex& eigenScalar) { 142 | mklScalar.real=eigenScalar.real(); 143 | mklScalar.imag=-eigenScalar.imag(); 144 | } 145 | 146 | template <> 147 | inline void assign_conj_scalar_eig2mkl(MKL_Complex8& mklScalar, const scomplex& eigenScalar) { 148 | mklScalar.real=eigenScalar.real(); 149 | mklScalar.imag=-eigenScalar.imag(); 150 | } 151 | 152 | } // end namespace internal 153 | 154 | } // end namespace Eigen 155 | 156 | #endif 157 | 158 | #endif // EIGEN_MKL_SUPPORT_H -------------------------------------------------------------------------------- /eigen/src/Core/util/NonMPL2.h: -------------------------------------------------------------------------------- 1 | #ifdef EIGEN_MPL2_ONLY 2 | #error Including non-MPL2 code in EIGEN_MPL2_ONLY mode 3 | #endif -------------------------------------------------------------------------------- /eigen/src/Core/util/ReenableStupidWarnings.h: -------------------------------------------------------------------------------- 1 | #ifdef EIGEN_WARNINGS_DISABLED 2 | #undef EIGEN_WARNINGS_DISABLED 3 | 4 | #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS 5 | #ifdef _MSC_VER 6 | #pragma warning( pop ) 7 | #elif defined __INTEL_COMPILER 8 | #pragma warning pop 9 | #elif defined __clang__ 10 | #pragma clang diagnostic pop 11 | #endif 12 | #endif 13 | 14 | #endif // EIGEN_WARNINGS_DISABLED -------------------------------------------------------------------------------- /eigen/src/Eigenvalues/ComplexSchur_MKL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to Intel(R) MKL 29 | * Complex Schur needed to complex unsymmetrical eigenvalues/eigenvectors. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_COMPLEX_SCHUR_MKL_H 34 | #define EIGEN_COMPLEX_SCHUR_MKL_H 35 | 36 | #include "Eigen/src/Core/util/MKL_support.h" 37 | 38 | namespace Eigen { 39 | 40 | /** \internal Specialization for the data types supported by MKL */ 41 | 42 | #define EIGEN_MKL_SCHUR_COMPLEX(EIGTYPE, MKLTYPE, MKLPREFIX, MKLPREFIX_U, EIGCOLROW, MKLCOLROW) \ 43 | template<> inline \ 44 | ComplexSchur >& \ 45 | ComplexSchur >::compute(const Matrix& matrix, bool computeU) \ 46 | { \ 47 | typedef Matrix MatrixType; \ 48 | typedef MatrixType::RealScalar RealScalar; \ 49 | typedef std::complex ComplexScalar; \ 50 | \ 51 | eigen_assert(matrix.cols() == matrix.rows()); \ 52 | \ 53 | m_matUisUptodate = false; \ 54 | if(matrix.cols() == 1) \ 55 | { \ 56 | m_matT = matrix.cast(); \ 57 | if(computeU) m_matU = ComplexMatrixType::Identity(1,1); \ 58 | m_info = Success; \ 59 | m_isInitialized = true; \ 60 | m_matUisUptodate = computeU; \ 61 | return *this; \ 62 | } \ 63 | lapack_int n = matrix.cols(), sdim, info; \ 64 | lapack_int lda = matrix.outerStride(); \ 65 | lapack_int matrix_order = MKLCOLROW; \ 66 | char jobvs, sort='N'; \ 67 | LAPACK_##MKLPREFIX_U##_SELECT1 select = 0; \ 68 | jobvs = (computeU) ? 'V' : 'N'; \ 69 | m_matU.resize(n, n); \ 70 | lapack_int ldvs = m_matU.outerStride(); \ 71 | m_matT = matrix; \ 72 | Matrix w; \ 73 | w.resize(n, 1);\ 74 | info = LAPACKE_##MKLPREFIX##gees( matrix_order, jobvs, sort, select, n, (MKLTYPE*)m_matT.data(), lda, &sdim, (MKLTYPE*)w.data(), (MKLTYPE*)m_matU.data(), ldvs ); \ 75 | if(info == 0) \ 76 | m_info = Success; \ 77 | else \ 78 | m_info = NoConvergence; \ 79 | \ 80 | m_isInitialized = true; \ 81 | m_matUisUptodate = computeU; \ 82 | return *this; \ 83 | \ 84 | } 85 | 86 | EIGEN_MKL_SCHUR_COMPLEX(dcomplex, MKL_Complex16, z, Z, ColMajor, LAPACK_COL_MAJOR) 87 | EIGEN_MKL_SCHUR_COMPLEX(scomplex, MKL_Complex8, c, C, ColMajor, LAPACK_COL_MAJOR) 88 | EIGEN_MKL_SCHUR_COMPLEX(dcomplex, MKL_Complex16, z, Z, RowMajor, LAPACK_ROW_MAJOR) 89 | EIGEN_MKL_SCHUR_COMPLEX(scomplex, MKL_Complex8, c, C, RowMajor, LAPACK_ROW_MAJOR) 90 | 91 | } // end namespace Eigen 92 | 93 | #endif // EIGEN_COMPLEX_SCHUR_MKL_H -------------------------------------------------------------------------------- /eigen/src/Eigenvalues/RealSchur_MKL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to Intel(R) MKL 29 | * Real Schur needed to real unsymmetrical eigenvalues/eigenvectors. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_REAL_SCHUR_MKL_H 34 | #define EIGEN_REAL_SCHUR_MKL_H 35 | 36 | #include "Eigen/src/Core/util/MKL_support.h" 37 | 38 | namespace Eigen { 39 | 40 | /** \internal Specialization for the data types supported by MKL */ 41 | 42 | #define EIGEN_MKL_SCHUR_REAL(EIGTYPE, MKLTYPE, MKLPREFIX, MKLPREFIX_U, EIGCOLROW, MKLCOLROW) \ 43 | template<> inline \ 44 | RealSchur >& \ 45 | RealSchur >::compute(const Matrix& matrix, bool computeU) \ 46 | { \ 47 | eigen_assert(matrix.cols() == matrix.rows()); \ 48 | \ 49 | lapack_int n = matrix.cols(), sdim, info; \ 50 | lapack_int lda = matrix.outerStride(); \ 51 | lapack_int matrix_order = MKLCOLROW; \ 52 | char jobvs, sort='N'; \ 53 | LAPACK_##MKLPREFIX_U##_SELECT2 select = 0; \ 54 | jobvs = (computeU) ? 'V' : 'N'; \ 55 | m_matU.resize(n, n); \ 56 | lapack_int ldvs = m_matU.outerStride(); \ 57 | m_matT = matrix; \ 58 | Matrix wr, wi; \ 59 | wr.resize(n, 1); wi.resize(n, 1); \ 60 | info = LAPACKE_##MKLPREFIX##gees( matrix_order, jobvs, sort, select, n, (MKLTYPE*)m_matT.data(), lda, &sdim, (MKLTYPE*)wr.data(), (MKLTYPE*)wi.data(), (MKLTYPE*)m_matU.data(), ldvs ); \ 61 | if(info == 0) \ 62 | m_info = Success; \ 63 | else \ 64 | m_info = NoConvergence; \ 65 | \ 66 | m_isInitialized = true; \ 67 | m_matUisUptodate = computeU; \ 68 | return *this; \ 69 | \ 70 | } 71 | 72 | EIGEN_MKL_SCHUR_REAL(double, double, d, D, ColMajor, LAPACK_COL_MAJOR) 73 | EIGEN_MKL_SCHUR_REAL(float, float, s, S, ColMajor, LAPACK_COL_MAJOR) 74 | EIGEN_MKL_SCHUR_REAL(double, double, d, D, RowMajor, LAPACK_ROW_MAJOR) 75 | EIGEN_MKL_SCHUR_REAL(float, float, s, S, RowMajor, LAPACK_ROW_MAJOR) 76 | 77 | } // end namespace Eigen 78 | 79 | #endif // EIGEN_REAL_SCHUR_MKL_H -------------------------------------------------------------------------------- /eigen/src/Eigenvalues/SelfAdjointEigenSolver_MKL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to Intel(R) MKL 29 | * Self-adjoint eigenvalues/eigenvectors. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_SAEIGENSOLVER_MKL_H 34 | #define EIGEN_SAEIGENSOLVER_MKL_H 35 | 36 | #include "Eigen/src/Core/util/MKL_support.h" 37 | 38 | namespace Eigen { 39 | 40 | /** \internal Specialization for the data types supported by MKL */ 41 | 42 | #define EIGEN_MKL_EIG_SELFADJ(EIGTYPE, MKLTYPE, MKLRTYPE, MKLNAME, EIGCOLROW, MKLCOLROW ) \ 43 | template<> inline \ 44 | SelfAdjointEigenSolver >& \ 45 | SelfAdjointEigenSolver >::compute(const Matrix& matrix, int options) \ 46 | { \ 47 | eigen_assert(matrix.cols() == matrix.rows()); \ 48 | eigen_assert((options&~(EigVecMask|GenEigMask))==0 \ 49 | && (options&EigVecMask)!=EigVecMask \ 50 | && "invalid option parameter"); \ 51 | bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors; \ 52 | lapack_int n = matrix.cols(), lda, matrix_order, info; \ 53 | m_eivalues.resize(n,1); \ 54 | m_subdiag.resize(n-1); \ 55 | m_eivec = matrix; \ 56 | \ 57 | if(n==1) \ 58 | { \ 59 | m_eivalues.coeffRef(0,0) = numext::real(matrix.coeff(0,0)); \ 60 | if(computeEigenvectors) m_eivec.setOnes(n,n); \ 61 | m_info = Success; \ 62 | m_isInitialized = true; \ 63 | m_eigenvectorsOk = computeEigenvectors; \ 64 | return *this; \ 65 | } \ 66 | \ 67 | lda = matrix.outerStride(); \ 68 | matrix_order=MKLCOLROW; \ 69 | char jobz, uplo='L'/*, range='A'*/; \ 70 | jobz = computeEigenvectors ? 'V' : 'N'; \ 71 | \ 72 | info = LAPACKE_##MKLNAME( matrix_order, jobz, uplo, n, (MKLTYPE*)m_eivec.data(), lda, (MKLRTYPE*)m_eivalues.data() ); \ 73 | m_info = (info==0) ? Success : NoConvergence; \ 74 | m_isInitialized = true; \ 75 | m_eigenvectorsOk = computeEigenvectors; \ 76 | return *this; \ 77 | } 78 | 79 | 80 | EIGEN_MKL_EIG_SELFADJ(double, double, double, dsyev, ColMajor, LAPACK_COL_MAJOR) 81 | EIGEN_MKL_EIG_SELFADJ(float, float, float, ssyev, ColMajor, LAPACK_COL_MAJOR) 82 | EIGEN_MKL_EIG_SELFADJ(dcomplex, MKL_Complex16, double, zheev, ColMajor, LAPACK_COL_MAJOR) 83 | EIGEN_MKL_EIG_SELFADJ(scomplex, MKL_Complex8, float, cheev, ColMajor, LAPACK_COL_MAJOR) 84 | 85 | EIGEN_MKL_EIG_SELFADJ(double, double, double, dsyev, RowMajor, LAPACK_ROW_MAJOR) 86 | EIGEN_MKL_EIG_SELFADJ(float, float, float, ssyev, RowMajor, LAPACK_ROW_MAJOR) 87 | EIGEN_MKL_EIG_SELFADJ(dcomplex, MKL_Complex16, double, zheev, RowMajor, LAPACK_ROW_MAJOR) 88 | EIGEN_MKL_EIG_SELFADJ(scomplex, MKL_Complex8, float, cheev, RowMajor, LAPACK_ROW_MAJOR) 89 | 90 | } // end namespace Eigen 91 | 92 | #endif // EIGEN_SAEIGENSOLVER_H -------------------------------------------------------------------------------- /eigen/src/Geometry/EulerAngles.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_EULERANGLES_H 11 | #define EIGEN_EULERANGLES_H 12 | 13 | namespace Eigen { 14 | 15 | /** \geometry_module \ingroup Geometry_Module 16 | * 17 | * 18 | * \returns the Euler-angles of the rotation matrix \c *this using the convention defined by the triplet (\a a0,\a a1,\a a2) 19 | * 20 | * Each of the three parameters \a a0,\a a1,\a a2 represents the respective rotation axis as an integer in {0,1,2}. 21 | * For instance, in: 22 | * \code Vector3f ea = mat.eulerAngles(2, 0, 2); \endcode 23 | * "2" represents the z axis and "0" the x axis, etc. The returned angles are such that 24 | * we have the following equality: 25 | * \code 26 | * mat == AngleAxisf(ea[0], Vector3f::UnitZ()) 27 | * * AngleAxisf(ea[1], Vector3f::UnitX()) 28 | * * AngleAxisf(ea[2], Vector3f::UnitZ()); \endcode 29 | * This corresponds to the right-multiply conventions (with right hand side frames). 30 | * 31 | * The returned angles are in the ranges [0:pi]x[-pi:pi]x[-pi:pi]. 32 | * 33 | * \sa class AngleAxis 34 | */ 35 | template 36 | inline Matrix::Scalar,3,1> 37 | MatrixBase::eulerAngles(Index a0, Index a1, Index a2) const 38 | { 39 | using std::atan2; 40 | using std::sin; 41 | using std::cos; 42 | /* Implemented from Graphics Gems IV */ 43 | EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,3,3) 44 | 45 | Matrix res; 46 | typedef Matrix Vector2; 47 | 48 | const Index odd = ((a0+1)%3 == a1) ? 0 : 1; 49 | const Index i = a0; 50 | const Index j = (a0 + 1 + odd)%3; 51 | const Index k = (a0 + 2 - odd)%3; 52 | 53 | if (a0==a2) 54 | { 55 | res[0] = atan2(coeff(j,i), coeff(k,i)); 56 | if((odd && res[0]Scalar(0))) 57 | { 58 | res[0] = (res[0] > Scalar(0)) ? res[0] - Scalar(M_PI) : res[0] + Scalar(M_PI); 59 | Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm(); 60 | res[1] = -atan2(s2, coeff(i,i)); 61 | } 62 | else 63 | { 64 | Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm(); 65 | res[1] = atan2(s2, coeff(i,i)); 66 | } 67 | 68 | // With a=(0,1,0), we have i=0; j=1; k=2, and after computing the first two angles, 69 | // we can compute their respective rotation, and apply its inverse to M. Since the result must 70 | // be a rotation around x, we have: 71 | // 72 | // c2 s1.s2 c1.s2 1 0 0 73 | // 0 c1 -s1 * M = 0 c3 s3 74 | // -s2 s1.c2 c1.c2 0 -s3 c3 75 | // 76 | // Thus: m11.c1 - m21.s1 = c3 & m12.c1 - m22.s1 = s3 77 | 78 | Scalar s1 = sin(res[0]); 79 | Scalar c1 = cos(res[0]); 80 | res[2] = atan2(c1*coeff(j,k)-s1*coeff(k,k), c1*coeff(j,j) - s1 * coeff(k,j)); 81 | } 82 | else 83 | { 84 | res[0] = atan2(coeff(j,k), coeff(k,k)); 85 | Scalar c2 = Vector2(coeff(i,i), coeff(i,j)).norm(); 86 | if((odd && res[0]Scalar(0))) { 87 | res[0] = (res[0] > Scalar(0)) ? res[0] - Scalar(M_PI) : res[0] + Scalar(M_PI); 88 | res[1] = atan2(-coeff(i,k), -c2); 89 | } 90 | else 91 | res[1] = atan2(-coeff(i,k), c2); 92 | Scalar s1 = sin(res[0]); 93 | Scalar c1 = cos(res[0]); 94 | res[2] = atan2(s1*coeff(k,i)-c1*coeff(j,i), c1*coeff(j,j) - s1 * coeff(k,j)); 95 | } 96 | if (!odd) 97 | res = -res; 98 | 99 | return res; 100 | } 101 | 102 | } // end namespace Eigen 103 | 104 | #endif // EIGEN_EULERANGLES_H -------------------------------------------------------------------------------- /eigen/src/Geometry/Rotation2D.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_ROTATION2D_H 11 | #define EIGEN_ROTATION2D_H 12 | 13 | namespace Eigen { 14 | 15 | /** \geometry_module \ingroup Geometry_Module 16 | * 17 | * \class Rotation2D 18 | * 19 | * \brief Represents a rotation/orientation in a 2 dimensional space. 20 | * 21 | * \param _Scalar the scalar type, i.e., the type of the coefficients 22 | * 23 | * This class is equivalent to a single scalar representing a counter clock wise rotation 24 | * as a single angle in radian. It provides some additional features such as the automatic 25 | * conversion from/to a 2x2 rotation matrix. Moreover this class aims to provide a similar 26 | * interface to Quaternion in order to facilitate the writing of generic algorithms 27 | * dealing with rotations. 28 | * 29 | * \sa class Quaternion, class Transform 30 | */ 31 | 32 | namespace internal { 33 | 34 | template struct traits > 35 | { 36 | typedef _Scalar Scalar; 37 | }; 38 | } // end namespace internal 39 | 40 | template 41 | class Rotation2D : public RotationBase,2> 42 | { 43 | typedef RotationBase,2> Base; 44 | 45 | public: 46 | 47 | using Base::operator*; 48 | 49 | enum { Dim = 2 }; 50 | /** the scalar type of the coefficients */ 51 | typedef _Scalar Scalar; 52 | typedef Matrix Vector2; 53 | typedef Matrix Matrix2; 54 | 55 | protected: 56 | 57 | Scalar m_angle; 58 | 59 | public: 60 | 61 | /** Construct a 2D counter clock wise rotation from the angle \a a in radian. */ 62 | inline Rotation2D(const Scalar& a) : m_angle(a) {} 63 | 64 | /** Default constructor wihtout initialization. The represented rotation is undefined. */ 65 | Rotation2D() {} 66 | 67 | /** \returns the rotation angle */ 68 | inline Scalar angle() const { return m_angle; } 69 | 70 | /** \returns a read-write reference to the rotation angle */ 71 | inline Scalar& angle() { return m_angle; } 72 | 73 | /** \returns the inverse rotation */ 74 | inline Rotation2D inverse() const { return -m_angle; } 75 | 76 | /** Concatenates two rotations */ 77 | inline Rotation2D operator*(const Rotation2D& other) const 78 | { return m_angle + other.m_angle; } 79 | 80 | /** Concatenates two rotations */ 81 | inline Rotation2D& operator*=(const Rotation2D& other) 82 | { m_angle += other.m_angle; return *this; } 83 | 84 | /** Applies the rotation to a 2D vector */ 85 | Vector2 operator* (const Vector2& vec) const 86 | { return toRotationMatrix() * vec; } 87 | 88 | template 89 | Rotation2D& fromRotationMatrix(const MatrixBase& m); 90 | Matrix2 toRotationMatrix() const; 91 | 92 | /** \returns the spherical interpolation between \c *this and \a other using 93 | * parameter \a t. It is in fact equivalent to a linear interpolation. 94 | */ 95 | inline Rotation2D slerp(const Scalar& t, const Rotation2D& other) const 96 | { return m_angle * (1-t) + other.angle() * t; } 97 | 98 | /** \returns \c *this with scalar type casted to \a NewScalarType 99 | * 100 | * Note that if \a NewScalarType is equal to the current scalar type of \c *this 101 | * then this function smartly returns a const reference to \c *this. 102 | */ 103 | template 104 | inline typename internal::cast_return_type >::type cast() const 105 | { return typename internal::cast_return_type >::type(*this); } 106 | 107 | /** Copy constructor with scalar type conversion */ 108 | template 109 | inline explicit Rotation2D(const Rotation2D& other) 110 | { 111 | m_angle = Scalar(other.angle()); 112 | } 113 | 114 | static inline Rotation2D Identity() { return Rotation2D(0); } 115 | 116 | /** \returns \c true if \c *this is approximately equal to \a other, within the precision 117 | * determined by \a prec. 118 | * 119 | * \sa MatrixBase::isApprox() */ 120 | bool isApprox(const Rotation2D& other, const typename NumTraits::Real& prec = NumTraits::dummy_precision()) const 121 | { return internal::isApprox(m_angle,other.m_angle, prec); } 122 | }; 123 | 124 | /** \ingroup Geometry_Module 125 | * single precision 2D rotation type */ 126 | typedef Rotation2D Rotation2Df; 127 | /** \ingroup Geometry_Module 128 | * double precision 2D rotation type */ 129 | typedef Rotation2D Rotation2Dd; 130 | 131 | /** Set \c *this from a 2x2 rotation matrix \a mat. 132 | * In other words, this function extract the rotation angle 133 | * from the rotation matrix. 134 | */ 135 | template 136 | template 137 | Rotation2D& Rotation2D::fromRotationMatrix(const MatrixBase& mat) 138 | { 139 | using std::atan2; 140 | EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime==2 && Derived::ColsAtCompileTime==2,YOU_MADE_A_PROGRAMMING_MISTAKE) 141 | m_angle = atan2(mat.coeff(1,0), mat.coeff(0,0)); 142 | return *this; 143 | } 144 | 145 | /** Constructs and \returns an equivalent 2x2 rotation matrix. 146 | */ 147 | template 148 | typename Rotation2D::Matrix2 149 | Rotation2D::toRotationMatrix(void) const 150 | { 151 | using std::sin; 152 | using std::cos; 153 | Scalar sinA = sin(m_angle); 154 | Scalar cosA = cos(m_angle); 155 | return (Matrix2() << cosA, -sinA, sinA, cosA).finished(); 156 | } 157 | 158 | } // end namespace Eigen 159 | 160 | #endif // EIGEN_ROTATION2D_H -------------------------------------------------------------------------------- /eigen/src/Householder/BlockHouseholder.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2010 Vincent Lejeune 5 | // Copyright (C) 2010 Gael Guennebaud 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_BLOCK_HOUSEHOLDER_H 12 | #define EIGEN_BLOCK_HOUSEHOLDER_H 13 | 14 | // This file contains some helper function to deal with block householder reflectors 15 | 16 | namespace Eigen { 17 | 18 | namespace internal { 19 | 20 | /** \internal */ 21 | template 22 | void make_block_householder_triangular_factor(TriangularFactorType& triFactor, const VectorsType& vectors, const CoeffsType& hCoeffs) 23 | { 24 | typedef typename TriangularFactorType::Index Index; 25 | typedef typename VectorsType::Scalar Scalar; 26 | const Index nbVecs = vectors.cols(); 27 | eigen_assert(triFactor.rows() == nbVecs && triFactor.cols() == nbVecs && vectors.rows()>=nbVecs); 28 | 29 | for(Index i = 0; i < nbVecs; i++) 30 | { 31 | Index rs = vectors.rows() - i; 32 | Scalar Vii = vectors(i,i); 33 | vectors.const_cast_derived().coeffRef(i,i) = Scalar(1); 34 | triFactor.col(i).head(i).noalias() = -hCoeffs(i) * vectors.block(i, 0, rs, i).adjoint() 35 | * vectors.col(i).tail(rs); 36 | vectors.const_cast_derived().coeffRef(i, i) = Vii; 37 | // FIXME add .noalias() once the triangular product can work inplace 38 | triFactor.col(i).head(i) = triFactor.block(0,0,i,i).template triangularView() 39 | * triFactor.col(i).head(i); 40 | triFactor(i,i) = hCoeffs(i); 41 | } 42 | } 43 | 44 | /** \internal */ 45 | template 46 | void apply_block_householder_on_the_left(MatrixType& mat, const VectorsType& vectors, const CoeffsType& hCoeffs) 47 | { 48 | typedef typename MatrixType::Index Index; 49 | enum { TFactorSize = MatrixType::ColsAtCompileTime }; 50 | Index nbVecs = vectors.cols(); 51 | Matrix T(nbVecs,nbVecs); 52 | make_block_householder_triangular_factor(T, vectors, hCoeffs); 53 | 54 | const TriangularView& V(vectors); 55 | 56 | // A -= V T V^* A 57 | Matrix tmp = V.adjoint() * mat; 59 | // FIXME add .noalias() once the triangular product can work inplace 60 | tmp = T.template triangularView().adjoint() * tmp; 61 | mat.noalias() -= V * tmp; 62 | } 63 | 64 | } // end namespace internal 65 | 66 | } // end namespace Eigen 67 | 68 | #endif // EIGEN_BLOCK_HOUSEHOLDER_H -------------------------------------------------------------------------------- /eigen/src/Householder/Householder.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2010 Benoit Jacob 5 | // Copyright (C) 2009 Gael Guennebaud 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_HOUSEHOLDER_H 12 | #define EIGEN_HOUSEHOLDER_H 13 | 14 | namespace Eigen { 15 | 16 | namespace internal { 17 | template struct decrement_size 18 | { 19 | enum { 20 | ret = n==Dynamic ? n : n-1 21 | }; 22 | }; 23 | } 24 | 25 | /** Computes the elementary reflector H such that: 26 | * \f$ H *this = [ beta 0 ... 0]^T \f$ 27 | * where the transformation H is: 28 | * \f$ H = I - tau v v^*\f$ 29 | * and the vector v is: 30 | * \f$ v^T = [1 essential^T] \f$ 31 | * 32 | * The essential part of the vector \c v is stored in *this. 33 | * 34 | * On output: 35 | * \param tau the scaling factor of the Householder transformation 36 | * \param beta the result of H * \c *this 37 | * 38 | * \sa MatrixBase::makeHouseholder(), MatrixBase::applyHouseholderOnTheLeft(), 39 | * MatrixBase::applyHouseholderOnTheRight() 40 | */ 41 | template 42 | void MatrixBase::makeHouseholderInPlace(Scalar& tau, RealScalar& beta) 43 | { 44 | VectorBlock::ret> essentialPart(derived(), 1, size()-1); 45 | makeHouseholder(essentialPart, tau, beta); 46 | } 47 | 48 | /** Computes the elementary reflector H such that: 49 | * \f$ H *this = [ beta 0 ... 0]^T \f$ 50 | * where the transformation H is: 51 | * \f$ H = I - tau v v^*\f$ 52 | * and the vector v is: 53 | * \f$ v^T = [1 essential^T] \f$ 54 | * 55 | * On output: 56 | * \param essential the essential part of the vector \c v 57 | * \param tau the scaling factor of the Householder transformation 58 | * \param beta the result of H * \c *this 59 | * 60 | * \sa MatrixBase::makeHouseholderInPlace(), MatrixBase::applyHouseholderOnTheLeft(), 61 | * MatrixBase::applyHouseholderOnTheRight() 62 | */ 63 | template 64 | template 65 | void MatrixBase::makeHouseholder( 66 | EssentialPart& essential, 67 | Scalar& tau, 68 | RealScalar& beta) const 69 | { 70 | using std::sqrt; 71 | using numext::conj; 72 | 73 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart) 74 | VectorBlock tail(derived(), 1, size()-1); 75 | 76 | RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm(); 77 | Scalar c0 = coeff(0); 78 | 79 | if(tailSqNorm == RealScalar(0) && numext::imag(c0)==RealScalar(0)) 80 | { 81 | tau = RealScalar(0); 82 | beta = numext::real(c0); 83 | essential.setZero(); 84 | } 85 | else 86 | { 87 | beta = sqrt(numext::abs2(c0) + tailSqNorm); 88 | if (numext::real(c0)>=RealScalar(0)) 89 | beta = -beta; 90 | essential = tail / (c0 - beta); 91 | tau = conj((beta - c0) / beta); 92 | } 93 | } 94 | 95 | /** Apply the elementary reflector H given by 96 | * \f$ H = I - tau v v^*\f$ 97 | * with 98 | * \f$ v^T = [1 essential^T] \f$ 99 | * from the left to a vector or matrix. 100 | * 101 | * On input: 102 | * \param essential the essential part of the vector \c v 103 | * \param tau the scaling factor of the Householder transformation 104 | * \param workspace a pointer to working space with at least 105 | * this->cols() * essential.size() entries 106 | * 107 | * \sa MatrixBase::makeHouseholder(), MatrixBase::makeHouseholderInPlace(), 108 | * MatrixBase::applyHouseholderOnTheRight() 109 | */ 110 | template 111 | template 112 | void MatrixBase::applyHouseholderOnTheLeft( 113 | const EssentialPart& essential, 114 | const Scalar& tau, 115 | Scalar* workspace) 116 | { 117 | if(rows() == 1) 118 | { 119 | *this *= Scalar(1)-tau; 120 | } 121 | else 122 | { 123 | Map::type> tmp(workspace,cols()); 124 | Block bottom(derived(), 1, 0, rows()-1, cols()); 125 | tmp.noalias() = essential.adjoint() * bottom; 126 | tmp += this->row(0); 127 | this->row(0) -= tau * tmp; 128 | bottom.noalias() -= tau * essential * tmp; 129 | } 130 | } 131 | 132 | /** Apply the elementary reflector H given by 133 | * \f$ H = I - tau v v^*\f$ 134 | * with 135 | * \f$ v^T = [1 essential^T] \f$ 136 | * from the right to a vector or matrix. 137 | * 138 | * On input: 139 | * \param essential the essential part of the vector \c v 140 | * \param tau the scaling factor of the Householder transformation 141 | * \param workspace a pointer to working space with at least 142 | * this->cols() * essential.size() entries 143 | * 144 | * \sa MatrixBase::makeHouseholder(), MatrixBase::makeHouseholderInPlace(), 145 | * MatrixBase::applyHouseholderOnTheLeft() 146 | */ 147 | template 148 | template 149 | void MatrixBase::applyHouseholderOnTheRight( 150 | const EssentialPart& essential, 151 | const Scalar& tau, 152 | Scalar* workspace) 153 | { 154 | if(cols() == 1) 155 | { 156 | *this *= Scalar(1)-tau; 157 | } 158 | else 159 | { 160 | Map::type> tmp(workspace,rows()); 161 | Block right(derived(), 0, 1, rows(), cols()-1); 162 | tmp.noalias() = right * essential.conjugate(); 163 | tmp += this->col(0); 164 | this->col(0) -= tau * tmp; 165 | right.noalias() -= tau * tmp * essential.transpose(); 166 | } 167 | } 168 | 169 | } // end namespace Eigen 170 | 171 | #endif // EIGEN_HOUSEHOLDER_H -------------------------------------------------------------------------------- /eigen/src/LU/Determinant.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008 Benoit Jacob 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_DETERMINANT_H 11 | #define EIGEN_DETERMINANT_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | template 18 | inline const typename Derived::Scalar bruteforce_det3_helper 19 | (const MatrixBase& matrix, int a, int b, int c) 20 | { 21 | return matrix.coeff(0,a) 22 | * (matrix.coeff(1,b) * matrix.coeff(2,c) - matrix.coeff(1,c) * matrix.coeff(2,b)); 23 | } 24 | 25 | template 26 | const typename Derived::Scalar bruteforce_det4_helper 27 | (const MatrixBase& matrix, int j, int k, int m, int n) 28 | { 29 | return (matrix.coeff(j,0) * matrix.coeff(k,1) - matrix.coeff(k,0) * matrix.coeff(j,1)) 30 | * (matrix.coeff(m,2) * matrix.coeff(n,3) - matrix.coeff(n,2) * matrix.coeff(m,3)); 31 | } 32 | 33 | template struct determinant_impl 36 | { 37 | static inline typename traits::Scalar run(const Derived& m) 38 | { 39 | if(Derived::ColsAtCompileTime==Dynamic && m.rows()==0) 40 | return typename traits::Scalar(1); 41 | return m.partialPivLu().determinant(); 42 | } 43 | }; 44 | 45 | template struct determinant_impl 46 | { 47 | static inline typename traits::Scalar run(const Derived& m) 48 | { 49 | return m.coeff(0,0); 50 | } 51 | }; 52 | 53 | template struct determinant_impl 54 | { 55 | static inline typename traits::Scalar run(const Derived& m) 56 | { 57 | return m.coeff(0,0) * m.coeff(1,1) - m.coeff(1,0) * m.coeff(0,1); 58 | } 59 | }; 60 | 61 | template struct determinant_impl 62 | { 63 | static inline typename traits::Scalar run(const Derived& m) 64 | { 65 | return bruteforce_det3_helper(m,0,1,2) 66 | - bruteforce_det3_helper(m,1,0,2) 67 | + bruteforce_det3_helper(m,2,0,1); 68 | } 69 | }; 70 | 71 | template struct determinant_impl 72 | { 73 | static typename traits::Scalar run(const Derived& m) 74 | { 75 | // trick by Martin Costabel to compute 4x4 det with only 30 muls 76 | return bruteforce_det4_helper(m,0,1,2,3) 77 | - bruteforce_det4_helper(m,0,2,1,3) 78 | + bruteforce_det4_helper(m,0,3,1,2) 79 | + bruteforce_det4_helper(m,1,2,0,3) 80 | - bruteforce_det4_helper(m,1,3,0,2) 81 | + bruteforce_det4_helper(m,2,3,0,1); 82 | } 83 | }; 84 | 85 | } // end namespace internal 86 | 87 | /** \lu_module 88 | * 89 | * \returns the determinant of this matrix 90 | */ 91 | template 92 | inline typename internal::traits::Scalar MatrixBase::determinant() const 93 | { 94 | eigen_assert(rows() == cols()); 95 | typedef typename internal::nested::type Nested; 96 | return internal::determinant_impl::type>::run(derived()); 97 | } 98 | 99 | } // end namespace Eigen 100 | 101 | #endif // EIGEN_DETERMINANT_H -------------------------------------------------------------------------------- /eigen/src/LU/PartialPivLU_MKL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to Intel(R) MKL 29 | * LU decomposition with partial pivoting based on LAPACKE_?getrf function. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_PARTIALLU_LAPACK_H 34 | #define EIGEN_PARTIALLU_LAPACK_H 35 | 36 | #include "Eigen/src/Core/util/MKL_support.h" 37 | 38 | namespace Eigen { 39 | 40 | namespace internal { 41 | 42 | /** \internal Specialization for the data types supported by MKL */ 43 | 44 | #define EIGEN_MKL_LU_PARTPIV(EIGTYPE, MKLTYPE, MKLPREFIX) \ 45 | template \ 46 | struct partial_lu_impl \ 47 | { \ 48 | /* \internal performs the LU decomposition in-place of the matrix represented */ \ 49 | static lapack_int blocked_lu(lapack_int rows, lapack_int cols, EIGTYPE* lu_data, lapack_int luStride, lapack_int* row_transpositions, lapack_int& nb_transpositions, lapack_int maxBlockSize=256) \ 50 | { \ 51 | EIGEN_UNUSED_VARIABLE(maxBlockSize);\ 52 | lapack_int matrix_order, first_zero_pivot; \ 53 | lapack_int m, n, lda, *ipiv, info; \ 54 | EIGTYPE* a; \ 55 | /* Set up parameters for ?getrf */ \ 56 | matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \ 57 | lda = luStride; \ 58 | a = lu_data; \ 59 | ipiv = row_transpositions; \ 60 | m = rows; \ 61 | n = cols; \ 62 | nb_transpositions = 0; \ 63 | \ 64 | info = LAPACKE_##MKLPREFIX##getrf( matrix_order, m, n, (MKLTYPE*)a, lda, ipiv ); \ 65 | \ 66 | for(int i=0;i= 0); \ 69 | /* something should be done with nb_transpositions */ \ 70 | \ 71 | first_zero_pivot = info; \ 72 | return first_zero_pivot; \ 73 | } \ 74 | }; 75 | 76 | EIGEN_MKL_LU_PARTPIV(double, double, d) 77 | EIGEN_MKL_LU_PARTPIV(float, float, s) 78 | EIGEN_MKL_LU_PARTPIV(dcomplex, MKL_Complex16, z) 79 | EIGEN_MKL_LU_PARTPIV(scomplex, MKL_Complex8, c) 80 | 81 | } // end namespace internal 82 | 83 | } // end namespace Eigen 84 | 85 | #endif // EIGEN_PARTIALLU_LAPACK_H -------------------------------------------------------------------------------- /eigen/src/QR/ColPivHouseholderQR_MKL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to Intel(R) MKL 29 | * Householder QR decomposition of a matrix with column pivoting based on 30 | * LAPACKE_?geqp3 function. 31 | ******************************************************************************** 32 | */ 33 | 34 | #ifndef EIGEN_COLPIVOTINGHOUSEHOLDERQR_MKL_H 35 | #define EIGEN_COLPIVOTINGHOUSEHOLDERQR_MKL_H 36 | 37 | #include "Eigen/src/Core/util/MKL_support.h" 38 | 39 | namespace Eigen { 40 | 41 | /** \internal Specialization for the data types supported by MKL */ 42 | 43 | #define EIGEN_MKL_QR_COLPIV(EIGTYPE, MKLTYPE, MKLPREFIX, EIGCOLROW, MKLCOLROW) \ 44 | template<> inline \ 45 | ColPivHouseholderQR >& \ 46 | ColPivHouseholderQR >::compute( \ 47 | const Matrix& matrix) \ 48 | \ 49 | { \ 50 | using std::abs; \ 51 | typedef Matrix MatrixType; \ 52 | typedef MatrixType::RealScalar RealScalar; \ 53 | Index rows = matrix.rows();\ 54 | Index cols = matrix.cols();\ 55 | Index size = matrix.diagonalSize();\ 56 | \ 57 | m_qr = matrix;\ 58 | m_hCoeffs.resize(size);\ 59 | \ 60 | m_colsTranspositions.resize(cols);\ 61 | /*Index number_of_transpositions = 0;*/ \ 62 | \ 63 | m_nonzero_pivots = 0; \ 64 | m_maxpivot = RealScalar(0);\ 65 | m_colsPermutation.resize(cols); \ 66 | m_colsPermutation.indices().setZero(); \ 67 | \ 68 | lapack_int lda = m_qr.outerStride(), i; \ 69 | lapack_int matrix_order = MKLCOLROW; \ 70 | LAPACKE_##MKLPREFIX##geqp3( matrix_order, rows, cols, (MKLTYPE*)m_qr.data(), lda, (lapack_int*)m_colsPermutation.indices().data(), (MKLTYPE*)m_hCoeffs.data()); \ 71 | m_isInitialized = true; \ 72 | m_maxpivot=m_qr.diagonal().cwiseAbs().maxCoeff(); \ 73 | m_hCoeffs.adjointInPlace(); \ 74 | RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold(); \ 75 | lapack_int *perm = m_colsPermutation.indices().data(); \ 76 | for(i=0;i premultiplied_threshold);\ 78 | } \ 79 | for(i=0;i \ 47 | struct householder_qr_inplace_blocked \ 48 | { \ 49 | static void run(MatrixQR& mat, HCoeffs& hCoeffs, \ 50 | typename MatrixQR::Index = 32, \ 51 | typename MatrixQR::Scalar* = 0) \ 52 | { \ 53 | lapack_int m = (lapack_int) mat.rows(); \ 54 | lapack_int n = (lapack_int) mat.cols(); \ 55 | lapack_int lda = (lapack_int) mat.outerStride(); \ 56 | lapack_int matrix_order = (MatrixQR::IsRowMajor) ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \ 57 | LAPACKE_##MKLPREFIX##geqrf( matrix_order, m, n, (MKLTYPE*)mat.data(), lda, (MKLTYPE*)hCoeffs.data()); \ 58 | hCoeffs.adjointInPlace(); \ 59 | } \ 60 | }; 61 | 62 | EIGEN_MKL_QR_NOPIV(double, double, d) 63 | EIGEN_MKL_QR_NOPIV(float, float, s) 64 | EIGEN_MKL_QR_NOPIV(dcomplex, MKL_Complex16, z) 65 | EIGEN_MKL_QR_NOPIV(scomplex, MKL_Complex8, c) 66 | 67 | } // end namespace internal 68 | 69 | } // end namespace Eigen 70 | 71 | #endif // EIGEN_QR_MKL_H -------------------------------------------------------------------------------- /eigen/src/SVD/JacobiSVD_MKL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to Intel(R) MKL 29 | * Singular Value Decomposition - SVD. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_JACOBISVD_MKL_H 34 | #define EIGEN_JACOBISVD_MKL_H 35 | 36 | #include "Eigen/src/Core/util/MKL_support.h" 37 | 38 | namespace Eigen { 39 | 40 | /** \internal Specialization for the data types supported by MKL */ 41 | 42 | #define EIGEN_MKL_SVD(EIGTYPE, MKLTYPE, MKLRTYPE, MKLPREFIX, EIGCOLROW, MKLCOLROW) \ 43 | template<> inline \ 44 | JacobiSVD, ColPivHouseholderQRPreconditioner>& \ 45 | JacobiSVD, ColPivHouseholderQRPreconditioner>::compute(const Matrix& matrix, unsigned int computationOptions) \ 46 | { \ 47 | typedef Matrix MatrixType; \ 48 | /*typedef MatrixType::Scalar Scalar;*/ \ 49 | /*typedef MatrixType::RealScalar RealScalar;*/ \ 50 | allocate(matrix.rows(), matrix.cols(), computationOptions); \ 51 | \ 52 | /*const RealScalar precision = RealScalar(2) * NumTraits::epsilon();*/ \ 53 | m_nonzeroSingularValues = m_diagSize; \ 54 | \ 55 | lapack_int lda = matrix.outerStride(), ldu, ldvt; \ 56 | lapack_int matrix_order = MKLCOLROW; \ 57 | char jobu, jobvt; \ 58 | MKLTYPE *u, *vt, dummy; \ 59 | jobu = (m_computeFullU) ? 'A' : (m_computeThinU) ? 'S' : 'N'; \ 60 | jobvt = (m_computeFullV) ? 'A' : (m_computeThinV) ? 'S' : 'N'; \ 61 | if (computeU()) { \ 62 | ldu = m_matrixU.outerStride(); \ 63 | u = (MKLTYPE*)m_matrixU.data(); \ 64 | } else { ldu=1; u=&dummy; }\ 65 | MatrixType localV; \ 66 | ldvt = (m_computeFullV) ? m_cols : (m_computeThinV) ? m_diagSize : 1; \ 67 | if (computeV()) { \ 68 | localV.resize(ldvt, m_cols); \ 69 | vt = (MKLTYPE*)localV.data(); \ 70 | } else { ldvt=1; vt=&dummy; }\ 71 | Matrix superb; superb.resize(m_diagSize, 1); \ 72 | MatrixType m_temp; m_temp = matrix; \ 73 | LAPACKE_##MKLPREFIX##gesvd( matrix_order, jobu, jobvt, m_rows, m_cols, (MKLTYPE*)m_temp.data(), lda, (MKLRTYPE*)m_singularValues.data(), u, ldu, vt, ldvt, superb.data()); \ 74 | if (computeV()) m_matrixV = localV.adjoint(); \ 75 | /* for(int i=0;i 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_MISC_IMAGE_H 11 | #define EIGEN_MISC_IMAGE_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | /** \class image_retval_base 18 | * 19 | */ 20 | template 21 | struct traits > 22 | { 23 | typedef typename DecompositionType::MatrixType MatrixType; 24 | typedef Matrix< 25 | typename MatrixType::Scalar, 26 | MatrixType::RowsAtCompileTime, // the image is a subspace of the destination space, whose 27 | // dimension is the number of rows of the original matrix 28 | Dynamic, // we don't know at compile time the dimension of the image (the rank) 29 | MatrixType::Options, 30 | MatrixType::MaxRowsAtCompileTime, // the image matrix will consist of columns from the original matrix, 31 | MatrixType::MaxColsAtCompileTime // so it has the same number of rows and at most as many columns. 32 | > ReturnType; 33 | }; 34 | 35 | template struct image_retval_base 36 | : public ReturnByValue > 37 | { 38 | typedef _DecompositionType DecompositionType; 39 | typedef typename DecompositionType::MatrixType MatrixType; 40 | typedef ReturnByValue Base; 41 | typedef typename Base::Index Index; 42 | 43 | image_retval_base(const DecompositionType& dec, const MatrixType& originalMatrix) 44 | : m_dec(dec), m_rank(dec.rank()), 45 | m_cols(m_rank == 0 ? 1 : m_rank), 46 | m_originalMatrix(originalMatrix) 47 | {} 48 | 49 | inline Index rows() const { return m_dec.rows(); } 50 | inline Index cols() const { return m_cols; } 51 | inline Index rank() const { return m_rank; } 52 | inline const DecompositionType& dec() const { return m_dec; } 53 | inline const MatrixType& originalMatrix() const { return m_originalMatrix; } 54 | 55 | template inline void evalTo(Dest& dst) const 56 | { 57 | static_cast*>(this)->evalTo(dst); 58 | } 59 | 60 | protected: 61 | const DecompositionType& m_dec; 62 | Index m_rank, m_cols; 63 | const MatrixType& m_originalMatrix; 64 | }; 65 | 66 | } // end namespace internal 67 | 68 | #define EIGEN_MAKE_IMAGE_HELPERS(DecompositionType) \ 69 | typedef typename DecompositionType::MatrixType MatrixType; \ 70 | typedef typename MatrixType::Scalar Scalar; \ 71 | typedef typename MatrixType::RealScalar RealScalar; \ 72 | typedef typename MatrixType::Index Index; \ 73 | typedef Eigen::internal::image_retval_base Base; \ 74 | using Base::dec; \ 75 | using Base::originalMatrix; \ 76 | using Base::rank; \ 77 | using Base::rows; \ 78 | using Base::cols; \ 79 | image_retval(const DecompositionType& dec, const MatrixType& originalMatrix) \ 80 | : Base(dec, originalMatrix) {} 81 | 82 | } // end namespace Eigen 83 | 84 | #endif // EIGEN_MISC_IMAGE_H -------------------------------------------------------------------------------- /eigen/src/misc/Kernel.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009 Benoit Jacob 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_MISC_KERNEL_H 11 | #define EIGEN_MISC_KERNEL_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | /** \class kernel_retval_base 18 | * 19 | */ 20 | template 21 | struct traits > 22 | { 23 | typedef typename DecompositionType::MatrixType MatrixType; 24 | typedef Matrix< 25 | typename MatrixType::Scalar, 26 | MatrixType::ColsAtCompileTime, // the number of rows in the "kernel matrix" 27 | // is the number of cols of the original matrix 28 | // so that the product "matrix * kernel = zero" makes sense 29 | Dynamic, // we don't know at compile-time the dimension of the kernel 30 | MatrixType::Options, 31 | MatrixType::MaxColsAtCompileTime, // see explanation for 2nd template parameter 32 | MatrixType::MaxColsAtCompileTime // the kernel is a subspace of the domain space, 33 | // whose dimension is the number of columns of the original matrix 34 | > ReturnType; 35 | }; 36 | 37 | template struct kernel_retval_base 38 | : public ReturnByValue > 39 | { 40 | typedef _DecompositionType DecompositionType; 41 | typedef ReturnByValue Base; 42 | typedef typename Base::Index Index; 43 | 44 | kernel_retval_base(const DecompositionType& dec) 45 | : m_dec(dec), 46 | m_rank(dec.rank()), 47 | m_cols(m_rank==dec.cols() ? 1 : dec.cols() - m_rank) 48 | {} 49 | 50 | inline Index rows() const { return m_dec.cols(); } 51 | inline Index cols() const { return m_cols; } 52 | inline Index rank() const { return m_rank; } 53 | inline const DecompositionType& dec() const { return m_dec; } 54 | 55 | template inline void evalTo(Dest& dst) const 56 | { 57 | static_cast*>(this)->evalTo(dst); 58 | } 59 | 60 | protected: 61 | const DecompositionType& m_dec; 62 | Index m_rank, m_cols; 63 | }; 64 | 65 | } // end namespace internal 66 | 67 | #define EIGEN_MAKE_KERNEL_HELPERS(DecompositionType) \ 68 | typedef typename DecompositionType::MatrixType MatrixType; \ 69 | typedef typename MatrixType::Scalar Scalar; \ 70 | typedef typename MatrixType::RealScalar RealScalar; \ 71 | typedef typename MatrixType::Index Index; \ 72 | typedef Eigen::internal::kernel_retval_base Base; \ 73 | using Base::dec; \ 74 | using Base::rank; \ 75 | using Base::rows; \ 76 | using Base::cols; \ 77 | kernel_retval(const DecompositionType& dec) : Base(dec) {} 78 | 79 | } // end namespace Eigen 80 | 81 | #endif // EIGEN_MISC_KERNEL_H -------------------------------------------------------------------------------- /eigen/src/misc/Solve.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009 Benoit Jacob 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_MISC_SOLVE_H 11 | #define EIGEN_MISC_SOLVE_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | /** \class solve_retval_base 18 | * 19 | */ 20 | template 21 | struct traits > 22 | { 23 | typedef typename DecompositionType::MatrixType MatrixType; 24 | typedef Matrix ReturnType; 30 | }; 31 | 32 | template struct solve_retval_base 33 | : public ReturnByValue > 34 | { 35 | typedef typename remove_all::type RhsNestedCleaned; 36 | typedef _DecompositionType DecompositionType; 37 | typedef ReturnByValue Base; 38 | typedef typename Base::Index Index; 39 | 40 | solve_retval_base(const DecompositionType& dec, const Rhs& rhs) 41 | : m_dec(dec), m_rhs(rhs) 42 | {} 43 | 44 | inline Index rows() const { return m_dec.cols(); } 45 | inline Index cols() const { return m_rhs.cols(); } 46 | inline const DecompositionType& dec() const { return m_dec; } 47 | inline const RhsNestedCleaned& rhs() const { return m_rhs; } 48 | 49 | template inline void evalTo(Dest& dst) const 50 | { 51 | static_cast*>(this)->evalTo(dst); 52 | } 53 | 54 | protected: 55 | const DecompositionType& m_dec; 56 | typename Rhs::Nested m_rhs; 57 | }; 58 | 59 | } // end namespace internal 60 | 61 | #define EIGEN_MAKE_SOLVE_HELPERS(DecompositionType,Rhs) \ 62 | typedef typename DecompositionType::MatrixType MatrixType; \ 63 | typedef typename MatrixType::Scalar Scalar; \ 64 | typedef typename MatrixType::RealScalar RealScalar; \ 65 | typedef typename MatrixType::Index Index; \ 66 | typedef Eigen::internal::solve_retval_base Base; \ 67 | using Base::dec; \ 68 | using Base::rhs; \ 69 | using Base::rows; \ 70 | using Base::cols; \ 71 | solve_retval(const DecompositionType& dec, const Rhs& rhs) \ 72 | : Base(dec, rhs) {} 73 | 74 | } // end namespace Eigen 75 | 76 | #endif // EIGEN_MISC_SOLVE_H -------------------------------------------------------------------------------- /eigen/src/misc/SparseSolve.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2010 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_SPARSE_SOLVE_H 11 | #define EIGEN_SPARSE_SOLVE_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | template struct sparse_solve_retval_base; 18 | template struct sparse_solve_retval; 19 | 20 | template 21 | struct traits > 22 | { 23 | typedef typename DecompositionType::MatrixType MatrixType; 24 | typedef SparseMatrix ReturnType; 25 | }; 26 | 27 | template struct sparse_solve_retval_base 28 | : public ReturnByValue > 29 | { 30 | typedef typename remove_all::type RhsNestedCleaned; 31 | typedef _DecompositionType DecompositionType; 32 | typedef ReturnByValue Base; 33 | typedef typename Base::Index Index; 34 | 35 | sparse_solve_retval_base(const DecompositionType& dec, const Rhs& rhs) 36 | : m_dec(dec), m_rhs(rhs) 37 | {} 38 | 39 | inline Index rows() const { return m_dec.cols(); } 40 | inline Index cols() const { return m_rhs.cols(); } 41 | inline const DecompositionType& dec() const { return m_dec; } 42 | inline const RhsNestedCleaned& rhs() const { return m_rhs; } 43 | 44 | template inline void evalTo(Dest& dst) const 45 | { 46 | static_cast*>(this)->evalTo(dst); 47 | } 48 | 49 | protected: 50 | template 51 | inline void defaultEvalTo(SparseMatrix& dst) const 52 | { 53 | // we process the sparse rhs per block of NbColsAtOnce columns temporarily stored into a dense matrix. 54 | static const int NbColsAtOnce = 4; 55 | int rhsCols = m_rhs.cols(); 56 | int size = m_rhs.rows(); 57 | Eigen::Matrix tmp(size,rhsCols); 58 | Eigen::Matrix tmpX(size,rhsCols); 59 | for(int k=0; k(rhsCols-k, NbColsAtOnce); 62 | tmp.leftCols(actualCols) = m_rhs.middleCols(k,actualCols); 63 | tmpX.leftCols(actualCols) = m_dec.solve(tmp.leftCols(actualCols)); 64 | dst.middleCols(k,actualCols) = tmpX.leftCols(actualCols).sparseView(); 65 | } 66 | } 67 | const DecompositionType& m_dec; 68 | typename Rhs::Nested m_rhs; 69 | }; 70 | 71 | #define EIGEN_MAKE_SPARSE_SOLVE_HELPERS(DecompositionType,Rhs) \ 72 | typedef typename DecompositionType::MatrixType MatrixType; \ 73 | typedef typename MatrixType::Scalar Scalar; \ 74 | typedef typename MatrixType::RealScalar RealScalar; \ 75 | typedef typename MatrixType::Index Index; \ 76 | typedef Eigen::internal::sparse_solve_retval_base Base; \ 77 | using Base::dec; \ 78 | using Base::rhs; \ 79 | using Base::rows; \ 80 | using Base::cols; \ 81 | sparse_solve_retval(const DecompositionType& dec, const Rhs& rhs) \ 82 | : Base(dec, rhs) {} 83 | 84 | 85 | 86 | template struct solve_retval_with_guess; 87 | 88 | template 89 | struct traits > 90 | { 91 | typedef typename DecompositionType::MatrixType MatrixType; 92 | typedef Matrix ReturnType; 98 | }; 99 | 100 | template struct solve_retval_with_guess 101 | : public ReturnByValue > 102 | { 103 | typedef typename DecompositionType::Index Index; 104 | 105 | solve_retval_with_guess(const DecompositionType& dec, const Rhs& rhs, const Guess& guess) 106 | : m_dec(dec), m_rhs(rhs), m_guess(guess) 107 | {} 108 | 109 | inline Index rows() const { return m_dec.cols(); } 110 | inline Index cols() const { return m_rhs.cols(); } 111 | 112 | template inline void evalTo(Dest& dst) const 113 | { 114 | dst = m_guess; 115 | m_dec._solveWithGuess(m_rhs,dst); 116 | } 117 | 118 | protected: 119 | const DecompositionType& m_dec; 120 | const typename Rhs::Nested m_rhs; 121 | const typename Guess::Nested m_guess; 122 | }; 123 | 124 | } // namepsace internal 125 | 126 | } // end namespace Eigen 127 | 128 | #endif // EIGEN_SPARSE_SOLVE_H -------------------------------------------------------------------------------- /eigen/src/plugins/ArrayCwiseUnaryOps.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** \returns an expression of the coefficient-wise absolute value of \c *this 4 | * 5 | * Example: \include Cwise_abs.cpp 6 | * Output: \verbinclude Cwise_abs.out 7 | * 8 | * \sa abs2() 9 | */ 10 | EIGEN_STRONG_INLINE const CwiseUnaryOp, const Derived> 11 | abs() const 12 | { 13 | return derived(); 14 | } 15 | 16 | /** \returns an expression of the coefficient-wise squared absolute value of \c *this 17 | * 18 | * Example: \include Cwise_abs2.cpp 19 | * Output: \verbinclude Cwise_abs2.out 20 | * 21 | * \sa abs(), square() 22 | */ 23 | EIGEN_STRONG_INLINE const CwiseUnaryOp, const Derived> 24 | abs2() const 25 | { 26 | return derived(); 27 | } 28 | 29 | /** \returns an expression of the coefficient-wise exponential of *this. 30 | * 31 | * Example: \include Cwise_exp.cpp 32 | * Output: \verbinclude Cwise_exp.out 33 | * 34 | * \sa pow(), log(), sin(), cos() 35 | */ 36 | inline const CwiseUnaryOp, const Derived> 37 | exp() const 38 | { 39 | return derived(); 40 | } 41 | 42 | /** \returns an expression of the coefficient-wise logarithm of *this. 43 | * 44 | * Example: \include Cwise_log.cpp 45 | * Output: \verbinclude Cwise_log.out 46 | * 47 | * \sa exp() 48 | */ 49 | inline const CwiseUnaryOp, const Derived> 50 | log() const 51 | { 52 | return derived(); 53 | } 54 | 55 | /** \returns an expression of the coefficient-wise square root of *this. 56 | * 57 | * Example: \include Cwise_sqrt.cpp 58 | * Output: \verbinclude Cwise_sqrt.out 59 | * 60 | * \sa pow(), square() 61 | */ 62 | inline const CwiseUnaryOp, const Derived> 63 | sqrt() const 64 | { 65 | return derived(); 66 | } 67 | 68 | /** \returns an expression of the coefficient-wise cosine of *this. 69 | * 70 | * Example: \include Cwise_cos.cpp 71 | * Output: \verbinclude Cwise_cos.out 72 | * 73 | * \sa sin(), acos() 74 | */ 75 | inline const CwiseUnaryOp, const Derived> 76 | cos() const 77 | { 78 | return derived(); 79 | } 80 | 81 | 82 | /** \returns an expression of the coefficient-wise sine of *this. 83 | * 84 | * Example: \include Cwise_sin.cpp 85 | * Output: \verbinclude Cwise_sin.out 86 | * 87 | * \sa cos(), asin() 88 | */ 89 | inline const CwiseUnaryOp, const Derived> 90 | sin() const 91 | { 92 | return derived(); 93 | } 94 | 95 | /** \returns an expression of the coefficient-wise arc cosine of *this. 96 | * 97 | * Example: \include Cwise_acos.cpp 98 | * Output: \verbinclude Cwise_acos.out 99 | * 100 | * \sa cos(), asin() 101 | */ 102 | inline const CwiseUnaryOp, const Derived> 103 | acos() const 104 | { 105 | return derived(); 106 | } 107 | 108 | /** \returns an expression of the coefficient-wise arc sine of *this. 109 | * 110 | * Example: \include Cwise_asin.cpp 111 | * Output: \verbinclude Cwise_asin.out 112 | * 113 | * \sa sin(), acos() 114 | */ 115 | inline const CwiseUnaryOp, const Derived> 116 | asin() const 117 | { 118 | return derived(); 119 | } 120 | 121 | /** \returns an expression of the coefficient-wise tan of *this. 122 | * 123 | * Example: \include Cwise_tan.cpp 124 | * Output: \verbinclude Cwise_tan.out 125 | * 126 | * \sa cos(), sin() 127 | */ 128 | inline const CwiseUnaryOp, Derived> 129 | tan() const 130 | { 131 | return derived(); 132 | } 133 | 134 | 135 | /** \returns an expression of the coefficient-wise power of *this to the given exponent. 136 | * 137 | * Example: \include Cwise_pow.cpp 138 | * Output: \verbinclude Cwise_pow.out 139 | * 140 | * \sa exp(), log() 141 | */ 142 | inline const CwiseUnaryOp, const Derived> 143 | pow(const Scalar& exponent) const 144 | { 145 | return CwiseUnaryOp, const Derived> 146 | (derived(), internal::scalar_pow_op(exponent)); 147 | } 148 | 149 | 150 | /** \returns an expression of the coefficient-wise inverse of *this. 151 | * 152 | * Example: \include Cwise_inverse.cpp 153 | * Output: \verbinclude Cwise_inverse.out 154 | * 155 | * \sa operator/(), operator*() 156 | */ 157 | inline const CwiseUnaryOp, const Derived> 158 | inverse() const 159 | { 160 | return derived(); 161 | } 162 | 163 | /** \returns an expression of the coefficient-wise square of *this. 164 | * 165 | * Example: \include Cwise_square.cpp 166 | * Output: \verbinclude Cwise_square.out 167 | * 168 | * \sa operator/(), operator*(), abs2() 169 | */ 170 | inline const CwiseUnaryOp, const Derived> 171 | square() const 172 | { 173 | return derived(); 174 | } 175 | 176 | /** \returns an expression of the coefficient-wise cube of *this. 177 | * 178 | * Example: \include Cwise_cube.cpp 179 | * Output: \verbinclude Cwise_cube.out 180 | * 181 | * \sa square(), pow() 182 | */ 183 | inline const CwiseUnaryOp, const Derived> 184 | cube() const 185 | { 186 | return derived(); 187 | } -------------------------------------------------------------------------------- /eigen/src/plugins/CommonCwiseBinaryOps.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2009 Gael Guennebaud 5 | // Copyright (C) 2006-2008 Benoit Jacob 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 | // This file is a base class plugin containing common coefficient wise functions. 12 | 13 | /** \returns an expression of the difference of \c *this and \a other 14 | * 15 | * \note If you want to substract a given scalar from all coefficients, see Cwise::operator-(). 16 | * 17 | * \sa class CwiseBinaryOp, operator-=() 18 | */ 19 | EIGEN_MAKE_CWISE_BINARY_OP(operator-,internal::scalar_difference_op) 20 | 21 | /** \returns an expression of the sum of \c *this and \a other 22 | * 23 | * \note If you want to add a given scalar to all coefficients, see Cwise::operator+(). 24 | * 25 | * \sa class CwiseBinaryOp, operator+=() 26 | */ 27 | EIGEN_MAKE_CWISE_BINARY_OP(operator+,internal::scalar_sum_op) 28 | 29 | /** \returns an expression of a custom coefficient-wise operator \a func of *this and \a other 30 | * 31 | * The template parameter \a CustomBinaryOp is the type of the functor 32 | * of the custom operator (see class CwiseBinaryOp for an example) 33 | * 34 | * Here is an example illustrating the use of custom functors: 35 | * \include class_CwiseBinaryOp.cpp 36 | * Output: \verbinclude class_CwiseBinaryOp.out 37 | * 38 | * \sa class CwiseBinaryOp, operator+(), operator-(), cwiseProduct() 39 | */ 40 | template 41 | EIGEN_STRONG_INLINE const CwiseBinaryOp 42 | binaryExpr(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other, const CustomBinaryOp& func = CustomBinaryOp()) const 43 | { 44 | return CwiseBinaryOp(derived(), other.derived(), func); 45 | } 46 | -------------------------------------------------------------------------------- /eigen/src/plugins/MatrixCwiseUnaryOps.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2009 Gael Guennebaud 5 | // Copyright (C) 2006-2008 Benoit Jacob 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 | // This file is a base class plugin containing matrix specifics coefficient wise functions. 12 | 13 | /** \returns an expression of the coefficient-wise absolute value of \c *this 14 | * 15 | * Example: \include MatrixBase_cwiseAbs.cpp 16 | * Output: \verbinclude MatrixBase_cwiseAbs.out 17 | * 18 | * \sa cwiseAbs2() 19 | */ 20 | EIGEN_STRONG_INLINE const CwiseUnaryOp, const Derived> 21 | cwiseAbs() const { return derived(); } 22 | 23 | /** \returns an expression of the coefficient-wise squared absolute value of \c *this 24 | * 25 | * Example: \include MatrixBase_cwiseAbs2.cpp 26 | * Output: \verbinclude MatrixBase_cwiseAbs2.out 27 | * 28 | * \sa cwiseAbs() 29 | */ 30 | EIGEN_STRONG_INLINE const CwiseUnaryOp, const Derived> 31 | cwiseAbs2() const { return derived(); } 32 | 33 | /** \returns an expression of the coefficient-wise square root of *this. 34 | * 35 | * Example: \include MatrixBase_cwiseSqrt.cpp 36 | * Output: \verbinclude MatrixBase_cwiseSqrt.out 37 | * 38 | * \sa cwisePow(), cwiseSquare() 39 | */ 40 | inline const CwiseUnaryOp, const Derived> 41 | cwiseSqrt() const { return derived(); } 42 | 43 | /** \returns an expression of the coefficient-wise inverse of *this. 44 | * 45 | * Example: \include MatrixBase_cwiseInverse.cpp 46 | * Output: \verbinclude MatrixBase_cwiseInverse.out 47 | * 48 | * \sa cwiseProduct() 49 | */ 50 | inline const CwiseUnaryOp, const Derived> 51 | cwiseInverse() const { return derived(); } 52 | -------------------------------------------------------------------------------- /include/ESKF.h: -------------------------------------------------------------------------------- 1 | #ifndef ESKF_H 2 | #define ESKF_H 3 | 4 | // Malloc is really bad on embedded platform 5 | #define EIGEN_NO_MALLOC 6 | #include 7 | #include 8 | #include 9 | 10 | #define SUPPORT_STDIOSTREAM 11 | 12 | #define POS_IDX (0) 13 | #define VEL_IDX (POS_IDX + 3) 14 | #define QUAT_IDX (VEL_IDX + 3) 15 | #define AB_IDX (QUAT_IDX + 4) 16 | #define GB_IDX (AB_IDX + 3) 17 | #define STATE_SIZE (GB_IDX + 3) 18 | 19 | #define dPOS_IDX (0) 20 | #define dVEL_IDX (dPOS_IDX + 3) 21 | #define dTHETA_IDX (dVEL_IDX + 3) 22 | #define dAB_IDX (dTHETA_IDX + 3) 23 | #define dGB_IDX (dAB_IDX + 3) 24 | #define dSTATE_SIZE (dGB_IDX + 3) 25 | 26 | //the main ESKF class 27 | class ESKF { 28 | public: 29 | ESKF() {}; 30 | // takes as input the variance of the acceleration and gyro, where _n is the measurement noise, and _w is the pertibations of the system. 31 | ESKF(Eigen::Vector3f a_gravity, 32 | const Eigen::Matrix& initialState, 33 | const Eigen::Matrix& initalP, 34 | float var_acc, float var_omega, float var_acc_bias, float var_omega_bias); 35 | 36 | // Concatenates relevant vectors to one large vector. 37 | static Eigen::Matrix makeState( 38 | const Eigen::Vector3f& p, 39 | const Eigen::Vector3f& v, 40 | const Eigen::Quaternionf& q, 41 | const Eigen::Vector3f& a_b, 42 | const Eigen::Vector3f& omega_b); 43 | // Inserts relevant parts of the block-diagonal of the P matrix 44 | static Eigen::Matrix makeP( 45 | const Eigen::Matrix3f& cov_pos, 46 | const Eigen::Matrix3f& cov_vel, 47 | const Eigen::Matrix3f& cov_dtheta, 48 | const Eigen::Matrix3f& cov_a_b, 49 | const Eigen::Matrix3f& cov_omega_b); 50 | 51 | // The quaternion convention in the document is "Hamilton" convention. 52 | // Eigen has a different order of components, so we need conversion 53 | static Eigen::Quaternionf quatFromHamilton(const Eigen::Vector4f& qHam); 54 | static Eigen::Vector4f quatToHamilton(const Eigen::Quaternionf& q); 55 | static Eigen::Matrix3f rotVecToMat(const Eigen::Vector3f& in); 56 | static Eigen::Quaternionf rotVecToQuat(const Eigen::Vector3f& in); 57 | static Eigen::Vector3f quatToRotVec(const Eigen::Quaternionf& q); 58 | static Eigen::Matrix3f getSkew(const Eigen::Vector3f& in); 59 | 60 | // Acessors of nominal state 61 | inline Eigen::Vector3f getPos() { return nominalState_.block<3, 1>(POS_IDX, 0); } 62 | inline Eigen::Vector3f getVel() { return nominalState_.block<3, 1>(VEL_IDX, 0); } 63 | inline Eigen::Vector4f getQuatVector() { return nominalState_.block<4, 1>(QUAT_IDX, 0); } 64 | inline Eigen::Quaternionf getQuat() { return quatFromHamilton(getQuatVector()); } 65 | inline Eigen::Vector3f getAccelBias() { return nominalState_.block<3, 1>(AB_IDX, 0); } 66 | inline Eigen::Vector3f getGyroBias() { return nominalState_.block<3, 1>(GB_IDX, 0); } 67 | 68 | // Called when there is a new measurment from the IMU. 69 | // dt is the integration time of this sample, nominally the IMU sample period 70 | void predictIMU(const Eigen::Vector3f& a_m, const Eigen::Vector3f& omega_m, const float dt); 71 | 72 | // Called when there is a new measurment from an absolute position reference. 73 | // Note that this has no body offset, i.e. it assumes exact observation of the center of the IMU. 74 | void measurePos(const Eigen::Vector3f& pos_meas, const Eigen::Matrix3f& pos_covariance); 75 | 76 | // Called when there is a new measurment from an absolute position reference. 77 | // The measurement is with respect to some location on the body that is not at the IMU center in general. 78 | // pos_ref_body should specify the reference location in the body frame. 79 | // For example, this would be the location of the GPS antenna on the body. 80 | // NOT YET IMPLEMENTED 81 | // void measurePosWithOffset(Eigen::Vector3f pos_meas, Matrix3f pos_covariance, 82 | // Eigen::Vector3f pos_ref_body); 83 | 84 | // Called when there is a new measurment from an absolute orientation reference. 85 | // The uncertianty is represented as the covariance of a rotation vector in the body frame 86 | void measureQuat(const Eigen::Quaternionf& q_meas, const Eigen::Matrix3f& theta_covariance); 87 | 88 | Eigen::Matrix3f getDCM(); 89 | 90 | private: 91 | Eigen::Matrix getQ_dtheta(); // eqn 280, page 62 92 | void update_3D( 93 | const Eigen::Vector3f& delta_measurement, 94 | const Eigen::Matrix3f& meas_covariance, 95 | const Eigen::Matrix& H); 96 | void injectErrorState(const Eigen::Matrix& error_state); 97 | 98 | // IMU Noise values, used in prediction 99 | float var_acc_; 100 | float var_omega_; 101 | float var_acc_bias_; 102 | float var_omega_bias_; 103 | // Acceleration due to gravity in global frame 104 | Eigen::Vector3f a_gravity_; // [m/s^2] 105 | // State vector of the filter 106 | Eigen::Matrix nominalState_; 107 | // Covariance of the (error) state 108 | Eigen::Matrix P_; 109 | // Jacobian of the state transition: page 59, eqn 269 110 | // Note that we precompute the static parts in the constructor, 111 | // and update the dynamic parts in the predict function 112 | Eigen::Matrix F_x_; 113 | }; 114 | 115 | #endif /* ESKF_H */ 116 | -------------------------------------------------------------------------------- /tools/analyze.py: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | import pandas 5 | 6 | Ndrop = 20 7 | 8 | # Main figure 9 | fig, ax = plt.subplots(1, 1) 10 | 11 | # Filter output 12 | df = pandas.read_csv('../filtered.txt', index_col='t') 13 | df.drop(df.drop(df.index[:Ndrop], inplace=True)) 14 | base_t = df.index[0] 15 | df.index -= base_t 16 | df.plot(ax=ax) 17 | 18 | # Mocap 19 | dfMocap = pandas.read_csv('../inMocap.txt', index_col='t') 20 | dfMocap.drop(dfMocap.index[:Ndrop], inplace=True) 21 | dfMocap.index -= base_t 22 | dfMocap.plot(ax=ax, style='.') 23 | 24 | # IMU 25 | dfIMU = pandas.read_csv('../inIMU.txt', index_col='t') 26 | dfIMU.drop(dfIMU.index[:Ndrop], inplace=True) 27 | dfIMU.index -= base_t 28 | dfIMU.plot() 29 | 30 | plt.show() 31 | -------------------------------------------------------------------------------- /tools/codegen.py: -------------------------------------------------------------------------------- 1 | import sympy as sp 2 | from sympy.utilities import codegen 3 | 4 | dPOS_IDX = (0) 5 | dVEL_IDX = (dPOS_IDX + 3) 6 | dTHETA_IDX = (dVEL_IDX + 3) 7 | dAB_IDX = (dTHETA_IDX + 3) 8 | dGB_IDX = (dAB_IDX + 3) 9 | dSTATE_SIZE = (dGB_IDX + 3) 10 | 11 | outfile_name = '../include/unrolledFPFt.h' 12 | 13 | 14 | def make_matrix(name, rows, cols): 15 | M = sp.zeros(rows, cols) 16 | for i in range(rows): 17 | for j in range(cols): 18 | M[i,j] = sp.Symbol('{}({},{})'.format(name, i, j)) 19 | return M 20 | 21 | def copy_lower_to_upper(M): 22 | for i in range(M.rows): 23 | for j in range(i, M.cols): 24 | M[i,j] = M[j,i] 25 | 26 | 27 | dt = sp.symbols('dt') 28 | F_x = sp.zeros(dSTATE_SIZE, dSTATE_SIZE) 29 | 30 | # dPos row 31 | F_x[dPOS_IDX:dPOS_IDX+3, dPOS_IDX:dPOS_IDX+3] = sp.eye(3) 32 | F_x[dPOS_IDX:dPOS_IDX+3, dVEL_IDX:dVEL_IDX+3] = sp.eye(3) * dt 33 | # dVel row 34 | F_x[dVEL_IDX:dVEL_IDX+3, dVEL_IDX:dVEL_IDX+3] = sp.eye(3) 35 | F_x[dVEL_IDX:dVEL_IDX+3, dTHETA_IDX:dTHETA_IDX+3] = make_matrix('dVel_dTheta', 3, 3) 36 | F_x[dVEL_IDX:dVEL_IDX+3, dAB_IDX:dAB_IDX+3] = make_matrix('dVel_dAccelBias', 3, 3) 37 | # dTheta row 38 | F_x[dTHETA_IDX:dTHETA_IDX+3, dTHETA_IDX:dTHETA_IDX+3] = make_matrix('dTheta_dTheta', 3, 3) 39 | F_x[dTHETA_IDX:dTHETA_IDX+3, dGB_IDX:dGB_IDX+3] = -sp.eye(3) * dt 40 | # dAccelBias row 41 | F_x[dAB_IDX:dAB_IDX+3, dAB_IDX:dAB_IDX+3] = sp.eye(3) 42 | # dGyroBias row 43 | F_x[dGB_IDX:dGB_IDX+3, dGB_IDX:dGB_IDX+3] = sp.eye(3) 44 | 45 | 46 | P = make_matrix('Pin', dSTATE_SIZE, dSTATE_SIZE) 47 | copy_lower_to_upper(P) # Exploit symmetric P for CSE 48 | 49 | Pnew = F_x * P * F_x.T 50 | copy_lower_to_upper(Pnew) # Exploit symmetric Pnew for CSE 51 | 52 | # Generate common subexpressions 53 | sub_expr, Pnew_cse = sp.cse(Pnew) 54 | sub_expr_strs = ['const float {} = {};'.format(name, code) for name, code in sub_expr] 55 | 56 | # Generate matrix expression 57 | mat_strs = [] 58 | for res, expr in zip( 59 | sp.flatten(make_matrix('Pnew', Pnew.rows, Pnew.cols)), 60 | sp.flatten(Pnew_cse)): 61 | mat_strs.append('{} = {};'.format(res.name, codegen.ccode(expr))) 62 | 63 | # Write output 64 | # Hint: Copy out to a text editor to edit with syntax, then copy back 65 | header = """ 66 | #ifndef UNROLLEDFPFT_H 67 | #define UNROLLEDFPFT_H 68 | 69 | static inline void unrolledFPFt( 70 | const Eigen::Matrix& Pin, 71 | Eigen::Matrix& Pnew, 72 | const float dt, 73 | const Eigen::Matrix3f& dVel_dTheta, 74 | const Eigen::Matrix3f& dVel_dAccelBias, 75 | const Eigen::Matrix3f& dTheta_dTheta 76 | ) { 77 | """ 78 | 79 | body = '\n'.join(sub_expr_strs + mat_strs) 80 | 81 | footer = """ 82 | } 83 | #endif /* UNROLLEDFPFT_H */ 84 | """ 85 | 86 | with open(outfile_name, 'w+') as outfile: 87 | outfile.write(header) 88 | outfile.write(body) 89 | outfile.write(footer) 90 | --------------------------------------------------------------------------------